Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Execution Result using frontier hardfork #222

Open
Lohann opened this issue Nov 20, 2023 · 6 comments · May be fixed by #223
Open

Wrong Execution Result using frontier hardfork #222

Lohann opened this issue Nov 20, 2023 · 6 comments · May be fixed by #223

Comments

@Lohann
Copy link

Lohann commented Nov 20, 2023

Crate version: v0.41.0

I was using this evm for syncing to ethereum mainnet, as sanity check I computed the state root using the VM and compared it against the expected state root, whoever I found a sync mismatch when processing this transaction at block 49018:
https://etherscan.io/tx/0x5c4fdc85bf5efdfcbf7d4991c37287a9c3d5b660b57b0082118c3cff3c69dff1

I was syncing using the correct preset Config::frontier, after a investigation I've found the cause of the issue.

Issue

The current implementation doesn't consider the pre EIP-2 contract creation behavior, I'll use this transaction as example: 0x5c4fdc85bf5efdfcbf7d4991c37287a9c3d5b660b57b0082118c3cff3c69dff1

Actual State Changes - incorrect

Hardfork: frontier
Gas used: 145029 (which is the transaction gas_limit)
Result: ExitError::OutOfGas
Not contract created.

Trace logs
  TRACE evm: Gasometer Record Create 65304 [gas_transaction_create: 21000, zero_data_len: 145, non_zero_data_len: 643, access_list_address_len: 0, access_list_storage_len: 0, initcode_cost: 50] [Gas used: 0, Gas left: 145029]    
  TRACE evm: Gasometer Record cost 79725 [Gas used: 65304, Gas left: 79725]    
  TRACE evm: Gasometer Record cost 3 [Gas used: 0, Gas left: 79725]    
  TRACE evm: OpCode Push [@0]: 0x0000…0060    
  TRACE evm: Gasometer Record cost 3 [Gas used: 3, Gas left: 79722]    
  TRACE evm: OpCode Push [@1]: 0x0000…0040    
  TRACE evm: Gasometer Record dynamic cost 3 - memory_gas 9 - gas_refund 0 [Gas used: 6, Gas left: 79719]    
  TRACE evm: OpCode MStore: 64, 0x0000…0060    
  TRACE evm: Gasometer Record cost 3 [Gas used: 18, Gas left: 79707]    
  TRACE evm: OpCode Push [@0]: 0x0000…0040    
  TRACE evm: Gasometer Record dynamic cost 3 - memory_gas 9 - gas_refund 0 [Gas used: 21, Gas left: 79704]    
  TRACE evm: OpCode MLoad: 64    
  TRACE evm: Gasometer Record cost 3 [Gas used: 24, Gas left: 79701]    
  TRACE evm: OpCode Push [@1]: 0x0000…02b4    
  TRACE evm: Gasometer Record cost 2 [Gas used: 27, Gas left: 79698]    
  TRACE evm: OpCode CodeSize: 788    
  TRACE evm: Gasometer Record cost 3 [Gas used: 29, Gas left: 79696]    
  TRACE evm: OpCode overflowing_sub 788, 692: 96    
  TRACE evm: Gasometer Record cost 3 [Gas used: 32, Gas left: 79693]    
  TRACE evm: OpCode Dup1 [@2]: 0x0000…0060    
  TRACE evm: Gasometer Record cost 3 [Gas used: 35, Gas left: 79690]    
  TRACE evm: OpCode Push [@3]: 0x0000…02b4    
  TRACE evm: Gasometer Record cost 3 [Gas used: 38, Gas left: 79687]    
  TRACE evm: OpCode Dup4 [@4]: 0x0000…0060    
  TRACE evm: Gasometer Record dynamic cost 12 - memory_gas 18 - gas_refund 0 [Gas used: 41, Gas left: 79684]    
  TRACE evm: OpCode CodeCopy: 96    
  TRACE evm: Gasometer Record cost 3 [Gas used: 62, Gas left: 79663]    
  TRACE evm: OpCode overflowing_add 96, 96: 192    
  TRACE evm: Gasometer Record cost 3 [Gas used: 65, Gas left: 79660]    
  TRACE evm: OpCode Push [@1]: 0x0000…0040    
  TRACE evm: Gasometer Record dynamic cost 3 - memory_gas 18 - gas_refund 0 [Gas used: 68, Gas left: 79657]    
  TRACE evm: OpCode MStore: 64, 0x0000…00c0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 71, Gas left: 79654]    
  TRACE evm: OpCode Push [@0]: 0x0000…0060    
  TRACE evm: Gasometer Record cost 3 [Gas used: 74, Gas left: 79651]    
  TRACE evm: OpCode Dup1 [@1]: 0x0000…0060    
  TRACE evm: Gasometer Record dynamic cost 3 - memory_gas 18 - gas_refund 0 [Gas used: 77, Gas left: 79648]    
  TRACE evm: OpCode MLoad: 96    
  TRACE evm: Gasometer Record cost 3 [Gas used: 80, Gas left: 79645]    
  TRACE evm: OpCode Push [@2]: 0x0000…0060    
  TRACE evm: Gasometer Record cost 3 [Gas used: 83, Gas left: 79642]    
  TRACE evm: OpCode overflowing_add 96, 32: 128    
  TRACE evm: Gasometer Record cost 3 [Gas used: 86, Gas left: 79639]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…0080, 0x0000…0060    
  TRACE evm: Gasometer Record cost 3 [Gas used: 89, Gas left: 79636]    
  TRACE evm: OpCode Push [@2]: 0x0000…0020    
  TRACE evm: Gasometer Record cost 3 [Gas used: 92, Gas left: 79633]    
  TRACE evm: OpCode overflowing_add 32, 96: 128    
  TRACE evm: Gasometer Record cost 2 [Gas used: 95, Gas left: 79630]    
  TRACE evm: OpCode Pop [@1]: 0x0000…0080    
  TRACE evm: Gasometer Record cost 1 [Gas used: 97, Gas left: 79628]    
  TRACE evm: Gasometer Record cost 1 [Gas used: 98, Gas left: 79627]    
  TRACE evm: Gasometer Record cost 2 [Gas used: 99, Gas left: 79626]    
  TRACE evm: OpCode Trap: Opcode(51)    
  TRACE evm: Gasometer Record cost 3 [Gas used: 101, Gas left: 79624]    
  TRACE evm: OpCode Push [@2]: 0x0000…0000    
  TRACE evm: Gasometer Record cost 3 [Gas used: 104, Gas left: 79621]    
  TRACE evm: OpCode Push [@3]: 0x0000…0000    
  TRACE evm: Gasometer Record cost 3 [Gas used: 107, Gas left: 79618]    
  TRACE evm: OpCode Push [@4]: 0x0000…0100    
  TRACE evm: Gasometer Record dynamic cost 10 - memory_gas 18 - gas_refund 0 [Gas used: 110, Gas left: 79615]    
  TRACE evm: OpCode self::arithmetic::exp 256, 0: 1    
  TRACE evm: Gasometer Record cost 3 [Gas used: 120, Gas left: 79605]    
  TRACE evm: OpCode Dup2 [@4]: 0x0000…0000    
  TRACE evm: Gasometer Record dynamic cost 50 - memory_gas 18 - gas_refund 0 [Gas used: 123, Gas left: 79602]    
  TRACE evm: OpCode Trap: Opcode(84)    
  TRACE evm: Gasometer Record cost 3 [Gas used: 173, Gas left: 79552]    
  TRACE evm: OpCode Dup2 [@5]: 0x0000…0001    
  TRACE evm: Gasometer Record cost 3 [Gas used: 176, Gas left: 79549]    
  TRACE evm: OpCode Push [@6]: 0x0000…ffff    
  TRACE evm: Gasometer Record cost 5 [Gas used: 179, Gas left: 79546]    
  TRACE evm: OpCode overflowing_mul 1461501637330902918203684832716283019655932542975, 1: 1461501637330902918203684832716283019655932542975    
  TRACE evm: Gasometer Record cost 3 [Gas used: 184, Gas left: 79541]    
  TRACE evm: OpCode self::bitwise::not 1461501637330902918203684832716283019655932542975: 115792089237316195423570985007226406215939081747436879206741300988257197096960    
  TRACE evm: Gasometer Record cost 3 [Gas used: 187, Gas left: 79538]    
  TRACE evm: OpCode bitand 115792089237316195423570985007226406215939081747436879206741300988257197096960, 0: 0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 190, Gas left: 79535]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…0000, 0x0000…0001    
  TRACE evm: Gasometer Record cost 3 [Gas used: 193, Gas left: 79532]    
  TRACE evm: OpCode Dup4 [@5]: 0x0000…6c2d    
  TRACE evm: Gasometer Record cost 5 [Gas used: 196, Gas left: 79529]    
  TRACE evm: OpCode overflowing_mul 348413676108971912559174908100972406029277031469, 1: 348413676108971912559174908100972406029277031469    
  TRACE evm: Gasometer Record cost 3 [Gas used: 201, Gas left: 79524]    
  TRACE evm: OpCode bitor 348413676108971912559174908100972406029277031469, 0: 348413676108971912559174908100972406029277031469    
  TRACE evm: Gasometer Record cost 3 [Gas used: 204, Gas left: 79521]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…6c2d, 0x0000…0000    
  TRACE evm: Gasometer Record dynamic cost 20000 - memory_gas 18 - gas_refund 0 [Gas used: 207, Gas left: 79518]    
  TRACE evm: OpCode Trap: Opcode(85)    
  TRACE evm: Gasometer Record cost 2 [Gas used: 20207, Gas left: 59518]    
  TRACE evm: OpCode Pop [@1]: 0x0000…6c2d    
  TRACE evm: Gasometer Record cost 1 [Gas used: 20209, Gas left: 59516]    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20210, Gas left: 59515]    
  TRACE evm: OpCode Dup1 [@1]: 0x0000…0080    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20213, Gas left: 59512]    
  TRACE evm: OpCode Push [@2]: 0x0000…0001    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20216, Gas left: 59509]    
  TRACE evm: OpCode Push [@3]: 0x0000…0000    
  TRACE evm: Gasometer Record cost 2 [Gas used: 20219, Gas left: 59506]    
  TRACE evm: OpCode Pop [@3]: 0x0000…0000    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20221, Gas left: 59504]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…0001, 0x0000…0080    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20224, Gas left: 59501]    
  TRACE evm: OpCode Dup1 [@3]: 0x0000…0080    
  TRACE evm: Gasometer Record dynamic cost 3 - memory_gas 18 - gas_refund 0 [Gas used: 20227, Gas left: 59498]    
  TRACE evm: OpCode MLoad: 128    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20230, Gas left: 59495]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…000c, 0x0000…0080    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20233, Gas left: 59492]    
  TRACE evm: OpCode Push [@4]: 0x0000…0020    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20236, Gas left: 59489]    
  TRACE evm: OpCode overflowing_add 32, 128: 160    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20239, Gas left: 59486]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…00a0, 0x0000…000c    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20242, Gas left: 59483]    
  TRACE evm: OpCode Dup3 [@4]: 0x0000…0001    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20245, Gas left: 59480]    
  TRACE evm: OpCode Dup1 [@5]: 0x0000…0001    
  TRACE evm: Gasometer Record dynamic cost 50 - memory_gas 18 - gas_refund 0 [Gas used: 20248, Gas left: 59477]    
  TRACE evm: OpCode Trap: Opcode(84)    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20298, Gas left: 59427]    
  TRACE evm: OpCode Dup3 [@6]: 0x0000…000c    
  TRACE evm: Gasometer Record cost 3 [Gas used: 20301, Gas left: 59424]    
  TRACE evm: OpCode Dup3 [@7]: 0x0000…0001    
  TRACE evm: Gasometer Record dynamic cost 20000 - memory_gas 18 - gas_refund 0 [Gas used: 20304, Gas left: 59421]    
  TRACE evm: OpCode Trap: Opcode(85)    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40304, Gas left: 39421]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…0000, 0x0000…0001    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40307, Gas left: 39418]    
  TRACE evm: OpCode Push [@6]: 0x0000…0000    
  TRACE evm: Gasometer Record dynamic cost 3 - memory_gas 18 - gas_refund 0 [Gas used: 40310, Gas left: 39415]    
  TRACE evm: OpCode MStore: 0, 0x0000…0001    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40313, Gas left: 39412]    
  TRACE evm: OpCode Push [@5]: 0x0000…0020    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40316, Gas left: 39409]    
  TRACE evm: OpCode Push [@6]: 0x0000…0000    
  TRACE evm: Gasometer Record dynamic cost 36 - memory_gas 18 - gas_refund 0 [Gas used: 40319, Gas left: 39406]    
  TRACE evm: OpCode Trap: Opcode(32)    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40355, Gas left: 39370]    
  TRACE evm: OpCode Swap [@0:@1]: 0xb10e…0cf6, 0x0000…0000    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40358, Gas left: 39367]    
  TRACE evm: OpCode Push [@6]: 0x0000…001f    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40361, Gas left: 39364]    
  TRACE evm: OpCode overflowing_add 31, 0: 31    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40364, Gas left: 39361]    
  TRACE evm: OpCode Push [@6]: 0x0000…0020    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40367, Gas left: 39358]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…0020, 0x0000…001f    
  TRACE evm: Gasometer Record cost 5 [Gas used: 40370, Gas left: 39355]    
  TRACE evm: OpCode self::arithmetic::div 31, 32: 0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40375, Gas left: 39350]    
  TRACE evm: OpCode Dup2 [@6]: 0xb10e…0cf6    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40378, Gas left: 39347]    
  TRACE evm: OpCode overflowing_add 80084422859880547211683076133703299733277748156566366325829078699459944778998, 0: 80084422859880547211683076133703299733277748156566366325829078699459944778998    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40381, Gas left: 39344]    
  TRACE evm: OpCode Swap [@0:@3]: 0xb10e…0cf6, 0x0000…00a0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40384, Gas left: 39341]    
  TRACE evm: OpCode Dup3 [@6]: 0x0000…000c    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40387, Gas left: 39338]    
  TRACE evm: OpCode self::bitwise::iszero 12: 0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40390, Gas left: 39335]    
  TRACE evm: OpCode Push [@7]: 0x0000…009e    
  TRACE evm: Gasometer Record cost 10 [Gas used: 40393, Gas left: 39332]    
  TRACE evm: OpCode JumpI: skipped    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40403, Gas left: 39322]    
  TRACE evm: OpCode Swap [@0:@2]: 0x0000…00a0, 0x0000…000c    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40406, Gas left: 39319]    
  TRACE evm: OpCode Dup3 [@6]: 0x0000…00a0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40409, Gas left: 39316]    
  TRACE evm: OpCode overflowing_add 160, 12: 172    
  TRACE evm: Gasometer Record cost 1 [Gas used: 40412, Gas left: 39313]    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40413, Gas left: 39312]    
  TRACE evm: OpCode Dup3 [@6]: 0x0000…00a0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40416, Gas left: 39309]    
  TRACE evm: OpCode Dup2 [@7]: 0x0000…00ac    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40419, Gas left: 39306]    
  TRACE evm: OpCode gt 172, 160: true    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40422, Gas left: 39303]    
  TRACE evm: OpCode self::bitwise::iszero 1: 0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40425, Gas left: 39300]    
  TRACE evm: OpCode Push [@7]: 0x0000…009d    
  TRACE evm: Gasometer Record cost 10 [Gas used: 40428, Gas left: 39297]    
  TRACE evm: OpCode JumpI: skipped    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40438, Gas left: 39287]    
  TRACE evm: OpCode Dup3 [@6]: 0x0000…00a0    
  TRACE evm: Gasometer Record dynamic cost 3 - memory_gas 18 - gas_refund 0 [Gas used: 40441, Gas left: 39284]    
  TRACE evm: OpCode MLoad: 160    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40444, Gas left: 39281]    
  TRACE evm: OpCode Dup3 [@7]: 0xb10e…0cf6    
  TRACE evm: Gasometer Record cost 3 [Gas used: 40447, Gas left: 39278]    
  TRACE evm: OpCode Push [@8]: 0x0000…0000    
  TRACE evm: Gasometer Record cost 2 [Gas used: 40450, Gas left: 39275]    
  TRACE evm: OpCode Pop [@8]: 0x0000…0000    
  TRACE evm: Gasometer Record dynamic cost 20000 - memory_gas 18 - gas_refund 0 [Gas used: 40452, Gas left: 39273]    
  TRACE evm: OpCode Trap: Opcode(85)    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60452, Gas left: 19273]    
  TRACE evm: OpCode Swap [@0:@2]: 0x0000…00ac, 0x0000…00a0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60455, Gas left: 19270]    
  TRACE evm: OpCode Push [@6]: 0x0000…0020    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60458, Gas left: 19267]    
  TRACE evm: OpCode overflowing_add 32, 160: 192    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60461, Gas left: 19264]    
  TRACE evm: OpCode Swap [@0:@2]: 0x0000…00c0, 0x0000…00ac    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60464, Gas left: 19261]    
  TRACE evm: OpCode Swap [@0:@1]: 0x0000…00ac, 0xb10e…0cf6    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60467, Gas left: 19258]    
  TRACE evm: OpCode Push [@6]: 0x0000…0001    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60470, Gas left: 19255]    
  TRACE evm: OpCode overflowing_add 1, 80084422859880547211683076133703299733277748156566366325829078699459944778998: 80084422859880547211683076133703299733277748156566366325829078699459944778999    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60473, Gas left: 19252]    
  TRACE evm: OpCode Swap [@0:@1]: 0xb10e…0cf7, 0x0000…00ac    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60476, Gas left: 19249]    
  TRACE evm: OpCode Push [@6]: 0x0000…0081    
  TRACE evm: Gasometer Record cost 8 [Gas used: 60479, Gas left: 19246]    
  TRACE evm: OpCode Jump: 129    
  TRACE evm: Gasometer Record cost 1 [Gas used: 60487, Gas left: 19238]    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60488, Gas left: 19237]    
  TRACE evm: OpCode Dup3 [@6]: 0x0000…00c0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60491, Gas left: 19234]    
  TRACE evm: OpCode Dup2 [@7]: 0x0000…00ac    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60494, Gas left: 19231]    
  TRACE evm: OpCode gt 172, 192: false    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60497, Gas left: 19228]    
  TRACE evm: OpCode self::bitwise::iszero 0: 1    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60500, Gas left: 19225]    
  TRACE evm: OpCode Push [@7]: 0x0000…009d    
  TRACE evm: Gasometer Record cost 10 [Gas used: 60503, Gas left: 19222]    
  TRACE evm: OpCode JumpI: 157    
  TRACE evm: Gasometer Record cost 1 [Gas used: 60513, Gas left: 19212]    
  TRACE evm: Gasometer Record cost 1 [Gas used: 60514, Gas left: 19211]    
  TRACE evm: Gasometer Record cost 2 [Gas used: 60515, Gas left: 19210]    
  TRACE evm: OpCode Pop [@5]: 0x0000…00ac    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60517, Gas left: 19208]    
  TRACE evm: OpCode Swap [@0:@1]: 0xb10e…0cf7, 0x0000…00c0    
  TRACE evm: Gasometer Record cost 2 [Gas used: 60520, Gas left: 19205]    
  TRACE evm: OpCode Pop [@4]: 0x0000…00c0    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60522, Gas left: 19203]    
  TRACE evm: OpCode Push [@4]: 0x0000…00c5    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60525, Gas left: 19200]    
  TRACE evm: OpCode Swap [@0:@2]: 0x0000…00c5, 0xb10e…0cf6    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60528, Gas left: 19197]    
  TRACE evm: OpCode Swap [@0:@1]: 0xb10e…0cf6, 0xb10e…0cf7    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60531, Gas left: 19194]    
  TRACE evm: OpCode Push [@5]: 0x0000…00a9    
  TRACE evm: Gasometer Record cost 8 [Gas used: 60534, Gas left: 19191]    
  TRACE evm: OpCode Jump: 169    
  TRACE evm: Gasometer Record cost 1 [Gas used: 60542, Gas left: 19183]    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60543, Gas left: 19182]    
  TRACE evm: OpCode Dup1 [@5]: 0xb10e…0cf7    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60546, Gas left: 19179]    
  TRACE evm: OpCode Dup3 [@6]: 0xb10e…0cf6    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60549, Gas left: 19176]    
  TRACE evm: OpCode gt 80084422859880547211683076133703299733277748156566366325829078699459944778998, 80084422859880547211683076133703299733277748156566366325829078699459944778999: false    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60552, Gas left: 19173]    
  TRACE evm: OpCode self::bitwise::iszero 0: 1    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60555, Gas left: 19170]    
  TRACE evm: OpCode Push [@6]: 0x0000…00c1    
  TRACE evm: Gasometer Record cost 10 [Gas used: 60558, Gas left: 19167]    
  TRACE evm: OpCode JumpI: 193    
  TRACE evm: Gasometer Record cost 1 [Gas used: 60568, Gas left: 19157]    
  TRACE evm: Gasometer Record cost 2 [Gas used: 60569, Gas left: 19156]    
  TRACE evm: OpCode Pop [@4]: 0xb10e…0cf7    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60571, Gas left: 19154]    
  TRACE evm: OpCode Swap [@0:@1]: 0xb10e…0cf6, 0x0000…00c5    
  TRACE evm: Gasometer Record cost 8 [Gas used: 60574, Gas left: 19151]    
  TRACE evm: OpCode Jump: 197    
  TRACE evm: Gasometer Record cost 1 [Gas used: 60582, Gas left: 19143]    
  TRACE evm: Gasometer Record cost 2 [Gas used: 60583, Gas left: 19142]    
  TRACE evm: OpCode Pop [@2]: 0xb10e…0cf6    
  TRACE evm: Gasometer Record cost 2 [Gas used: 60585, Gas left: 19140]    
  TRACE evm: OpCode Pop [@1]: 0x0000…0001    
  TRACE evm: Gasometer Record cost 1 [Gas used: 60587, Gas left: 19138]    
  TRACE evm: Gasometer Record cost 2 [Gas used: 60588, Gas left: 19137]    
  TRACE evm: OpCode Pop [@0]: 0x0000…0080    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60590, Gas left: 19135]    
  TRACE evm: OpCode Push [@0]: 0x0000…01dc    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60593, Gas left: 19132]    
  TRACE evm: OpCode Dup1 [@1]: 0x0000…01dc    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60596, Gas left: 19129]    
  TRACE evm: OpCode Push [@2]: 0x0000…00d8    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60599, Gas left: 19126]    
  TRACE evm: OpCode Push [@3]: 0x0000…0000    
  TRACE evm: Gasometer Record dynamic cost 48 - memory_gas 45 - gas_refund 0 [Gas used: 60602, Gas left: 19123]    
  TRACE evm: OpCode CodeCopy: 476    
  TRACE evm: Gasometer Record cost 3 [Gas used: 60677, Gas left: 19048]    
  TRACE evm: OpCode Push [@1]: 0x0000…0000    
  TRACE evm: Gasometer Record dynamic cost 0 - memory_gas 45 - gas_refund 0 [Gas used: 60680, Gas left: 19045]    
  TRACE evm: OpCode Return    
  DEBUG evm: Create execution using address 0x630e…fe7a: Succeed(Returned)    
  TRACE evm: Gasometer Record cost 95200 [Gas used: 60680, Gas left: 19045]

