Skip to content

cmd/evm: add --prestate, --sender, --json flags for fuzzing#14476

Merged
fjl merged 7 commits into
ethereum:masterfrom
holiman:evmfuzz
Jun 7, 2017
Merged

cmd/evm: add --prestate, --sender, --json flags for fuzzing#14476
fjl merged 7 commits into
ethereum:masterfrom
holiman:evmfuzz

Conversation

@holiman
Copy link
Copy Markdown
Contributor

@holiman holiman commented May 15, 2017

This is work in progress, do not merge yet.

This adds support to execute evm with a custom genesis, primarily to be able to use alloc section and config to test various evm hardfork rule implementations.

Example execution below

#cat g.json 
{
  "nonce":      "0x0000000000000000",
  "difficulty": "0x1",
  "mixhash":    "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase":   "0x0000000000000000000000000000000000000000",
  "timestamp":  "0x00",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData":  "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit":   "0x3D0900",
  "alloc": {
    "0x2a50613a76a4c2c58d052d5ebf3b03ed3227eae9" :{ "balance": "1000000000000000000000000"}
  },
    "config": {
            "homesteadBlock": 10
    }
}

Execution with the specified genesis file, with frontier-rules, where BALANCE cost 20, and 0x2a50613a76a4c2c58d052d5ebf3b03ed3227eae9 has some ether allocated:

[~/go/src/github.com/ethereum/go-ethereum]
#make evm && build/bin/evm --debug --genesisflag g.json --code "732a50613a76a4c2c58d052d5ebf3b03ed3227eae931" run 
build/env.sh go run build/ci.go install ./cmd/evm
>>> /usr/local/go/bin/go install -ldflags -X main.gitCommit=ef7b9fb7d0cbcc2e381074f6be82e4791c41bdeb -v ./cmd/evm
github.com/ethereum/go-ethereum/cmd/evm
Done building.
Run "build/bin/evm" to start the evm.
GenesisPath: g.json
Genesi config {ChainID: <nil> Homestead: 10 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: <nil> EIP158: <nil> Engine: unknown}#### TRACE ####
PUSH20    pc=00000000 gas=9999999997 cost=3

BALANCE   pc=00000021 gas=9999999977 cost=20
00000000  0000000000000000000000002a50613a76a4c2c58d052d5ebf3b03ed3227eae9

STOP      pc=00000022 gas=9999999977 cost=0
00000000  00000000000000000000000000000000000000000000d3c21bcecceda1000000

#### LOGS ####
evm execution time: 60.482µs
heap objects:       10345
allocations:        1866256
total allocations:  1866256
GC calls:           0

0x

Execution with defaults, ( latest HF rules), where BALANCE cost 400, and 0x2a50613a76a4c2c58d052d5ebf3b03ed3227eae9 is not prefunded:

[~/go/src/github.com/ethereum/go-ethereum]
#make evm && build/bin/evm --debug --code "732a50613a76a4c2c58d052d5ebf3b03ed3227eae931" run 
build/env.sh go run build/ci.go install ./cmd/evm
>>> /usr/local/go/bin/go install -ldflags -X main.gitCommit=ef7b9fb7d0cbcc2e381074f6be82e4791c41bdeb -v ./cmd/evm
Done building.
Run "build/bin/evm" to start the evm.
#### TRACE ####
PUSH20    pc=00000000 gas=9999999997 cost=3

BALANCE   pc=00000021 gas=9999999597 cost=400
00000000  0000000000000000000000002a50613a76a4c2c58d052d5ebf3b03ed3227eae9

STOP      pc=00000022 gas=9999999597 cost=0
00000000  0000000000000000000000000000000000000000000000000000000000000000

#### LOGS ####
evm execution time: 47.425µs
heap objects:       10047
allocations:        1840664
total allocations:  1840664
GC calls:           0

0x

@GitCop
Copy link
Copy Markdown

GitCop commented May 15, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 5bbc233df42758971e9ebc01de44ceb4997d6f27
  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented May 15, 2017

Added support for json output:

#build/bin/evm --debug --code "732a50613a76a4c2c58d052d5ebf3b03ed3227eae9316001600155" --json --genesis g.json run 2>/dev/null
{"Pc":0,"Op":115,"Gas":9999999997,"GasCost":3,"Memory":"","Stack":[],"Storage":{},"Depth":1,"Err":null}
{"Pc":21,"Op":49,"Gas":9999999977,"GasCost":20,"Memory":"","Stack":[241570141776300762653945057459344026450497366761],"Storage":{},"Depth":1,"Err":null}
{"Pc":22,"Op":96,"Gas":9999999974,"GasCost":3,"Memory":"","Stack":[1000000000000000000000000],"Storage":{},"Depth":1,"Err":null}
{"Pc":24,"Op":96,"Gas":9999999971,"GasCost":3,"Memory":"","Stack":[1000000000000000000000000,1],"Storage":{},"Depth":1,"Err":null}
{"Pc":26,"Op":85,"Gas":9999979971,"GasCost":20000,"Memory":"","Stack":[1000000000000000000000000,1,1],"Storage":{"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001"},"Depth":1,"Err":null}
{"Pc":27,"Op":0,"Gas":9999979971,"GasCost":0,"Memory":"","Stack":[1000000000000000000000000],"Storage":{"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001"},"Depth":1,"Err":null}
0x

@holiman holiman force-pushed the evmfuzz branch 2 times, most recently from 81e07ab to 252a836 Compare May 19, 2017 12:54
@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented May 19, 2017

Rebased. This is pretty good-to-go, but as I'm waiting for Parity to build something similar, I may have to modify it a bit to behave the same way as theirs. So IMO it can be merged now or later, not time-critical

@obscuren
Copy link
Copy Markdown
Contributor

I've looked at this PR 3 times now and I've been trying to make sense of this in my head. I still can't figure out why this is needed. Can you please explain?

@fjl fjl changed the title EVM custom genesis+chainconfig cmd/evm: add --genesis and --json options May 24, 2017
@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented May 25, 2017

I've rebased it now and changed the flag name to prestate

@fjl fjl modified the milestone: 1.6.3 May 31, 2017
@karalabe karalabe modified the milestones: 1.6.4, 1.6.3 Jun 1, 2017
@obscuren
Copy link
Copy Markdown
Contributor

obscuren commented Jun 1, 2017

@holiman I think the JSON output needs to be formatted using lower camel case, not upper camel. Please add json:"gas" etc.

@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented Jun 2, 2017

I've done that, I just haven't committed the most recent code yet.

@obscuren
Copy link
Copy Markdown
Contributor

obscuren commented Jun 2, 2017

👍

@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented Jun 4, 2017

I've added ability for the evm to report gas used, and show it in statdump.

@holiman holiman force-pushed the evmfuzz branch 2 times, most recently from 129ac97 to 34ffdb3 Compare June 5, 2017 07:13
@holiman holiman force-pushed the evmfuzz branch 2 times, most recently from aa4af37 to 21ac4dd Compare June 5, 2017 07:21
Comment thread core/vm/logger.go Outdated
Gas math.HexOrDecimal64 `json:"gas"`
GasCost math.HexOrDecimal64 `json:"gasCost"`
Memory string `json:"memory"`
Stack hexArray `json:"stack"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can use gencodec to avoid writing the conversion.

//go:generate gencodec -type StructLogJson -field-override structLogJsonMarshaling -out gen_structlog_json.go

type StructLogJson struct{
    ...
    Stack []*big.Int
}

type structLogJsonMarshaling struct{
    Stack []*math.HexOrDecimal256
}

This would create a MarshalJSON method that converts Stack internally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh nice, thanks. I wasn't sure how to cast those kind of spells

Comment thread core/vm/logger.go Outdated

// captureState logs a new structured log message and pushes it out to the environment
// NewJSONLogger returns a new JSON logger
func NewJSONLogger(writer io.Writer) *JSONLogger {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMHO this logger should be defined in cmd/evm.

@holiman holiman modified the milestones: 1.6.6, 1.6.4 Jun 6, 2017
@GitCop
Copy link
Copy Markdown

GitCop commented Jun 7, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: d47802a

  • Commits must be prefixed with the package(s) they modify

  • Commit: bfed02b

  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@GitCop
Copy link
Copy Markdown

GitCop commented Jun 7, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: d47802a

  • Commits must be prefixed with the package(s) they modify

  • Commit: bfed02b

  • Commits must be prefixed with the package(s) they modify

  • Commit: b1f55451504b480f939c1546588847ecd4de16a9

  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@holiman holiman changed the title cmd/evm: add --genesis and --json options Make EVM binary support prestate, and output JSON Jun 7, 2017
@fjl fjl changed the title Make EVM binary support prestate, and output JSON cmd/evm: add --prestate, --sender, --json flags for fuzzing Jun 7, 2017
@fjl fjl merged commit 80f7c6c into ethereum:master Jun 7, 2017
holiman added a commit to holiman/go-ethereum that referenced this pull request Jun 19, 2017
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.

5 participants