From e109b4e17f544f7798f19a5d10cdca17293f3fa4 Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 9 Jan 2025 10:20:46 +0800 Subject: [PATCH 1/2] PEVM-fix: fix journal record in add/sub balance with 0 --- core/state/pevm_statedb.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/state/pevm_statedb.go b/core/state/pevm_statedb.go index bff3eadad..35c1012e1 100644 --- a/core/state/pevm_statedb.go +++ b/core/state/pevm_statedb.go @@ -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) } From 7db8b0bc89097f49b9c0be3c974d92bd1fc76eea Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 9 Jan 2025 14:45:10 +0800 Subject: [PATCH 2/2] fix ut issue fix the ut issue by avoid pollute the pst.cache when append journal --- core/state/pevm_statedb.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/state/pevm_statedb.go b/core/state/pevm_statedb.go index 35c1012e1..a9605373f 100644 --- a/core/state/pevm_statedb.go +++ b/core/state/pevm_statedb.go @@ -169,25 +169,27 @@ func (pst *UncommittedDB) Prepare(rules params.Rules, sender, coinbase common.Ad // 2. object func (pst *UncommittedDB) SubBalance(addr common.Address, amount *uint256.Int) { - obj := pst.getOrNewObject(addr) if amount.IsZero() { + obj := pst.getOrNewObject(addr) if !obj.empty(pst) { return } } pst.journal.append(newJBalance(pst.cache[addr], addr)) + obj := pst.getOrNewObject(addr) newb := new(uint256.Int).Sub(obj.balance, amount) pst.cache.setBalance(addr, newb) } func (pst *UncommittedDB) AddBalance(addr common.Address, amount *uint256.Int) { - obj := pst.getOrNewObject(addr) if amount.IsZero() { + obj := pst.getOrNewObject(addr) if !obj.empty(pst) { return } } pst.journal.append(newJBalance(pst.cache[addr], addr)) + obj := pst.getOrNewObject(addr) newb := new(uint256.Int).Add(obj.balance, amount) pst.cache.setBalance(addr, newb) }