From 0fa00d333a5b67dae475ea226106651c74b3e07c Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Mon, 19 Aug 2024 03:44:00 +0200 Subject: [PATCH] vm: 7702 correctly apply the refund [no ci] --- packages/vm/src/runTx.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/vm/src/runTx.ts b/packages/vm/src/runTx.ts index 4a712eca80..1fce1d8b6a 100644 --- a/packages/vm/src/runTx.ts +++ b/packages/vm/src/runTx.ts @@ -423,6 +423,8 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { } await vm.evm.journal.putAccount(caller, fromAccount) + let gasRefund = BIGINT_0 + const writtenAddresses = new Set() if (tx.supports(Capability.EIP7702EOACode)) { // Add contract code for authority tuples provided by EIP 7702 tx @@ -468,11 +470,12 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { if (accountExists) { const refund = tx.common.param('perEmptyAccountCost') - tx.common.param('perAuthBaseGas') - fromAccount.balance += refund + gasRefund += refund + await vm.evm.journal.putAccount(caller, fromAccount) } - fromAccount.nonce++ - await vm.evm.journal.putAccount(authority, fromAccount) + account.nonce++ + await vm.evm.journal.putAccount(authority, account) const addressCode = concatBytes(new Uint8Array([0xef, 0x01, 0x00]), address) await vm.stateManager.putCode(authority, addressCode) @@ -566,7 +569,7 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { } // Process any gas refund - let gasRefund = results.execResult.gasRefund ?? BIGINT_0 + gasRefund += results.execResult.gasRefund ?? BIGINT_0 results.gasRefund = gasRefund const maxRefundQuotient = vm.common.param('maxRefundQuotient') if (gasRefund !== BIGINT_0) {