Skip to content

Commit

Permalink
cmd/evm: improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Jul 3, 2021
1 parent 3670f9c commit 1880505
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 48 deletions.
68 changes: 34 additions & 34 deletions cmd/evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,45 +239,46 @@ The `BLOCKHASH` opcode requires blockhashes to be provided by the caller, inside
If a required blockhash is not provided, the exit code should be `4`:
Example where blockhashes are provided:
```
./evm t8n --input.alloc=./testdata/3/alloc.json --input.txs=./testdata/3/txs.json --input.env=./testdata/3/env.json --trace
./evm --verbosity=1 t8n --input.alloc=./testdata/3/alloc.json --input.txs=./testdata/3/txs.json --input.env=./testdata/3/env.json --trace
INFO [07-03|18:35:02.557] Trie dumping started root=b7341d..857ea1
INFO [07-03|18:35:02.557] Trie dumping complete accounts=3 elapsed="152.102µs"
INFO [07-03|18:35:02.559] Wrote file file=alloc.json
INFO [07-03|18:35:02.565] Wrote file file=result.json
```
INFO [06-30|22:56:04.664] Trie dumping started root=b7341d..857ea1
INFO [06-30|22:56:04.664] Trie dumping complete accounts=3 elapsed="186.324µs"
INFO [06-30|22:56:04.665] Wrote file file=alloc.json
INFO [06-30|22:56:04.665] Wrote file file=result.json

```
cat trace-0-0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81.jsonl | grep BLOCKHASH -C2
```
```
{"pc":0,"op":96,"gas":"0x5f58ef8","gasCost":"0x3","memory":"0x","memSize":0,"stack":[],"returnStack":null,"returnData":"0x","depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":2,"op":64,"gas":"0x5f58ef5","gasCost":"0x14","memory":"0x","memSize":0,"stack":["0x1"],"returnStack":null,"returnData":"0x","depth":1,"refund":0,"opName":"BLOCKHASH","error":""}
{"pc":3,"op":0,"gas":"0x5f58ee1","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0xdac58aa524e50956d0c0bae7f3f8bb9d35381365d07804dd5b48a5a297c06af4"],"returnStack":null,"returnData":"0x","depth":1,"refund":0,"opName":"STOP","error":""}
{"output":"","gasUsed":"0x17","time":677139}
{"output":"","gasUsed":"0x17","time":352278}
```

In this example, the caller has not provided the required blockhash:
```
./evm t8n --input.alloc=./testdata/4/alloc.json --input.txs=./testdata/4/txs.json --input.env=./testdata/4/env.json --trace
```
```
ERROR(4): getHash(3) invoked, blockhash for that block not provided
```
Error code: 4
transition-test.sh: line 171: ecoh: command not found
### Chaining

Another thing that can be done, is to chain invocations:
```
./evm t8n --input.alloc=./testdata/1/alloc.json --input.txs=./testdata/1/txs.json --input.env=./testdata/1/env.json --output.alloc=stdout | ./evm t8n --input.alloc=stdin --input.env=./testdata/1/env.json --input.txs=./testdata/1/txs.json
INFO [06-30|22:56:04.791] rejected tx index=1 hash=0557ba..18d673 from=0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 error="nonce too low: address 0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192, tx: 0 state: 1"
INFO [06-30|22:56:04.793] Trie dumping started root=84208a..ae4e13
INFO [06-30|22:56:04.793] Trie dumping complete accounts=3 elapsed="391.808µs"
INFO [06-30|22:56:04.794] Wrote file file=result.json
INFO [06-30|22:56:04.795] rejected tx index=0 hash=0557ba..18d673 from=0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 error="nonce too low: address 0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192, tx: 0 state: 1"
INFO [06-30|22:56:04.795] rejected tx index=1 hash=0557ba..18d673 from=0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 error="nonce too low: address 0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192, tx: 0 state: 1"
INFO [06-30|22:56:04.796] Trie dumping started root=84208a..ae4e13
INFO [06-30|22:56:04.796] Trie dumping complete accounts=3 elapsed="59.341µs"
INFO [06-30|22:56:04.796] Wrote file file=alloc.json
INFO [06-30|22:56:04.799] Wrote file file=result.json
INFO [07-03|18:35:02.656] rejected tx index=1 hash=0557ba..18d673 from=0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 error="nonce too low: address 0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192, tx: 0 state: 1"
INFO [07-03|18:35:02.656] Trie dumping started root=84208a..ae4e13
INFO [07-03|18:35:02.657] Trie dumping complete accounts=3 elapsed="76.053µs"
INFO [07-03|18:35:02.657] Wrote file file=result.json
INFO [07-03|18:35:02.659] rejected tx index=0 hash=0557ba..18d673 from=0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 error="nonce too low: address 0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192, tx: 0 state: 1"
INFO [07-03|18:35:02.659] rejected tx index=1 hash=0557ba..18d673 from=0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 error="nonce too low: address 0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192, tx: 0 state: 1"
INFO [07-03|18:35:02.659] Trie dumping started root=84208a..ae4e13
INFO [07-03|18:35:02.659] Trie dumping complete accounts=3 elapsed="77.406µs"
INFO [07-03|18:35:02.659] Wrote file file=alloc.json
INFO [07-03|18:35:02.659] Wrote file file=result.json
```
What happened here, is that we first applied two identical transactions, so the second one was rejected.
Expand All @@ -293,43 +294,42 @@ It is possible to provide already-signed transactions as input to, using an `inp
The input format for RLP-form transactions is _identical_ to the _output_ format for block bodies. Therefore, it's fully possible
to use the evm to go from `json` input to `rlp` input.

```
The following command takes **json** the transactions in `./testdata/12/txs.json` and signs them. After execution, they are output to `signed_txs.rlp`.:
```
./evm t8n --state.fork=London --input.alloc=./testdata/12/alloc.json --input.txs=./testdata/12/txs.json --input.env=./testdata/12/env.json --output.result=alloc_jsontx.json --output.body=signed_txs.rlp
INFO [06-30|22:56:04.840] Trie dumping started root=e4b924..6aef61
INFO [06-30|22:56:04.841] Trie dumping complete accounts=3 elapsed=1.027ms
INFO [06-30|22:56:04.841] Wrote file file=alloc.json
INFO [06-30|22:56:04.842] Wrote file file=alloc_jsontx.json
INFO [06-30|22:56:04.842] Wrote file file=signed_txs.rlp
INFO [07-03|18:35:02.700] Trie dumping started root=e4b924..6aef61
INFO [07-03|18:35:02.700] Trie dumping complete accounts=3 elapsed="170.36µs"
INFO [07-03|18:35:02.700] Wrote file file=alloc.json
INFO [07-03|18:35:02.700] Wrote file file=alloc_jsontx.json
INFO [07-03|18:35:02.700] Wrote file file=signed_txs.rlp
```

The `output.body` is the rlp-list of transactions, encoded in hex and placed in a string a'la `json` encoding rules:
```
cat signed_txs.rlp
"0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9"
```

We can use `rlpdump` to check what the contents are:
We can use `rlpdump` to check what the contents are:
```
rlpdump -hex $(cat signed_txs.rlp | jq -r )
[
02f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904,
02f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9,
02f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904,
02f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9,
]
```
Now, we can now use those (or any other already signed transactions), as input, like so:
Now, we can now use those (or any other already signed transactions), as input, like so:
```
./evm t8n --state.fork=London --input.alloc=./testdata/12/alloc.json --input.txs=./signed_txs.rlp --input.env=./testdata/12/env.json --output.result=alloc_rlptx.json
INFO [06-30|22:56:04.932] Trie dumping started root=e4b924..6aef61
INFO [06-30|22:56:04.932] Trie dumping complete accounts=3 elapsed="256.802µs"
INFO [06-30|22:56:04.932] Wrote file file=alloc.json
INFO [06-30|22:56:04.933] Wrote file file=alloc_rlptx.json
INFO [07-03|18:35:02.781] Trie dumping started root=e4b924..6aef61
INFO [07-03|18:35:02.782] Trie dumping complete accounts=3 elapsed="119.664µs"
INFO [07-03|18:35:02.782] Wrote file file=alloc.json
INFO [07-03|18:35:02.782] Wrote file file=alloc_rlptx.json
```

You might have noticed that the results from these two invocations were stored in two separate files.
You might have noticed that the results from these two invocations were stored in two separate files.
And we can now finally check that they match.
```
cat alloc_jsontx.json | jq .stateRoot && cat alloc_rlptx.json | jq .stateRoot
Expand Down
18 changes: 4 additions & 14 deletions cmd/evm/transition-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ echo ""
echo "The \`BLOCKHASH\` opcode requires blockhashes to be provided by the caller, inside the \`env\`."
echo "If a required blockhash is not provided, the exit code should be \`4\`:"
echo "Example where blockhashes are provided: "
cmd="./evm t8n --input.alloc=./testdata/3/alloc.json --input.txs=./testdata/3/txs.json --input.env=./testdata/3/env.json --trace"
tick && echo $cmd && tick
$cmd 2>&1 >/dev/null
demo "./evm --verbosity=1 t8n --input.alloc=./testdata/3/alloc.json --input.txs=./testdata/3/txs.json --input.env=./testdata/3/env.json --trace"
cmd="cat trace-0-0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81.jsonl | grep BLOCKHASH -C2"
tick && echo $cmd && tick
echo "$ticks"
Expand All @@ -166,13 +164,11 @@ echo ""

echo "In this example, the caller has not provided the required blockhash:"
cmd="./evm t8n --input.alloc=./testdata/4/alloc.json --input.txs=./testdata/4/txs.json --input.env=./testdata/4/env.json --trace"
tick && echo $cmd && tick
tick
$cmd
tick && echo $cmd && $cmd
errc=$?
tick
echo "Error code: $errc"

ecoh ""

echo "### Chaining"
echo ""
Expand All @@ -198,14 +194,8 @@ echo "It is possible to provide already-signed transactions as input to, using a
echo "The input format for RLP-form transactions is _identical_ to the _output_ format for block bodies. Therefore, it's fully possible"
echo "to use the evm to go from \`json\` input to \`rlp\` input."
echo ""
echo "$ticks"
echo "The following command takes **json** the transactions in \`./testdata/12/txs.json\` and signs them. After execution, they are output to \`signed_txs.rlp\`.:"
cmd="./evm t8n --state.fork=London --input.alloc=./testdata/12/alloc.json --input.txs=./testdata/12/txs.json --input.env=./testdata/12/env.json --output.result=alloc_jsontx.json --output.body=signed_txs.rlp"
echo "$ticks"
echo "$cmd"
output=$($cmd)
echo $output
echo "$ticks"
demo "./evm t8n --state.fork=London --input.alloc=./testdata/12/alloc.json --input.txs=./testdata/12/txs.json --input.env=./testdata/12/env.json --output.result=alloc_jsontx.json --output.body=signed_txs.rlp"
echo "The \`output.body\` is the rlp-list of transactions, encoded in hex and placed in a string a'la \`json\` encoding rules:"
demo "cat signed_txs.rlp"
echo "We can use \`rlpdump\` to check what the contents are: "
Expand Down

0 comments on commit 1880505

Please sign in to comment.