Expected State Changes

Hardfork: frontier
Gas used: 125984
Result: Succeed(Returned)
Empty Contract Created at 0x630ea66c8c5dc205d45a978573fa86df5af1fe7a

The difference in the execution is that if there's no gas for paying the bytecode deposit bytes.len() * 200, it must deploy an Empty Contract Account, which is the same as deploying a regular contract, but without the bytecode.

{
    "nonce": 0,
    "balance": tx.value,
    "code": [], // empty bytes
    "storage": {
        "0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000003d0768da09ce77d25e2d998e6a7b6ed4b9116c2d",
        "0x0000000000000000000000000000000000000000000000000000000000000001": "0x000000000000000000000000000000000000000000000000000000000000000c",
        "0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6": "0x48656c6c6f20576f726c64210000000000000000000000000000000000000000"
    },
}

For compute the state root I'm using this crate: https://docs.rs/trie-root/latest/trie_root/

@Lohann
Copy link
Author

Lohann commented Nov 20, 2023

I believe the error is here:
https://github.com/rust-blockchain/evm/blob/release-v041/src/executor/stack/executor.rs#L1005-L1010

There must be check there, if it is before Homestead hardfork it should not fail after charge the code deposit.

@Lohann Lohann changed the title Wrong Execution for frontier hardfork Wrong Execution Result using frontier hardfork Nov 20, 2023
@sorpaas
Copy link
Member

