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

EIP-4200 Tests #1103

Merged
merged 20 commits into from
Apr 22, 2023
Merged

EIP-4200 Tests #1103

merged 20 commits into from
Apr 22, 2023

Conversation

hugo-dc
Copy link
Member

@hugo-dc hugo-dc commented Nov 21, 2022

Based on Tests vectors: #1093


Tests

Valid

  • EOF code containing RJUMP (Positive, Negative, Zero)
  • EOF code containing RJUMPI (Positive, Negative, Zero)
  • EOF with RJUMPV table size 1 (Positive, Negative, Zero)
  • EOF with RJUMPV table size 3
  • EOF with RJUMPV table size 255 (Target 0, 100, 254, 256)
  • Code with branches having the same stack height
  • Jump table
  • Infinite loop
  • Infinite loop using RJUMPV
  • CALLF branches with the same total of outputs
  • CALLF inputs
  • Validate input for all opcode requiring at least 1 stack items
  • Containing terminating opcode at the end (RETURN, REVERT)
  • Loop ending with unconditional RJUMP
  • Functions ending with RETF
  • Stack is not required to be empty on terminating instruction (RETURN, REVERT)
  • RETF returning maximum number of outputs (127)

Invalid

  • EOF code containing truncated RJUMP
  • EOF code containing RJUMP with target outside code bounds
  • EOF code containing RJUMP with target immediate
  • EOF code containing truncated RJUMPI
  • EOF code containing RJUMPI with target outside code bounds
  • EOF code containing RJUMPI with target immediate
  • EOF code containing RJUMPV with count 0 and zero immediates
  • EOF code containing RJUMPV with count 0 and one immediates
  • EOF code containing truncated RJUMPV
  • EOF code containing RJUMPV with target outside code bounds
  • EOF code containing RJUMPV with target immediate

Execution

Test RJUMP/RJUMPI/RJUMPV execution.

  • EOF1_RJUMP_RJUMPI_Execution
  • RJUMP_MaxOffset
  • RJUMPI_MaxOffset

@winsvega
Copy link
Collaborator

whats new?

@gumb0 gumb0 force-pushed the eip-3540-3670-4200 branch 2 times, most recently from 48a25a6 to 0831735 Compare December 21, 2022 17:54
@gumb0
Copy link
Member

gumb0 commented Dec 21, 2022

Rebased and moved fillers to stEOF/stEIP4200, but haven't refilled yet (implementation not ready)

# Initcode: [Data: contract_code, Code: PUSH1(contract_size) PUSH1(data_offset) PUSH1(0) CODECOPY PUSH1(contract_size) PUSH1(0) RETURN]
- ':label eof1_initcode_deploy_eof1_rjump_jumpdest_pos :raw 0xef000101000c020014006014601660003960146000f3ef000101000d005c000300f3005b600160015500'
# - Negative:
# Deployed code: RJUMP(8) STOP JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP JUMPDEST RJUMP(-11) STOP - ef0001010010005c0008005b6001600155005b5cFFF500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid unreachable code this could be
RJUMP(7) JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP JUMPDEST RJUMP(-11)

data:
# Valid EOF deployed code with RJUMP having JUMPDEST as target
# - Positive:
# Deployed code: RJUMP(3) STOP RETURN STOP JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP - ef000101000d005c000300f3005b600160015500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid unreachable code this could be something like
RJUMP(3) SSTORE STOP JUMPDEST PUSH1(1) PUSH1(1) RJUMP(-10)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I would just delete all the tests with JUMPDEST, it is now NOP instruction, not better than any other instruction...

Copy link
Member

@gumb0 gumb0 Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I want to remove combinations that test whether it's validated in deployed code.

I think it's enough to try only initcode, doesn't seem worth it to check all tiny details of validation in both.


# Valid EOF deployed code with RJUMPI having JUMPDEST as target
# - Positive:
# Deployed code: PUSH1(1) RJUMPI(3) STOP RETURN STOP JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP - ef000101000f0060015d000300f3005b600160015500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid unreachable code

Suggested change
# Deployed code: PUSH1(1) RJUMPI(3) STOP RETURN STOP JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP - ef000101000f0060015d000300f3005b600160015500
# Deployed code: PUSH1(1) RJUMPI(3) NOP NOP STOP JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP - ef000101000f0060015d00035B5B005b600160015500

# Initcode: [Data: contract_code, Code: PUSH1(contract_size) PUSH1(data_offset) PUSH1(0) CODECOPY PUSH1(contract_size) PUSH1(0) RETURN]
- ':label eof1_initcode_deploy_eof1_rjumpi_jumpdest_pos :raw 0xef000101000c020016006016601660003960166000f3ef000101000f0060015d000300f3005b600160015500'
# - Negative:
# Deployed code: RJUMP(8) STOP JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP JUMPDEST PUSH1(1) RJUMPI(-13) STOP - ef0001010012005c0008005b6001600155005b60015dFFF300
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Deployed code: RJUMP(8) STOP JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP JUMPDEST PUSH1(1) RJUMPI(-13) STOP - ef0001010012005c0008005b6001600155005b60015dFFF300
# Deployed code: RJUMP(7) JUMPDEST PUSH1(1) PUSH1(1) SSTORE STOP JUMPDEST PUSH1(1) RJUMPI(-13) STOP - ef0001010011005c00075b6001600155005b60015dFFF300

@gumb0 gumb0 force-pushed the eip-3540-3670-4200 branch 2 times, most recently from a67b32c to 811bfa4 Compare December 28, 2022 16:44
@gumb0
Copy link
Member

gumb0 commented Dec 28, 2022

For some tests with EOF code in pre-state I used :yul-eof compiler which requires Solidity built from ethereum/solidity#13825 and yul-eof.sh file in retesteth config with the contents like:

#!/bin/sh
solc=$(which solc)
if [ -z $solc ]; then
   >&2 echo "yul.sh \"Yul compilation error: 'solc' not found!\""
   echo "0x"
else
    echo 0x`/home/andrei/dev/solidity/build/solc/solc --strict-assembly --evm-version shanghai --experimental-eof-version 1 --optimize --yul-optimizations ":" --bin $1 2>/dev/null | grep "Binary representation:" -A 1 | tail -n1`
fi

Also addition in main config file:

    "customCompilers" : {
        ":yul" : "yul.sh",
        ":yul-eof" : "yul-eof.sh",
...

@gumb0 gumb0 force-pushed the eip-3540-3670-4200 branch 4 times, most recently from eb7db8b to 2d77f2c Compare December 29, 2022 15:57

# Valid EOF initcode with RJUMPV table size 255
# Initcode (data): ef000101000402000100010300000000000000fe (code to be deployed)
# Initcode: PUSH1(0) RJUMPV(3, 0, -10) NOP NOP STOP PUSH1(20) PUSH1(44) PUSH1(0) CODECOPY PUSH1(20) PUSH1(0) RETURN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me like a copy paste error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thanks

@gumb0 gumb0 force-pushed the eip-3540-3670-4200 branch 5 times, most recently from f88667e to 771bbb0 Compare January 2, 2023 14:43
@gumb0 gumb0 force-pushed the eip-3540-3670-4200 branch 6 times, most recently from 74e0a66 to 1ac5aa2 Compare January 16, 2023 17:58
@hugo-dc
Copy link
Member Author

hugo-dc commented Apr 18, 2023

I updated the tests to use new validation format, all validation tests are now in this file. This is a better format for EOF code validation since it allows to specify the expected error.

:label EOF1I4200_0001 :raw 0xef0001010004020001000103000000000000005c
expectException:
"Shanghai" : "EOF_InvalidCode"
">=Cancun" : "EOF_TruncatedImmediate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there difference between forks?

All RJUMP-related changes supposedly target the single fork.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it's activated in Cancun, and the error for Shanghai means deploying code starting with 0xEF byte is rejected

@winsvega winsvega merged commit b6ceed7 into ethereum:develop Apr 22, 2023
@axic axic deleted the eip-3540-3670-4200 branch May 6, 2023 00:22
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 this pull request may close these issues.

4 participants