-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request adds support for [EELS](https://github.com/ethereum/execution-specs)' `ethereum-spec-evm`. Requires an _extremely_ new checkout (at least ethereum/execution-specs@c4f5b8a).
- Loading branch information
Showing
41 changed files
with
2,034 additions
and
10 deletions.
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
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,74 @@ | ||
# | ||
# The Mega Dockerfile | ||
# | ||
# This dockerfile is an attempt to bundle the following components into | ||
# one big dockerfile: | ||
# | ||
# - [x] Goevmlab binaries | ||
# - [x] Go-ethereum binary 'evm' | ||
# - [ ] Erigon binary 'evm' | ||
# - [ ] EvmOne vm binary 'evmone' | ||
# - [ ] Reth VM binary 'revme' | ||
# - [ ] Besu | ||
# - [ ] Nethermind | ||
# - [ ] Nimbus-eth1 | ||
# - [x] EELS | ||
# | ||
|
||
#--------------------------------------------------------------- | ||
# golang-builder (debian-based) | ||
#--------------------------------------------------------------- | ||
FROM golang:latest as golang-builder | ||
|
||
# | ||
# Go-evmlab | ||
# | ||
|
||
RUN git clone https://github.com/SamWilsn/goevmlab --depth 1 --branch eels-evm | ||
RUN cd goevmlab && \ | ||
go build ./cmd/generic-fuzzer && \ | ||
go build ./cmd/checkslow && \ | ||
go build ./cmd/minimizer && \ | ||
go build ./cmd/repro && \ | ||
go build ./cmd/runtest && \ | ||
go build ./cmd/tracediff && \ | ||
go build ./cmd/traceview | ||
|
||
# | ||
# GETH | ||
# | ||
|
||
RUN git clone https://github.com/ethereum/go-ethereum --depth 1 | ||
RUN cd go-ethereum && go run build/ci.go install -static ./cmd/evm | ||
|
||
# | ||
# Main non-builder | ||
# | ||
|
||
FROM debian:testing | ||
|
||
RUN apt-get update -q | ||
|
||
# Install execution-specs (EELS) | ||
RUN apt-get install -qy --no-install-recommends pipx git && \ | ||
git clone https://github.com/ethereum/execution-specs.git --branch statetests --depth 1 | ||
RUN PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/ pipx install './execution-specs/[test]' | ||
ENV EELS_BIN=/ethereum-spec-evm | ||
|
||
# Go-evmlab targets | ||
COPY --from=golang-builder /go/goevmlab/generic-fuzzer / | ||
COPY --from=golang-builder /go/goevmlab/checkslow / | ||
COPY --from=golang-builder /go/goevmlab/minimizer / | ||
COPY --from=golang-builder /go/goevmlab/repro / | ||
COPY --from=golang-builder /go/goevmlab/runtest / | ||
COPY --from=golang-builder /go/goevmlab/tracediff / | ||
COPY --from=golang-builder /go/goevmlab/traceview / | ||
COPY --from=golang-builder /go/goevmlab/evms/testdata/ /testdata/ | ||
|
||
COPY --from=golang-builder /go/go-ethereum/build/bin/evm /gethvm | ||
ENV GETH_BIN=/gethvm | ||
|
||
|
||
COPY readme_docker.md /README.md | ||
COPY entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/bin/bash"] |
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,187 @@ | ||
// Copyright 2019 Martin Holst Swende | ||
// Copyright 2024 Sam Wilson | ||
// This file is part of the goevmlab library. | ||
// | ||
// The library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This library 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 Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the goevmlab library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package evms | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/eth/tracers/logger" | ||
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
// EelsEVM is s Evm-interface wrapper around the `evm` binary, based on go-ethereum. | ||
type EelsEVM struct { | ||
path string | ||
name string // in case multiple instances are used | ||
|
||
// Some metrics | ||
stats *VmStat | ||
} | ||
|
||
func NewEelsEVM(path string, name string) *EelsEVM { | ||
return &EelsEVM{ | ||
path: path, | ||
name: name, | ||
stats: &VmStat{}, | ||
} | ||
} | ||
|
||
func (evm *EelsEVM) Instance(int) Evm { | ||
return evm | ||
} | ||
|
||
func (evm *EelsEVM) Name() string { | ||
return evm.name | ||
} | ||
|
||
// GetStateRoot runs the test and returns the stateroot | ||
// This currently only works for non-filled statetests. TODO: make it work even if the | ||
// test is filled. Either by getting the whole trace, or adding stateroot to exec std output | ||
// even in success-case | ||
func (evm *EelsEVM) GetStateRoot(path string) (root, command string, err error) { | ||
// In this mode, we can run it without tracing | ||
cmd := exec.Command(evm.path, "statetest", path) | ||
data, err := cmd.Output() | ||
if err != nil { | ||
return "", cmd.String(), err | ||
} | ||
root, err = evm.ParseStateRoot(data) | ||
if err != nil { | ||
log.Error("Failed to find stateroot", "vm", evm.Name(), "cmd", cmd.String()) | ||
return "", cmd.String(), err | ||
} | ||
return root, cmd.String(), err | ||
} | ||
|
||
// ParseStateRoot reads geth's stateroot from the combined output. | ||
func (evm *EelsEVM) ParseStateRoot(data []byte) (string, error) { | ||
start := bytes.Index(data, []byte(`"stateRoot": "`)) | ||
end := start + 14 + 66 | ||
if start == -1 || end >= len(data) { | ||
return "", fmt.Errorf("%v: no stateroot found", evm.Name()) | ||
} | ||
return string(data[start+14 : end]), nil | ||
} | ||
|
||
// RunStateTest implements the Evm interface | ||
func (evm *EelsEVM) RunStateTest(path string, out io.Writer, speedTest bool) (*tracingResult, error) { | ||
var ( | ||
t0 = time.Now() | ||
stderr io.ReadCloser | ||
err error | ||
cmd *exec.Cmd | ||
) | ||
if speedTest { | ||
cmd = exec.Command(evm.path, "statetest", "--nomemory", "--noreturndata", "--nostack", path) | ||
} else { | ||
cmd = exec.Command(evm.path, "statetest", "--json", "--noreturndata", "--nomemory", path) | ||
} | ||
if stderr, err = cmd.StderrPipe(); err != nil { | ||
return &tracingResult{Cmd: cmd.String()}, err | ||
} | ||
if err = cmd.Start(); err != nil { | ||
return &tracingResult{Cmd: cmd.String()}, err | ||
} | ||
// copy everything to the given writer | ||
evm.Copy(out, stderr) | ||
err = cmd.Wait() | ||
// release resources | ||
duration, slow := evm.stats.TraceDone(t0) | ||
|
||
return &tracingResult{ | ||
Slow: slow, | ||
ExecTime: duration, | ||
Cmd: cmd.String(), | ||
}, err | ||
} | ||
|
||
func (vm *EelsEVM) Close() { | ||
} | ||
|
||
// Copy reads from the reader, does some geth-specific filtering and | ||
// outputs items onto the channel | ||
func (evm *EelsEVM) Copy(out io.Writer, input io.Reader) { | ||
evm.copyUntilEnd(out, input) | ||
} | ||
|
||
// copyUntilEnd reads from the reader, does some vm-specific filtering and | ||
// outputs items onto the channel | ||
func (evm *EelsEVM) copyUntilEnd(out io.Writer, input io.Reader) stateRoot { | ||
buf := bufferPool.Get().([]byte) | ||
//lint:ignore SA6002: argument should be pointer-like to avoid allocations. | ||
defer bufferPool.Put(buf) | ||
var stateRoot stateRoot | ||
scanner := bufio.NewScanner(input) | ||
scanner.Buffer(buf, 32*1024*1024) | ||
for scanner.Scan() { | ||
data := scanner.Bytes() | ||
if len(data) > 0 && data[0] == '#' { | ||
// Output preceded by # is ignored, but can be used for debugging, e.g. | ||
// to check that the generated tests cover the intended surface. | ||
fmt.Printf("%v: %v\n", evm.Name(), string(data)) | ||
continue | ||
} | ||
var elem logger.StructLog | ||
if err := json.Unmarshal(data, &elem); err != nil { | ||
fmt.Printf("eels err: %v, line\n\t%v\n", err, string(data)) | ||
continue | ||
} | ||
// If the output cannot be marshalled, all fields will be blanks. | ||
// We can detect that through 'depth', which should never be less than 1 | ||
// for any actual opcode | ||
if elem.Depth == 0 { | ||
/* It might be the stateroot | ||
{"output":"","gasUsed":"0x2d1cc4","error":"gas uint64 overflow"} | ||
{"stateRoot": "0xa2b3391f7a85bf1ad08dc541a1b99da3c591c156351391f26ec88c557ff12134"} | ||
*/ | ||
if stateRoot.StateRoot == "" { | ||
_ = json.Unmarshal(data, &stateRoot) | ||
} | ||
// If we have a stateroot, we're done | ||
if len(stateRoot.StateRoot) > 0 { | ||
break | ||
} | ||
continue | ||
} | ||
// When geth encounters end of code, it continues anyway, on a 'virtual' STOP. | ||
// In order to handle that, we need to drop all STOP opcodes. | ||
if elem.Op == 0x0 { | ||
continue | ||
} | ||
outp := FastMarshal(&elem) | ||
if _, err := out.Write(append(outp, '\n')); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error writing to out: %v\n", err) | ||
} | ||
} | ||
root, _ := json.Marshal(stateRoot) | ||
if _, err := out.Write(append(root, '\n')); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error writing to out: %v\n", err) | ||
} | ||
return stateRoot | ||
} | ||
|
||
func (evm *EelsEVM) Stats() []any { | ||
return evm.stats.Stats() | ||
} |
Oops, something went wrong.