nimbus-eth1/tests/test_op_env.nim

379 lines
11 KiB
Nim
Raw Normal View History

import
macro_assembler, unittest2,
2022-12-02 04:39:12 +00:00
stew/byteutils, ../nimbus/common/common,
2022-02-05 09:17:41 +00:00
../nimbus/[vm_state, constants],
../nimbus/db/accounts_cache
2019-09-21 05:45:23 +00:00
proc opEnvMain*() =
suite "Environmental Information Opcodes":
2022-05-24 03:43:31 +00:00
assembler: # EVM bug reported in discord
title: "stack's operator [] bug"
code:
PUSH1 "0x0A"
DUP1
RETURNDATASIZE
MSIZE
ADDRESS
GAS
STATICCALL
CALL
fork: London
2022-05-24 03:43:31 +00:00
success: false
memory: "0x0000000000000000000000000000000000000000000000000000000000000000"
2019-09-21 05:45:23 +00:00
assembler: # CODECOPY OP
title: "CODECOPY_1"
code:
PUSH1 "0x03" # size
PUSH1 "0x08" # copy start pos
PUSH1 "0x00" # mem start pos
CODECOPY
STOP
SLT
CALLVALUE
JUMP
memory: "0x1234560000000000000000000000000000000000000000000000000000000000"
# assertEquals(6, gas); ??
2019-09-21 05:45:23 +00:00
assembler: # CODECOPY OP
title: "CODECOPY_2"
code:
PUSH1 "0x5E" # size
PUSH1 "0x08" # copy start pos
PUSH1 "0x00" # mem start pos
CODECOPY
STOP
PUSH1 "0x00"
PUSH1 "0x5f"
SSTORE
PUSH1 "0x14"
PUSH1 "0x00"
SLOAD
PUSH1 "0x1e"
PUSH1 "0x20"
SLOAD
PUSH4 "0xabcddcba"
PUSH1 "0x40"
SLOAD
JUMPDEST
MLOAD
PUSH1 "0x20"
ADD
PUSH1 "0x0a"
MSTORE
SLOAD
MLOAD
PUSH1 "0x40"
ADD
PUSH1 "0x14"
MSTORE
SLOAD
MLOAD
PUSH1 "0x60"
ADD
PUSH1 "0x1e"
MSTORE
SLOAD
MLOAD
PUSH1 "0x80"
ADD
PUSH1 "0x28"
MSTORE
SLOAD
PUSH1 "0xa0"
MSTORE
SLOAD
PUSH1 "0x16"
PUSH1 "0x48"
PUSH1 "0x00"
CODECOPY
PUSH1 "0x16"
PUSH1 "0x00"
CALLCODE
PUSH1 "0x00"
PUSH1 "0x3f"
SSTORE
PUSH2 "0x03e7"
JUMP
PUSH1 "0x00"
SLOAD
PUSH1 "0x00"
MSTORE8
PUSH1 "0x20"
MUL
CALLDATALOAD
PUSH1 "0x20"
SLOAD
memory:
"0x6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254"
"0x516040016014525451606001601E5254516080016028525460A0525460166048"
"0x60003960166000F26000603F556103E756600054600053602002356020540000"
#assertEquals(10, gas); ??
2019-09-21 05:45:23 +00:00
assembler: # CODECOPY OP
title: "CODECOPY_3"
# cost for that:
# 94 - data copied
# 95 - new bytes allocated
code:
Push1 "0x5E"
Push1 "0x08"
Push1 "0x00"
CodeCopy
STOP
"0x6000605f556014600054601e60205463abcddcba6040545b"
"0x51602001600a5254516040016014525451606001601e52545160800160285254"
"0x60a052546016604860003960166000f26000603f556103e75660005460005360"
"0x20023500"
memory:
"0x6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254"
"0x516040016014525451606001601E5254516080016028525460A0525460166048"
"0x60003960166000F26000603F556103E756600054600053602002350000000000"
#assertEquals(10, program.getResult().getGasUsed());
2019-09-21 05:45:23 +00:00
assembler: # CODECOPY OP
title: "CODECOPY_4"
code:
Push1 "0x5E"
Push1 "0x07"
Push1 "0x00"
CodeCopy
STOP
"0x6000605f556014600054601e60205463abcddcba6040545b51"
"0x602001600a5254516040016014525451606001601e5254516080016028525460"
"0xa052546016604860003960166000f26000603f556103e756600054600053602002351234"
memory:
"0x006000605F556014600054601E60205463ABCDDCBA6040545B51602001600A52"
"0x54516040016014525451606001601E5254516080016028525460A05254601660"
"0x4860003960166000F26000603F556103E7566000546000536020023512340000"
#assertEquals(10, program.getResult().getGasUsed());
2019-09-21 05:45:23 +00:00
assembler: # CODECOPY OP
title: "CODECOPY_5"
code:
Push2 "0x1234"
Push1 "0x00"
Sload
Push2 "0x5566"
Push1 "0x20"
Sload
Push1 "0x70"
Push1 "0x00"
Push1 "0x20"
CodeCopy
STOP
"0x6000605f55601460"
"0x0054601e60205463abcddcba6040545b51602001600a525451604001"
"0x6014525451606001601e5254516080016028525460a0525460166048"
"0x60003960166000f26000603f556103e75660005460005360200235123400"
stack:
"0x1234"
"0x00"
"0x5566"
"0x00"
memory:
"0x0000000000000000000000000000000000000000000000000000000000000000"
"0x61123460005461556660205460706000602039006000605f556014600054601e"
"0x60205463abcddcba6040545b51602001600a5254516040016014525451606001"
"0x601e5254516080016028525460a052546016604860003960166000f26000603f"
"0x556103e756600054600053602002351200000000000000000000000000000000"
2019-09-21 05:45:23 +00:00
assembler: # CODECOPY OP mal
title: "CODECOPY_6"
code:
"0x605E6007396000605f556014600054601e60205463abcddcba604054"
"0x5b51602001600a5254516040016014525451606001601e5254516080"
"0x016028525460a052546016604860003960166000f26000603f556103"
"0xe756600054600053602002351234"
success: false
stack:
"0x5e"
"0x07"
suite "Environmental Information Opcodes 2":
let
acc = hexToByteArray[20]("0xfbe0afcd7658ba86be41922059dd879c192d4c73")
code = hexToSeqByte("0x0102030405060708090A0B0C0D0E0F" &
"611234600054615566602054603E6000602073471FD3AD3E9EEADEEC4608B92D" &
"16CE6B500704CC3C6000605f556014600054601e60205463abcddcba6040545b" &
"51602001600a5254516040016014525451606001601e52545160800160285254" &
"60a052546016604860003960166000f26000603f556103e756600054600053602002351234")
2019-09-21 05:45:23 +00:00
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_1"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
2019-09-21 05:45:23 +00:00
code:
Push1 "0x04" # size
Push1 "0x07" # code pos
Push1 "0x00" # mem pos
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeCopy
STOP
Slt
CallValue
Jump
Stop
memory: "0x08090a0b00000000000000000000000000000000000000000000000000000000"
2019-09-21 05:45:23 +00:00
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_2"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
2019-09-21 05:45:23 +00:00
code:
Push1 "0x3E"
Push1 "0x07"
Push1 "0x00"
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeCopy
STOP
"0x6000605f"
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
"0x166000f26000603f556103e75660005460005360200235602054"
memory:
"0x08090a0b0c0d0e0f611234600054615566602054603e6000602073471fd3ad3e"
"0x9eeadeec4608b92d16ce6b500704cc3c6000605f556014600054601e60200000"
2019-09-21 05:45:23 +00:00
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_3"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
2019-09-21 05:45:23 +00:00
code:
Push1 "0x5E"
Push1 "0x07"
Push1 "0x00"
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeCopy
STOP
"0x6000605f"
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
"0x166000f26000603f556103e75660005460005360200235"
memory:
"0x08090a0b0c0d0e0f611234600054615566602054603e6000602073471fd3ad3e"
"0x9eeadeec4608b92d16ce6b500704cc3c6000605f556014600054601e60205463"
"0xabcddcba6040545b51602001600a5254516040016014525451606001601e0000"
2019-09-21 05:45:23 +00:00
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_4"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
2019-09-21 05:45:23 +00:00
code:
Push2 "0x1234"
Push1 "0x00"
Sload
Push2 "0x5566"
Push1 "0x20"
Sload
Push1 "0x3E"
Push1 "0x00"
Push1 "0x20"
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeCopy
STOP
"0x6000605f556014600054601e60205463abcddcba6040545b"
"0x51602001600a5254516040016014525451606001601e52545160800160285254"
"0x60a052546016604860003960166000f26000603f556103e756600054600053602002351234"
stack:
"0x1234"
"0x00"
"0x5566"
"0x00"
memory:
"0x0000000000000000000000000000000000000000000000000000000000000000"
"0x0102030405060708090a0b0c0d0e0f611234600054615566602054603e600060"
"0x2073471fd3ad3e9eeadeec4608b92d16ce6b500704cc3c6000605f5560140000"
2019-09-21 05:45:23 +00:00
assembler: # EXTCODECOPY OP mal
title: "EXTCODECOPY_5"
code:
Push1 "0x5E"
Push1 "0x07"
Push20 "0x471FD3AD3E9EEADEEC4608B92D16CE6B500704CC"
ExtCodeCopy
success: false
stack:
"0x5E"
"0x07"
2019-09-21 05:45:23 +00:00
assembler: # CODESIZE OP
title: "CODESIZE_1"
code:
"0x385E60076000396000605f556014600054601e60205463abcddcba6040545b51"
"0x602001600a5254516040016014525451606001601e5254516080016028525460"
"0xa052546016604860003960166000f26000603f556103e75660005460005360200235"
stack:
"0x0000000000000000000000000000000000000000000000000000000000000062"
success: false
2019-09-21 05:45:23 +00:00
# 0x94 == 148 bytes
assembler: # EXTCODESIZE OP
title: "EXTCODESIZE_1"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
2019-09-21 05:45:23 +00:00
code:
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeSize
STOP
"0x5E60076000396000605f"
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
"0x166000f26000603f556103e75660005460005360200235"
stack: "0x94"
assembler: # EIP2929 EXTCODESIZE OP
title: "EIP2929 EXTCODESIZE_1"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeSize
STOP
stack: "0x94"
fork: Berlin
gasused: 2603
assembler: # EIP2929 EXTCODEHASH OP
title: "EIP2929 EXTCODEHASH_1"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeHash
STOP
stack:
"0xc862129bffb73168481c6a51fd36afb8342887fbc5314c763ac731c732d7310c"
fork: Berlin
gasused: 2603
assembler:
2022-02-27 05:21:46 +00:00
title: "EIP-4399 PrevRandao 0"
code:
2022-02-27 05:21:46 +00:00
PrevRandao
STOP
stack:
"0x0000000000000000000000000000000000000000000000000000000000000000"
fork: Merge
assembler:
2022-02-27 05:21:46 +00:00
title: "EIP-4399 PrevRandao: EMPTY_UNCLE_HASH"
setup:
vmState.prevRandao = EMPTY_UNCLE_HASH
code:
2022-02-27 05:21:46 +00:00
PrevRandao
STOP
stack:
"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
fork: Merge
2022-02-05 09:17:41 +00:00
when isMainModule:
opEnvMain()