-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
core/vm: implement full EOF suite #26133
Closed
+1,873
−45
Closed
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
492843d
core/vm: add eof container
lightclient f256678
core/vm: add eof execution semantics
lightclient 2579e9e
tests: add shanghai testing defn
lightclient 07da06d
core/vm: add eof code validation
lightclient c90f24e
core/vm: properly validated deployed code if eof
lightclient 0684011
core/vm: fix relative jump destination validation
lightclient 3906b64
core/vm: do code validation on eof
lightclient 05cf350
core/vm: fix linter and account for overflowing rjumpv case
lightclient d75812c
core/vm: add tests for deploying eof containers
lightclient 4d9179d
core/vm: fix lints
lightclient 2411f4d
core/vm: disallow eof deploying legacy code
lightclient c1eae0e
core/vm: parse relative args as ints in validation
lightclient 836a7f8
core/vm: add invalid to jump table
lightclient afc52bf
core/vm: reorder stack height checks in eof validation
lightclient 2cd5977
core/vm: follow rjumpv branches correctly
lightclient 944ba9f
core/vm: make eof parser more paranoid
holiman 3df0d42
core/vm: fix on eof
holiman 723e363
core/vm: fix uint16 overflow
holiman f4188b2
core/vm: tests for codeBitmap/eofCodeBitmap
holiman b4c0136
core/vm: bound check rjumpv before code analysis
lightclient 092750e
core/vm: fix fuzzer crashes
lightclient 4d9b08f
core/vm: more fixes
lightclient e84268b
core/vm: more fixes
lightclient 6a6af81
core/vm: bound type section inputs and outputs to 127
lightclient 3492758
core/vm: exit stack validation on terminal op
lightclient 60f1ed3
core/vm: reduce max_stack_height limit to 1023
lightclient c4f8993
core/vm: validate retf outputs
lightclient 2c8a9ab
core/vm: account for input stack height in max stack height calculation
lightclient ae91086
core/vm: increment pos after callf in stack validation
lightclient 96e435d
core/vm: flip comparison operator in stack validation for callf
lightclient 3ab52d5
core/vm: clean up eof unmarshaling errors plus a few other fixes
lightclient c115b1a
core/vm: account for callf return value in stack analysis and some ot…
lightclient 713eb5f
core/vm: fix lints
lightclient cd29313
core/vm: fix incorrect type
lightclient dff09a9
core/vm: clean up eof validation and remove jumpf
lightclient 167e3b9
core/vm: account for callf inputs and add some comments
lightclient 505db9d
cmd/evm: validate pre-allocated eof code in t8n
lightclient f7efe96
core/vm: ban eof code from running legacy initcode
lightclient bd082f5
core/vm: uncomment analysis tests
lightclient 630be09
core/vm: don't consume all gas if eof initcode validation fails
lightclient 2382f83
core/vm: check for full magic in initcode
lightclient f4c5cd7
core/vm: clean stop after retf
lightclient 41cd50b
core/vm: add custom eof errors
lightclient 50110b5
cmd/evm: add eofparser test tool to evm binary
lightclient db10933
core: fix eof blockchain test and reorder magic check
lightclient a229ad6
core/vm: don't update caller nonce on creation if eof validation fails
lightclient d410d2a
core/vm: clean up eof bitmap analysis
lightclient 8fb979f
core/vm: remove custom parser error
lightclient e60f7ec
core/vm: don't use iota to figure out eip-4750 opcodes
lightclient 55bff2b
core/vm: remove unused function
lightclient a1f2a17
core/vm: change formatter in error msg for invalid magic
lightclient e20edd6
core/vm: bump nonce for create tx with invalid eof
lightclient df23888
core/vm: don't double bump nonce when deployed eof is invalid in crea…
lightclient File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// Copyright 2023 The go-ethereum Authors | ||
// This file is part of go-ethereum. | ||
// | ||
// go-ethereum is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// go-ethereum is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"encoding/hex" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func init() { | ||
jt = vm.NewShanghaiEOFInstructionSetForTesting() | ||
} | ||
|
||
var ( | ||
jt vm.JumpTable | ||
errorMap = map[string]int{ | ||
io.ErrUnexpectedEOF.Error(): 1, | ||
vm.ErrInvalidMagic.Error(): 2, | ||
vm.ErrInvalidVersion.Error(): 3, | ||
vm.ErrMissingTypeHeader.Error(): 4, | ||
vm.ErrInvalidTypeSize.Error(): 5, | ||
vm.ErrMissingCodeHeader.Error(): 6, | ||
vm.ErrInvalidCodeHeader.Error(): 7, | ||
vm.ErrMissingDataHeader.Error(): 8, | ||
vm.ErrMissingTerminator.Error(): 9, | ||
vm.ErrTooManyInputs.Error(): 10, | ||
vm.ErrTooManyOutputs.Error(): 11, | ||
vm.ErrTooLargeMaxStackHeight.Error(): 12, | ||
vm.ErrInvalidCodeSize.Error(): 13, | ||
vm.ErrInvalidContainerSize.Error(): 14, | ||
vm.ErrUndefinedInstruction.Error(): 15, | ||
vm.ErrTruncatedImmediate.Error(): 16, | ||
vm.ErrInvalidSectionArgument.Error(): 17, | ||
vm.ErrInvalidJumpDest.Error(): 18, | ||
vm.ErrConflictingStack.Error(): 19, | ||
vm.ErrInvalidBranchCount.Error(): 20, | ||
vm.ErrInvalidOutputs.Error(): 21, | ||
vm.ErrInvalidMaxStackHeight.Error(): 22, | ||
vm.ErrInvalidCodeTermination.Error(): 23, | ||
vm.ErrUnreachableCode.Error(): 24, | ||
} | ||
) | ||
|
||
type EOFTest struct { | ||
Code string `json:"code"` | ||
Results map[string]etResult `json:"results"` | ||
} | ||
|
||
type etResult struct { | ||
Result bool `json:"result"` | ||
Exception int `json:"exception,omitempty"` | ||
} | ||
|
||
func eofParser(ctx *cli.Context) error { | ||
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false))) | ||
glogger.Verbosity(log.Lvl(ctx.Int(VerbosityFlag.Name))) | ||
log.Root().SetHandler(glogger) | ||
|
||
// If `--hex` is set, parse and validate the hex string argument. | ||
if ctx.IsSet(HexFlag.Name) { | ||
if _, err := parseAndValidate(ctx.String(HexFlag.Name)); err != nil { | ||
if err2 := errors.Unwrap(err); err2 != nil { | ||
err = err2 | ||
} | ||
return fmt.Errorf("err(%d): %w", errorMap[err.Error()], err) | ||
} | ||
fmt.Println("ok.") | ||
return nil | ||
} | ||
|
||
// If `--test` is set, parse and validate the reference test at the provided path. | ||
if ctx.IsSet(RefTestFlag.Name) { | ||
src, err := os.ReadFile(ctx.String(RefTestFlag.Name)) | ||
if err != nil { | ||
return err | ||
} | ||
var tests map[string]EOFTest | ||
if err = json.Unmarshal(src, &tests); err != nil { | ||
return err | ||
} | ||
passed, total := 0, 0 | ||
for name, tt := range tests { | ||
for fork, r := range tt.Results { | ||
total++ | ||
// TODO(matt): all tests currently run against | ||
// shanghai EOF, add support for custom forks. | ||
_, err := parseAndValidate(tt.Code) | ||
if err2 := errors.Unwrap(err); err2 != nil { | ||
err = err2 | ||
} | ||
if r.Result && err != nil { | ||
fmt.Fprintf(os.Stderr, "%s, %s: expected success, got %v\n", name, fork, err) | ||
continue | ||
} | ||
if !r.Result && err == nil { | ||
fmt.Fprintf(os.Stderr, "%s, %s: expected error %d, got %v\n", name, fork, r.Exception, err) | ||
continue | ||
} | ||
if !r.Result && err != nil && r.Exception != errorMap[err.Error()] { | ||
fmt.Fprintf(os.Stderr, "%s, %s: expected error %d, got: err(%d): %v\n", name, fork, r.Exception, errorMap[err.Error()], err) | ||
continue | ||
} | ||
passed++ | ||
} | ||
} | ||
fmt.Printf("%d/%d tests passed.\n", passed, total) | ||
return nil | ||
} | ||
|
||
// If neither are passed in, read input from stdin. | ||
scanner := bufio.NewScanner(os.Stdin) | ||
for scanner.Scan() { | ||
t := strings.TrimSpace(scanner.Text()) | ||
if len(t) == 0 || t[0] == '#' { | ||
continue | ||
} | ||
if _, err := parseAndValidate(t); err != nil { | ||
if err2 := errors.Unwrap(err); err2 != nil { | ||
err = err2 | ||
} | ||
fmt.Fprintf(os.Stderr, "err(%d): %v\n", errorMap[err.Error()], err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func parseAndValidate(s string) (*vm.Container, error) { | ||
if len(s) >= 2 && strings.HasPrefix(s, "0x") { | ||
s = s[2:] | ||
} | ||
b, err := hex.DecodeString(s) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to decode data: %w", err) | ||
} | ||
var c vm.Container | ||
if err := c.UnmarshalBinary(b); err != nil { | ||
return nil, err | ||
} | ||
if err := c.ValidateCode(&jt); err != nil { | ||
return nil, err | ||
} | ||
return &c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { | ||
"balance": "0x0", | ||
"code": "0xef01", | ||
"nonce": "0x1", | ||
"storage": {} | ||
}, | ||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0c": { | ||
"balance": "0x0", | ||
"code": "0xef0001010008020002000700020300000000000002020100025959b0000250b101b1", | ||
"nonce": "0x1", | ||
"storage": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", | ||
"currentDifficulty": null, | ||
"currentRandom": "0xdeadc0de", | ||
"currentGasLimit": "0x750a163df65e8a", | ||
"parentBaseFee": "0x500", | ||
"parentGasUsed": "0x0", | ||
"parentGasLimit": "0x750a163df65e8a", | ||
"currentNumber": "1", | ||
"currentTimestamp": "1000" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think t8n tool should also check that before the EOF fork, code in prestate doesn't start with
EF00