sorpaas commented Nov 20, 2023

Yeah we unfortunately still had a few compliance issues in the current version, especially for older hard forks.

We've been focusing on using this VM in production in Frontier (not to be confused with the frontier hardfork you referred 😄). So strict compliance wasn't necessary.

I'm currently also addressing the compliance issue, developing a new version in the next branch. I noted what you said and will make sure we get this fixed in the new release!

@Lohann Lohann linked a pull request Nov 20, 2023 that will close this issue
@Lohann
Copy link
Author

Lohann commented Nov 20, 2023

@sorpaas thx for the reply! I fixed this in PR: https://github.com/rust-blockchain/evm/pull/223/files

So far so good, with this fix my client was able to synchronize up to 100k blocks from ethereum mainnet, I'll leave it sync and see if detect any other issues.

About Frontier I had a lot of issues trying to integrate it with existing ethereum tools, even tough frontier goal is being a compatibility layer for substrate, It behaves completely different than the expect from a regular ethereum node, some examples:

1 - eth_getBalance returns the reducible balance instead the total balance, which is very weird because after transfering a given amount to an account, the eth_getBalance returns a different value than the expected, which seems like a bug for who is not familiarized to substrate.

2 - It uses substrate state root instead the expected ethereum state root, which use blake2 instead keccak256 and have a completely different trie structure, because of that will be impossible to implement rpc methods like eth_getproof very important for ethereum light-clients.

