Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Priority big int conversion should not causing underflow #1787

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion x/evm/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@

// calculate the priority by dividing the total fee with the native gas limit (i.e. the effective native gas price)
priority := fc.CalculatePriority(ctx, txData)
ctx = ctx.WithPriority(priority.Int64())

// only set priority if it is valid
if priority.IsInt64() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if priority is not int64? should we set some default priority?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be default to 0 if not set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But maybe we can explicitly set it to 0 again

ctx = ctx.WithPriority(priority.Int64())
} else {
ctx = ctx.WithPriority(0)
}

Check warning on line 103 in x/evm/ante/fee.go

View check run for this annotation

Codecov / codecov/patch

x/evm/ante/fee.go#L102-L103

Added lines #L102 - L103 were not covered by tests

return next(ctx, tx, simulate)
}
Expand All @@ -118,6 +124,8 @@
priority := sdk.NewDecFromBigInt(gp).Quo(fc.evmKeeper.GetPriorityNormalizer(ctx)).TruncateInt().BigInt()
if priority.Cmp(big.NewInt(antedecorators.MaxPriority)) > 0 {
priority = big.NewInt(antedecorators.MaxPriority)
} else if priority.Sign() < 0 {
priority = big.NewInt(0)

Check warning on line 128 in x/evm/ante/fee.go

View check run for this annotation

Codecov / codecov/patch

x/evm/ante/fee.go#L128

Added line #L128 was not covered by tests
}
return priority
}
Loading