Skip to content

Commit

Permalink
more review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Nov 5, 2024
1 parent 16b8a24 commit 660d9a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,13 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
rules := cfg.ChainConfig.Rules(big.NewInt(ctx.BlockHeight()), cfg.ChainConfig.MergeNetsplitBlock != nil, uint64(ctx.BlockTime().Unix()))
stateDB.Prepare(rules, msg.From, cfg.CoinBase, msg.To, evm.AllPrecompiledAddresses(rules), msg.AccessList)

value := msg.Value
if msg.Value == nil {
msg.Value = new(big.Int)
value = new(big.Int)
}
valueUint256, isOverflow := uint256.FromBig(msg.Value)
valueUint256, isOverflow := uint256.FromBig(value)
if isOverflow {
return nil, fmt.Errorf("%v is not a valid uint256", msg.Value)
return nil, fmt.Errorf("%v is not a valid uint256", value)
}

if contractCreation {
Expand Down
8 changes: 7 additions & 1 deletion x/evm/statedb/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ func (s *stateObject) SubBalance(amount *uint256.Int) {
if amount.Sign() == 0 {
return
}
s.SetBalance(new(uint256.Int).Sub(s.Balance(), amount))
// the underflow condition should be checked at higher levels, but
// we will guard against it anyway to be safe
newBalance, isUnderflow := new(uint256.Int).SubOverflow(s.Balance(), amount)
if isUnderflow {
return
}
s.SetBalance(newBalance)
}

// SetBalance update account balance.
Expand Down

0 comments on commit 660d9a4

Please sign in to comment.