From 9c6a345f4bed7a2d7cc484f68169727a88dda89e Mon Sep 17 00:00:00 2001 From: jangko Date: Tue, 4 Feb 2025 20:28:15 +0700 Subject: [PATCH] devnet-6: Update EIP-7702 outdated implementation https://github.com/ethereum/EIPs/blob/f27ddf2b0af7e862a967ee38ceeaa7d980786ca1/EIPS/eip-7702.md#behavior --- nimbus/transaction/call_common.nim | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/nimbus/transaction/call_common.nim b/nimbus/transaction/call_common.nim index 703fd5c59..fed8fe61a 100644 --- a/nimbus/transaction/call_common.nim +++ b/nimbus/transaction/call_common.nim @@ -91,42 +91,40 @@ proc preExecComputation(vmState: BaseVMState, call: CallParams): int64 = if not(auth.chainId == 0.ChainId or auth.chainId == vmState.com.chainId): continue - # 2. authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s] + # 2. Verify the nonce is less than 2**64 - 1. + if auth.nonce+1 < auth.nonce: + continue + + # 3. authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s] let authority = authority(auth).valueOr: continue - # 3. Add authority to accessed_addresses (as defined in EIP-2929.) + # 4. Add authority to accessed_addresses (as defined in EIP-2929.) ledger.accessList(authority) - # 4. Verify the code of authority is either empty or already delegated. + # 5. Verify the code of authority is either empty or already delegated. let code = ledger.getCode(authority) if code.len > 0: if not parseDelegation(code): continue - # 5. Verify the nonce of authority is equal to nonce. + # 6. Verify the nonce of authority is equal to nonce. if ledger.getNonce(authority) != auth.nonce: continue - # 6. Add PER_EMPTY_ACCOUNT_COST - PER_AUTH_BASE_COST gas to the global refund counter if authority exists in the trie. + # 7. Add PER_EMPTY_ACCOUNT_COST - PER_AUTH_BASE_COST gas to the global refund counter if authority exists in the trie. if ledger.accountExists(authority): gasRefund += PER_EMPTY_ACCOUNT_COST - PER_AUTH_BASE_COST - # 7. Set the code of authority to be 0xef0100 || address. This is a delegation designation. - if auth.address == default(eth_types.Address): + # 8. Set the code of authority to be 0xef0100 || address. This is a delegation designation. + if auth.address == zeroAddress: ledger.setCode(authority, @[]) else: ledger.setCode(authority, @(addressToDelegation(auth.address))) - # 8. Increase the nonce of authority by one. + # 9. Increase the nonce of authority by one. ledger.setNonce(authority, auth.nonce + 1) - # Usually the transaction destination and delegation target are added to - # the access list in initialAccessListEIP2929, however if the delegation is in - # the same transaction we need add here as to reduce calling slow ecrecover. - if call.to == authority: - ledger.accessList(auth.address) - gasRefund proc setupHost(call: CallParams, keepStack: bool): TransactionHost =