3 - Block Timestamp is stored in milliseconds instead seconds, and the api converts it in seconds, which makes impossible to recompute the block hash and execute light-client txs locally like how helios does.

@Lohann
Copy link
Author

Lohann commented Nov 20, 2023

I believe that by made this crate ethereum compliant, the number of contributors and attention to this project will increase, i liked the way the code is structured, is way cleaner than revm (which is mess and really hard to understand). If it is compliant, It has potential to be used in the Rust Ethereum Full-Node.

@sorpaas
Copy link
Member

sorpaas commented Nov 20, 2023

Yeah there are some specific requirements we need. In particular, we need something really flexible -- we need to be able to implement custom gasometers (for custom PVF size calculation and stuff) as well as really customized backend logic. We unfortunately don't have another EVM at this moment able to do that -- all of them have the gasometer deeply intertwined with the interpreter. Usually people just fork an EVM implementation and change things there, but I really want something reusable that stays close to Ethereum main spec.

The differences you mentioned regarding Frontier (the project) are compromises because certain things are just too different. It's possible to get around them (using child trie), but it's complicated, not yet available in Substrate, and probably not worth the effort. So unfortunately those annoying things will probably stay, because end users usually don't care.

I wouldn't call the design currently in the master branch "good structured". After all, it was several years ago where I had much less understanding of the requirements. For example, we still had to use hooks for custom gaosmeters, and there's really (unnecessarily) complicated logic for heap call stack. I hope you find the next branch nicer -- we now have proper gasometer customization point, a hybrid call stack (it initially use stack call stack for speed, and then switch to heap call stack for deeper calls), and you can finally step and debug things along the way from outside (not just hooks). It's still messy but I'll soon be working on documents after jsontests are fixed. :)

@rakita
Copy link

rakita commented Jan 12, 2024

I believe that by made this crate ethereum compliant, the number of contributors and attention to this project will increase, i liked the way the code is structured, is way cleaner than revm (which is mess and really hard to understand). If it is compliant, It has potential to be used in the Rust Ethereum Full-Node.

Hey @Lohann revm author here, feedback is always welcomed and appreciated. My focus at the beginning of the last year was mostly on reth so I didn't have a lot of love/time for revm. This had changed as reth is stable and I have finally refactored a big chunk of the internals to be a lot better, exposed the handlers for internal logic override and made docs that explains how it works. You can read more on it here: https://twitter.com/rakitadragan/status/1745632344873030049

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants