Skip to content

Commit

Permalink
Update based on comments: Test push0 in a successfully called contrac…
Browse files Browse the repository at this point in the history
…t using staticcall, improve gas usage calculation to avoid strong dependency on SSTORE
  • Loading branch information
hugo-dc committed Aug 25, 2022
1 parent 40da0d4 commit abf955b
Show file tree
Hide file tree
Showing 6 changed files with 408 additions and 251 deletions.
410 changes: 277 additions & 133 deletions BlockchainTests/GeneralStateTests/VMTests/vmTests/push0.json

Large diffs are not rendered by default.

139 changes: 68 additions & 71 deletions BlockchainTests/GeneralStateTests/VMTests/vmTests/push0Gas2.json

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions GeneralStateTests/VMTests/vmTests/push0.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"push0" : {
"_info" : {
"comment" : "",
"filling-rpc-server" : "evm version 1.10.18-unstable-e0a1fd5f-20220511",
"filling-rpc-server" : "evm version 1.10.18-unstable-cb1d9b7d-20220517",
"filling-tool-version" : "retesteth-0.2.2-testinfo+commit.764be094.Linux.g++",
"generatedTestHash" : "5bd0062975c9bbd3f8fd5d0c1028e89c5afe7540587fd8f32ce334704c4f4d39",
"generatedTestHash" : "27d4fff73d6698177b83382f5b0a35328902e2306677382fea0a255aacc13253",
"labels" : {
"0" : "single_push0",
"1" : "1024_push0",
Expand All @@ -15,7 +15,7 @@
"lllcversion" : "Version: 0.5.14-develop.2022.4.6+commit.401d5358.Linux.g++",
"solidity" : "Version: 0.8.5+commit.a4f2e591.Linux.g++",
"source" : "src/GeneralStateTestsFiller/VMTests/vmTests/push0Filler.yml",
"sourceHash" : "4ce334edb7ef170a55110aded4ca574a11a98a50c8a2cc9715fa05e5a9300471"
"sourceHash" : "0817ba4554b7519910eddd8f0be394864c0ede65a8e3936f3e147691e567c5e8"
},
"env" : {
"currentBaseFee" : "0x0a",
Expand All @@ -29,7 +29,7 @@
"post" : {
"London" : [
{
"hash" : "0xcf8b3ae5e854de7634c1a68e2c2eb31ba4a41eb369c4962a78bb7689f9254bb7",
"hash" : "0x8e35ff11bc04a9909ca4da6ad81b254bc4e64490914c6e90f711b0f28376d07f",
"indexes" : {
"data" : 0,
"gas" : 0,
Expand All @@ -39,7 +39,7 @@
"txbytes" : "0xf874800a830aae6094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000001001ba040c30479d1f1f7ac729145a6e98ff0bc4882cc21930cc283db84f42f1852d9fba0567ecfa0b8daeedfd9ab8d520bcf44f06d682be47dac7d64a6865cec4ec33cef"
},
{
"hash" : "0xcf8b3ae5e854de7634c1a68e2c2eb31ba4a41eb369c4962a78bb7689f9254bb7",
"hash" : "0x8e35ff11bc04a9909ca4da6ad81b254bc4e64490914c6e90f711b0f28376d07f",
"indexes" : {
"data" : 1,
"gas" : 0,
Expand All @@ -49,7 +49,7 @@
"txbytes" : "0xf873800a830aae6094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000002001b9f43461d911db5b49c5ec30977148b9ca28eccc4dc8b0f8269e039a548c48219a038a0a2bae79588d6a4b3849a32e5d94fd0da51b4f1ada903221873b4e65f5173"
},
{
"hash" : "0xcf8b3ae5e854de7634c1a68e2c2eb31ba4a41eb369c4962a78bb7689f9254bb7",
"hash" : "0x8e35ff11bc04a9909ca4da6ad81b254bc4e64490914c6e90f711b0f28376d07f",
"indexes" : {
"data" : 2,
"gas" : 0,
Expand All @@ -59,7 +59,7 @@
"txbytes" : "0xf874800a830aae6094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000003001ba0d2e4909b016fd0bbc811cd22ae17692b1dd2766b5d4534b79d05ea5b6128e4e9a033edc830c639c422099f36d73722dfc51b123c1bd772501b81ebc4358a9340b4"
},
{
"hash" : "0xcf8b3ae5e854de7634c1a68e2c2eb31ba4a41eb369c4962a78bb7689f9254bb7",
"hash" : "0x8e35ff11bc04a9909ca4da6ad81b254bc4e64490914c6e90f711b0f28376d07f",
"indexes" : {
"data" : 3,
"gas" : 0,
Expand All @@ -69,7 +69,7 @@
"txbytes" : "0xf874800a830aae6094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000004001ca0f58b32b3474cd912ca18d95f9e83c4e614469b8897120cfbc663c86224d49003a051cc042a2d0e537892e6b2ba6dd56790cff05ae55917e44710e60b6efb112daf"
},
{
"hash" : "0xcf8b3ae5e854de7634c1a68e2c2eb31ba4a41eb369c4962a78bb7689f9254bb7",
"hash" : "0x8e35ff11bc04a9909ca4da6ad81b254bc4e64490914c6e90f711b0f28376d07f",
"indexes" : {
"data" : 4,
"gas" : 0,
Expand All @@ -81,7 +81,7 @@
],
"London+3855" : [
{
"hash" : "0x545574f5bca1a0fcea55465f75511a2004513c93ca8064802ce590a3acbf6ae2",
"hash" : "0x82a70cb1a4dd0943714524454d1b1cf2e701caca3a66495a7221f410ea33f073",
"indexes" : {
"data" : 0,
"gas" : 0,
Expand All @@ -91,7 +91,7 @@
"txbytes" : "0xf874800a830aae6094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000001001ba040c30479d1f1f7ac729145a6e98ff0bc4882cc21930cc283db84f42f1852d9fba0567ecfa0b8daeedfd9ab8d520bcf44f06d682be47dac7d64a6865cec4ec33cef"
},
{
"hash" : "0x4215c0686333abb42dfc5b4bdfed457fdc686caf8f64a81df8883c01f4733eac",
"hash" : "0x927b464c0393f16126c4e35e2c5c8af82d39cb21542ccfa7d0cd54c7a1e35aee",
"indexes" : {
"data" : 1,
"gas" : 0,
Expand All @@ -101,7 +101,7 @@
"txbytes" : "0xf873800a830aae6094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000002001b9f43461d911db5b49c5ec30977148b9ca28eccc4dc8b0f8269e039a548c48219a038a0a2bae79588d6a4b3849a32e5d94fd0da51b4f1ada903221873b4e65f5173"
},
{
"hash" : "0xcf8b3ae5e854de7634c1a68e2c2eb31ba4a41eb369c4962a78bb7689f9254bb7",
"hash" : "0x8e35ff11bc04a9909ca4da6ad81b254bc4e64490914c6e90f711b0f28376d07f",
"indexes" : {
"data" : 2,
"gas" : 0,
Expand All @@ -111,7 +111,7 @@
"txbytes" : "0xf874800a830aae6094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000003001ba0d2e4909b016fd0bbc811cd22ae17692b1dd2766b5d4534b79d05ea5b6128e4e9a033edc830c639c422099f36d73722dfc51b123c1bd772501b81ebc4358a9340b4"
},
{
"hash" : "0x058abb09ee8dacca411f2fe03edcf3760b83ec9254225ad505e893f15bf14df2",
"hash" : "0x0eb42673ca361a493aab1005db03be3f02c18bf92e7672f5c5a80fb7db1ff0e9",
"indexes" : {
"data" : 3,
"gas" : 0,
Expand All @@ -121,7 +121,7 @@
"txbytes" : "0xf874800a830aae6094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000004001ca0f58b32b3474cd912ca18d95f9e83c4e614469b8897120cfbc663c86224d49003a051cc042a2d0e537892e6b2ba6dd56790cff05ae55917e44710e60b6efb112daf"
},
{
"hash" : "0xcf8b3ae5e854de7634c1a68e2c2eb31ba4a41eb369c4962a78bb7689f9254bb7",
"hash" : "0x5b4817efda891f9e6447b69509bd8385f3e088e6e5918d5051687e8ccf07eb60",
"indexes" : {
"data" : 4,
"gas" : 0,
Expand Down Expand Up @@ -165,7 +165,14 @@
},
"0x0000000000000000000000000000000000000500" : {
"balance" : "0x00",
"code" : "0x6000600060006000610400620186a0fa6000556001600155",
"code" : "0x6000600060006000610600620186a0fa600055600160015560016000601f3e600051600255",
"nonce" : "0x00",
"storage" : {
}
},
"0x0000000000000000000000000000000000000600" : {
"balance" : "0x00",
"code" : "0x60ff5f5360016000f3",
"nonce" : "0x00",
"storage" : {
}
Expand Down
16 changes: 8 additions & 8 deletions GeneralStateTests/VMTests/vmTests/push0Gas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"comment" : "",
"filling-rpc-server" : "evm version 1.10.18-unstable-e0a1fd5f-20220511",
"filling-tool-version" : "retesteth-0.2.2-testinfo+commit.764be094.Linux.g++",
"generatedTestHash" : "f476c56b45e8f28e11651be3725483c61744820aff5fe31102124554cda4a822",
"generatedTestHash" : "65972e6904c1f021b8f76a925992c9747d4b699ff5c29b619f4d65f178eebdc9",
"labels" : {
"0" : "use_push0",
"1" : "use_push1_00"
},
"lllcversion" : "Version: 0.5.14-develop.2022.4.6+commit.401d5358.Linux.g++",
"solidity" : "Version: 0.8.5+commit.a4f2e591.Linux.g++",
"source" : "src/GeneralStateTestsFiller/VMTests/vmTests/push0Gas2Filler.yml",
"sourceHash" : "561b39e40318db754d7bb15139b24c8cf55d255bf9a92586bd0f1430a641c58c"
"sourceHash" : "93adb5d5680bfa21601719a9558b45a49a87f139451c6011e4540d8ea74212dd"
},
"env" : {
"currentBaseFee" : "0x0a",
Expand All @@ -26,7 +26,7 @@
"post" : {
"London" : [
{
"hash" : "0x85f0c5c332ad08c02e57702879525594f539b403c1e7bc9d720fa96dac458bc8",
"hash" : "0x4be1fa7a308e185cc11220eb5b76c6d15bf00e3cd779b7eb11bf87169a64a247",
"indexes" : {
"data" : 0,
"gas" : 0,
Expand All @@ -36,7 +36,7 @@
"txbytes" : "0xf874800a830493e094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000001001ca07ca35b9faa1194e9e41b540d2b6e444e4fa53ad965c7ec13daee2d66a6bb6b17a0277aeba1448340329eaf4924eef938e51e7e7be7bc980e25a9bf6caf358603d9"
},
{
"hash" : "0x0dabb39ecee1d63fc3e64175648d9c5d88df88bc80cf2ee994c760a8d0e6692c",
"hash" : "0x8f09fc92400e32b5b6147edba6d9cb020751ce42b7ea6b926f2f54de6b794732",
"indexes" : {
"data" : 1,
"gas" : 0,
Expand All @@ -48,7 +48,7 @@
],
"London+3855" : [
{
"hash" : "0xc14ea9cb2420890d39b514b76ff3f61d3a1cb14ec79af83001c855a840b1efbd",
"hash" : "0x4d516d5bf477e17e1546a703cbd391d2213d342e5962a8f546d5179ac7283bf3",
"indexes" : {
"data" : 0,
"gas" : 0,
Expand All @@ -58,7 +58,7 @@
"txbytes" : "0xf874800a830493e094b94f5374fce5edbc8e2a8697c15331677e6ebf0b809400000000000000000000000000000000000001001ca07ca35b9faa1194e9e41b540d2b6e444e4fa53ad965c7ec13daee2d66a6bb6b17a0277aeba1448340329eaf4924eef938e51e7e7be7bc980e25a9bf6caf358603d9"
},
{
"hash" : "0x0dabb39ecee1d63fc3e64175648d9c5d88df88bc80cf2ee994c760a8d0e6692c",
"hash" : "0x8f09fc92400e32b5b6147edba6d9cb020751ce42b7ea6b926f2f54de6b794732",
"indexes" : {
"data" : 1,
"gas" : 0,
Expand All @@ -72,14 +72,14 @@
"pre" : {
"0x0000000000000000000000000000000000000100" : {
"balance" : "0x00",
"code" : "0x5a5f555a600155",
"code" : "0x5a5f5a9091039055",
"nonce" : "0x00",
"storage" : {
}
},
"0x0000000000000000000000000000000000000200" : {
"balance" : "0x00",
"code" : "0x5a6000555a600155",
"code" : "0x5a60005a9091039055",
"nonce" : "0x00",
"storage" : {
}
Expand Down
24 changes: 16 additions & 8 deletions src/GeneralStateTestsFiller/VMTests/vmTests/push0Filler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,25 @@ push0:
5f"
nonce: '0'
storage: {}

0000000000000000000000000000000000000400:
balance: 0
# Update already existing storage value
# push1(02) push0 sstore push1(00) push1(01) sstore
code: ':raw 0x60025f556000600155'
nonce: '0'
storage: {0: 0x0a, 1: 0x0a}

0000000000000000000000000000000000000500:
balance: 0
code: ':yul { sstore(0, staticcall(100000, 0x0000000000000000000000000000000000000400, 0, 0, 0, 0)) sstore(1, 1) }'
code: ':yul { sstore(0, staticcall(100000, 0x0000000000000000000000000000000000000600, 0, 0, 0, 0)) sstore(1, 1) returndatacopy(0x1f, 0x0, 0x1) sstore(0x2, mload(0x00)) }'
nonce: 0
storage: {}

0000000000000000000000000000000000000600:
balance: 0
# push1(0xff) push0 mstore8 push1(0x01) push1(0x00) return
code: ':raw 0x60ff5f5360016000f3'
nonce: 0
storage: {}

Expand Down Expand Up @@ -252,16 +261,15 @@ push0:
network:
- 'London+3855'
result:
0000000000000000000000000000000000000400:
storage:
0x00: 0x0a # storage not updated
0x01: 0x0a # storage not updated
0000000000000000000000000000000000000500:
storage:
0x00: 0x00 # 0x00..0400 failed (attempting sstore)
0x01: 0x00
0x00: 0x01
0x01: 0x01
0x02: 0xff # Returned by the contract called statically
0000000000000000000000000000000000000600:
storage: {}
b94f5374fce5edbc8e2a8697c15331677e6ebf0b:
storage:
0x00: 0x00
0x00: 0x01
0x01: 0x01

35 changes: 18 additions & 17 deletions src/GeneralStateTestsFiller/VMTests/vmTests/push0Gas2Filler.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# EIP-3855: PUSH0 instruction - test for gas price
# EIP-3855: PUSH0 instruction - test for gas cost
push0Gas2:
env:
currentCoinbase: 2adc25665018aa1fe0e6bc666dac8fc2697ff9ba
Expand All @@ -24,15 +24,19 @@ push0Gas2:

0000000000000000000000000000000000000100:
balance: 0
# gas push0 sstore gas push1(0x1) sstore
code: ':raw 0x5a5f555a600155'
# Calculates the difference between initial gas and gas after using
# PUSH0, stores the result in storage key 0x00
# gas push0 gas swap1 swap2 sub swap1 sstore
code: ':raw 0x5a5f5a9091039055'
nonce: '0'
storage: {}

0000000000000000000000000000000000000200:
balance: 0
# gas push1(0) sstore gas push1(0x1) sstore
code: ':raw 0x5a6000555a600155'
# Calculates the difference between initial gas and gas after using
# PUSH1(0), stores the result in storage key 0x00
# gas push1(0) gas swap1 swap2 sub swap1 sstore
code: ':raw 0x5a60005a9091039055'
nonce: '0'
storage: {}

Expand Down Expand Up @@ -70,12 +74,11 @@ push0Gas2:
- 'London+3855'
result:
a94f5374fce5edbc8e2a8697c15331677e6ebf0b:
balance: 8878600
balance: 9099510
0000000000000000000000000000000000000100:
balance: 0
storage: # Gas used: 99998 - 77894 = 22104 (PUSH0 = 2, SSTORE = 22100, GAS = 2)
0x00: 0x01869e # Initial gas: 99998
0x01: 0x013046 # 77894
storage: # GAS PUSH0
0x00: 4 # 2 + 2
- indexes:
data: ':label use_push1_00'
gas: !!int -1
Expand All @@ -84,12 +87,11 @@ push0Gas2:
- 'London'
result:
a94f5374fce5edbc8e2a8697c15331677e6ebf0b:
balance: 8878590
balance: 9099500
0000000000000000000000000000000000000200:
balance: 0
storage: # Gas used: 99998 - 77893 = 22105 (PUSH1 00 = 3 gas, SSTORE = 22100, GAS = 2)
0x00: 0x01869e # Initial gas: 99998 (2 gas used by GAS)
0x01: 0x013045 # 77893
storage: # GAS PUSH1(0)
0x00: 5 # 2 + 3

- indexes:
data: ':label use_push1_00'
Expand All @@ -100,8 +102,7 @@ push0Gas2:
result:
0000000000000000000000000000000000000200:
balance: 0
storage: # Gas used 99998 - 77893 = 22105 (PUSH1 00 = 3 gas, SSTORE = 22100, GAS = 2)
0x00: 0x01869e # Initial gas: 99998 (2 gas used by GAS)
0x01: 0x013045 # 77893
storage: # GAS PUSH1(0)
0x00: 5 # 2 + 3
a94f5374fce5edbc8e2a8697c15331677e6ebf0b:
balance: 8878590
balance: 9099500

0 comments on commit abf955b

Please sign in to comment.