Skip to content

Commit c9f87f7

Browse files
dwightguthehildenb
authored andcommitted
implement EXTCODEHASH in node. (#403)
* deps/plugin: update plugin submodule * evm, evm-node: extcodehash in node mode * don't build ocaml node
1 parent 9ae34f5 commit c9f87f7

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ $(DEFN_DIR)/ocaml/$(MAIN_DEFN_FILE)-kompiled/constants.$(EXT): $(ocaml_files)
241241
eval $$(opam config env) \
242242
&& $(K_BIN)/kompile --debug --main-module $(MAIN_MODULE) \
243243
--syntax-module $(SYNTAX_MODULE) $(DEFN_DIR)/ocaml/$(MAIN_DEFN_FILE).k \
244-
--hook-namespaces "KRYPTO BLOCKCHAIN" --gen-ml-only -O3 --non-strict \
244+
--hook-namespaces "KRYPTO" --gen-ml-only -O3 --non-strict \
245245
--directory $(DEFN_DIR)/ocaml -I $(DEFN_DIR)/ocaml $(KOMPILE_OPTS) \
246246
&& cd $(DEFN_DIR)/ocaml/$(MAIN_DEFN_FILE)-kompiled \
247247
&& ocamlfind $(OCAMLC) -c -g constants.ml -package gmp -package zarith -safe-string
@@ -254,9 +254,9 @@ $(DEFN_DIR)/ocaml/$(MAIN_DEFN_FILE)-kompiled/plugin/semantics.$(LIBEXT): $(wildc
254254
&& ocaml-protoc $(PLUGIN_SUBMODULE)/plugin/proto/*.proto -ml_out $(dir $@) \
255255
&& cd $(dir $@) \
256256
&& ocamlfind $(OCAMLC) -c -g -I $(CURDIR)/$(DEFN_DIR)/ocaml/$(MAIN_DEFN_FILE)-kompiled \
257-
msg_types.mli msg_types.ml msg_pb.mli msg_pb.ml apiVersion.ml world.mli world.ml caching.mli caching.ml BLOCKCHAIN.ml KRYPTO.ml \
257+
KRYPTO.ml \
258258
-package cryptokit -package secp256k1 -package bn128 -package ocaml-protoc -safe-string -thread \
259-
&& ocamlfind $(OCAMLC) -a -o semantics.$(LIBEXT) KRYPTO.$(EXT) msg_types.$(EXT) msg_pb.$(EXT) apiVersion.$(EXT) world.$(EXT) caching.$(EXT) BLOCKCHAIN.$(EXT) -thread \
259+
&& ocamlfind $(OCAMLC) -a -o semantics.$(LIBEXT) KRYPTO.$(EXT) -thread \
260260
&& ocamlfind remove ethereum-semantics-plugin-ocaml \
261261
&& ocamlfind install ethereum-semantics-plugin-ocaml $(PLUGIN_SUBMODULE)/plugin/META semantics.* *.cmi *.$(EXT)
262262

evm-node.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Because the same account may be loaded more than once, implementations of this i
2222
- Empty code is detected without lazy evaluation by means of checking the code hash, and therefore will always be represented in the `<code>` cell as `.WordStack`.
2323

2424
```{.k .node}
25-
syntax AccountCode ::= "#unloaded"
25+
syntax AccountCode ::= #unloaded(Int)
2626
```
2727

2828
- `#getBalance` returns the balance of an account that exists based on its integer address.
@@ -31,9 +31,10 @@ Because the same account may be loaded more than once, implementations of this i
3131
- `#accountExists` returns true if the account is present in the state trie for the current block, and false otherwise.
3232

3333
```{.k .node}
34-
syntax Int ::= #getBalance ( Int ) [function, hook(BLOCKCHAIN.getBalance)]
35-
| #getNonce ( Int ) [function, hook(BLOCKCHAIN.getNonce)]
36-
// -------------------------------------------------------------------------
34+
syntax Int ::= #getBalance ( Int ) [function, hook(BLOCKCHAIN.getBalance)]
35+
| #getNonce ( Int ) [function, hook(BLOCKCHAIN.getNonce)]
36+
| #getCodeHash ( Int ) [function, hook(BLOCKCHAIN.getCodeHash)]
37+
// -----------------------------------------------------------------------------
3738
3839
syntax Bool ::= #isCodeEmpty ( Int ) [function, hook(BLOCKCHAIN.isCodeEmpty)]
3940
| #accountExists ( Int ) [function, hook(BLOCKCHAIN.accountExists)]
@@ -51,7 +52,7 @@ Because the same account may be loaded more than once, implementations of this i
5152
=> <account>
5253
<acctID> ACCT </acctID>
5354
<balance> #getBalance(ACCT) </balance>
54-
<code> #if #isCodeEmpty(ACCT) #then .WordStack #else #unloaded #fi </code>
55+
<code> #if #isCodeEmpty(ACCT) #then .WordStack #else #unloaded(#getCodeHash(ACCT)) #fi </code>
5556
<storage> .Map </storage>
5657
<origStorage> .Map </origStorage>
5758
<nonce> #getNonce(ACCT) </nonce>
@@ -102,7 +103,7 @@ Because the same account may be loaded more than once, implementations of this i
102103
rule <k> #lookupCode ACCT => . ... </k>
103104
<account>
104105
<acctID> ACCT </acctID>
105-
<code> #unloaded => #parseByteStackRaw(#getCode(ACCT)) </code>
106+
<code> #unloaded(_) => #parseByteStackRaw(#getCode(ACCT)) </code>
106107
...
107108
</account>
108109
@@ -127,6 +128,17 @@ Because the same account may be loaded more than once, implementations of this i
127128
rule <k> BLOCKHASH N => 0 ~> #push ... </k> <mode> NORMAL </mode> requires N <Int 0 orBool N >=Int 256
128129
```
129130

131+
```{.k .node}
132+
rule <k> EXTCODEHASH ACCT => HASH ~> #push ... </k>
133+
<account>
134+
<acctID> ACCT </acctID>
135+
<code> #unloaded(HASH) </code>
136+
<nonce> NONCE </nonce>
137+
<balance> BAL </balance>
138+
...
139+
</account>
140+
```
141+
130142
### Transaction Execution
131143

132144
- `runVM` takes all the input state of a transaction and the current block header and executes the transaction according to the specified state, relying on the above loading operations for access to accounts and block hashes.

evm.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,19 +1134,17 @@ For now, I assume that they instantiate an empty account and use the empty data.
11341134
// ----------------------------------
11351135
```
11361136

1137-
```{.k .standalone}
1137+
```k
11381138
rule <k> EXTCODEHASH ACCT => keccak(CODE) ~> #push ... </k>
11391139
<account>
11401140
<acctID> ACCT </acctID>
1141-
<code> CODE </code>
1141+
<code> CODE:WordStack </code>
11421142
<nonce> NONCE </nonce>
11431143
<balance> BAL </balance>
11441144
...
11451145
</account>
11461146
requires notBool #accountEmpty(CODE, NONCE, BAL)
1147-
```
11481147
1149-
```k
11501148
rule <k> EXTCODEHASH ACCT => 0 ~> #push ... </k>
11511149
<account>
11521150
<acctID> ACCT </acctID>

0 commit comments

Comments
 (0)