-
Notifications
You must be signed in to change notification settings - Fork 19.6k
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
WIP mega eof #29518
Draft
MariusVanDerWijden
wants to merge
54
commits into
ethereum:master
Choose a base branch
from
MariusVanDerWijden:mega-eof
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,599
−216
Draft
WIP mega eof #29518
Changes from 16 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
c23f8af
core/vm: add eof container
lightclient e8953bd
happy lint, happy life
MariusVanDerWijden 9aa46f3
core/vm: add optional containerSections
MariusVanDerWijden 9ca1532
core/vm: add optional containerSections
MariusVanDerWijden e5724b2
core/types: implement InitCodeTransaction for EOF
MariusVanDerWijden 4723974
core/vm: implement JUMPF, added disallowed opcodes
MariusVanDerWijden 1e381a3
core/vm: started work on eofcreate, safety push
MariusVanDerWijden 319d022
core/vm: started work on eofcreate
MariusVanDerWijden ed5b362
core/vm: implement dataload opcodes
MariusVanDerWijden 61aa4c1
core/vm: implement dupN, swapN
MariusVanDerWijden 1762ea3
core/vm: refactor using min
MariusVanDerWijden e1e0a7a
core/vm: implement opReturnDataLoad
MariusVanDerWijden 6e16cf5
core/vm: implement opExt{Call,StaticCall,DelegateCall}
MariusVanDerWijden 5eac46f
core/vm: added opcode names
MariusVanDerWijden 9640e5f
core/vm: add opcodes to the jumptable
MariusVanDerWijden 7e7517d
cmd/evm: implement evm eofdump
MariusVanDerWijden 22f49b5
cmd/evm: implement evm eofdump
MariusVanDerWijden b537b7d
cmd/evm: fix tests
MariusVanDerWijden fc4f265
cmd/eofdump: move eofdump to own subcommand
MariusVanDerWijden e677308
core/vm: fixed bug in marshaling
MariusVanDerWijden 9443916
core/vm: better validation
MariusVanDerWijden f5ecd89
core/vm: fixed pc skip
MariusVanDerWijden ee16514
cmd/eofdump: add recursive mode for tests
MariusVanDerWijden a033d6b
core/vm: fix a few bugs, prettier print
MariusVanDerWijden 8835928
core/vm: fix bugs in DATALOADN, Validation, PUSH9 etc
MariusVanDerWijden f669cfc
core/vm: fix bugs in RETURNCONTRACT validation
MariusVanDerWijden 06872b2
core/vm: fix bugs in EOFCREATE validation and others
MariusVanDerWijden 96fd50a
core/vm: make sure every section is reachable
MariusVanDerWijden 046f287
core/vm: fix subcontainer validation
MariusVanDerWijden efb9807
core/vm: fix max-stack-height validation
MariusVanDerWijden 44d876c
core/vm: fix RJUMPV to use max_size + 1, fix tests
MariusVanDerWijden 56a0ca8
core/vm: fix CALLF stack height validation
MariusVanDerWijden 104df43
core/vm: fix DUPN, SWAPN, EXCHANGE stack height validation
MariusVanDerWijden ab6003b
core/vm: fix DUPN, SWAPN, EXCHANGE stack height validation
MariusVanDerWijden 4add7c2
core/vm: fix JUMPF stack height validation
MariusVanDerWijden f762178
core/vm: fix backward jump validation
MariusVanDerWijden 3929447
core/vm: fix ext stack heights, fix jumpdest validation bitmap
MariusVanDerWijden 2f91f0b
core/vm: started work on linear validation
MariusVanDerWijden 8c7de99
core/vm: more fixes for validate_linear
MariusVanDerWijden 65a20c4
core/vm: more fixes for validate_linear
MariusVanDerWijden ab1c88c
core/vm: fix stack limit
MariusVanDerWijden 076a587
core/vm: fix rjumpv offsets
MariusVanDerWijden a643fe9
core/vm: fix test
MariusVanDerWijden 4d29707
core/vm: fix underflow checks
MariusVanDerWijden 49086d5
core/vm: fix a bunch of validation bugs
MariusVanDerWijden 38d86bd
core/vm: fixed RJUMP bugs
MariusVanDerWijden 345b79f
core/vm: correctly set bounds for underflow
MariusVanDerWijden d1051a5
core/vm: fix off-by-one error in exchange validation
MariusVanDerWijden 1da9562
core/vm: fix error in DUPN/SWAPN
MariusVanDerWijden 81cf881
core/vm: fixed copy paste error
MariusVanDerWijden 2fde71e
core/vm: fix off-by-one in rjumpv
MariusVanDerWijden c3c3a28
core/vm: reordered logic
MariusVanDerWijden b789efe
core/vm: simplify
MariusVanDerWijden 19d492e
core/vm: validate rjump destination
MariusVanDerWijden File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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,184 @@ | ||
// 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/urfave/cli/v2" | ||
) | ||
|
||
func init() { | ||
jt = vm.NewPragueEOFInstructionSetForTesting() | ||
} | ||
|
||
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 { | ||
// 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 | ||
} | ||
|
||
func eofDump(ctx *cli.Context) error { | ||
// If `--hex` is set, parse and validate the hex string argument. | ||
if ctx.IsSet(HexFlag.Name) { | ||
s := ctx.String(HexFlag.Name) | ||
if len(s) >= 2 && strings.HasPrefix(s, "0x") { | ||
s = s[2:] | ||
} | ||
b, err := hex.DecodeString(s) | ||
if err != nil { | ||
return fmt.Errorf("unable to decode data: %w", err) | ||
} | ||
var c vm.Container | ||
if err := c.UnmarshalBinary(b); err != nil { | ||
return err | ||
} | ||
fmt.Print(c.String()) | ||
return nil | ||
} | ||
return 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
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.
we have
cmd/rlpdump
andcmd/abidump
. How about acmd/eofdump
?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.
Yep, will move