Skip to content

Commit

Permalink
PEVM-fix: fix journal record in add/sub balance with 0
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Jan 9, 2025
1 parent 9c30172 commit e109b4e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/state/pevm_statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,25 @@ func (pst *UncommittedDB) Prepare(rules params.Rules, sender, coinbase common.Ad
// 2. object

func (pst *UncommittedDB) SubBalance(addr common.Address, amount *uint256.Int) {
pst.journal.append(newJBalance(pst.cache[addr], addr))
obj := pst.getOrNewObject(addr)
if amount.IsZero() {
if !obj.empty(pst) {
return
}
}
pst.journal.append(newJBalance(pst.cache[addr], addr))
newb := new(uint256.Int).Sub(obj.balance, amount)
pst.cache.setBalance(addr, newb)
}

func (pst *UncommittedDB) AddBalance(addr common.Address, amount *uint256.Int) {
pst.journal.append(newJBalance(pst.cache[addr], addr))
obj := pst.getOrNewObject(addr)
if amount.IsZero() {
if !obj.empty(pst) {
return
}
}
pst.journal.append(newJBalance(pst.cache[addr], addr))
newb := new(uint256.Int).Add(obj.balance, amount)
pst.cache.setBalance(addr, newb)
}
Expand Down

0 comments on commit e109b4e

Please sign in to comment.