From 026ebc93b4df1db9c95997c3d4f9bf91e8e99085 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 29 Apr 2024 16:18:56 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Martin HS --- core/state/access_events.go | 2 +- core/state_transition.go | 20 ++------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/core/state/access_events.go b/core/state/access_events.go index b845fba303..bc6064e96d 100644 --- a/core/state/access_events.go +++ b/core/state/access_events.go @@ -237,7 +237,7 @@ func newChunkAccessKey(branchKey branchAccessKey, leafKey byte) chunkAccessKey { return lk } -// touchCodeChunksRangeOnReadAndChargeGas is a helper function to touch every chunk in a code range and charge witness gas costs +// CodeChunksRangeGas is a helper function to touch every chunk in a code range and charge witness gas costs func (aw *AccessEvents) CodeChunksRangeGas(contractAddr []byte, startPC, size uint64, codeLen uint64, isWrite bool) uint64 { // note that in the case where the copied code is outside the range of the // contract code but touches the last leaf with contract code in it, diff --git a/core/state_transition.go b/core/state_transition.go index 8a5e6329d1..fba41762ad 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -359,19 +359,6 @@ func (st *StateTransition) preCheck() error { return st.buyGas() } -// tryConsumeGas tries to subtract gas from gasPool, setting the result in gasPool -// if subtracting more gas than remains in gasPool, set gasPool = 0 and return false -// otherwise, do the subtraction setting the result in gasPool and return true -func tryConsumeGas(gasPool *uint64, gas uint64) bool { - if *gasPool < gas { - *gasPool = 0 - return false - } - - *gasPool -= gas - return true -} - // TransitionDb will transition the state by applying the current message and // returning the evm execution result with following fields. // @@ -419,12 +406,9 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { st.gasRemaining -= gas if rules.IsEIP4762 { - targetAddr := msg.To - originAddr := msg.From + st.evm.AccessEvents.AddTxOrigin(msg.From.Bytes()) - st.evm.AccessEvents.AddTxOrigin(originAddr.Bytes()) - - if msg.To != nil { + if targetAddr := msg.To; targetAddr != nil { st.evm.AccessEvents.AddTxDestination(targetAddr.Bytes(), msg.Value.Sign() != 0) // ensure the code size ends up in the access witness