Skip to content

Commit 903e131

Browse files
anvacaruehildenb
andauthored
Updates to the driver.md GST handler (#2682)
* sort failing.llvm * skip intrinsincally invalid blocks * regen failing.llvm * driver.md updates * preserve failing.llvm initial order * Update kevm-pyk/src/kevm_pyk/kproj/evm-semantics/driver.md Co-authored-by: Everett Hildenbrandt <[email protected]> * regen failing.llvm --------- Co-authored-by: Everett Hildenbrandt <[email protected]>
1 parent ee88122 commit 903e131

File tree

3 files changed

+102
-929
lines changed

3 files changed

+102
-929
lines changed

kevm-pyk/src/kevm_pyk/gst_to_kore.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
'sealEngine',
3737
'transactionSequence',
3838
'chainname',
39-
'expectException',
4039
'lastblockhash',
4140
]
4241
)
@@ -79,15 +78,21 @@
7978

8079

8180
def filter_gst_keys(gst_data: dict) -> dict:
82-
"""Filters the discarded keys out of a single GeneralStateTest.
83-
84-
:param gst_data: A single test from a GST file structured as {"test_name": {test_fields}, ... }.
85-
:returns: The gst_data object after filtering out _GST_DISCARD_KEYS.
8681
"""
87-
return {
88-
test_name: {k: v for k, v in test_data.items() if k not in _GST_DISCARD_KEYS}
89-
for test_name, test_data in gst_data.items()
90-
}
82+
Filters the discarded keys out of a single GeneralStateTest,
83+
recursively removing them from nested dicts/lists as well.
84+
"""
85+
86+
def _remove_discard_keys(obj: Any) -> Any:
87+
if type(obj) is dict:
88+
return {k: _remove_discard_keys(v) for k, v in obj.items() if k not in _GST_DISCARD_KEYS}
89+
elif type(obj) is list:
90+
return [_remove_discard_keys(item) for item in obj]
91+
else:
92+
# If it's neither dict nor list, just return as-is
93+
return obj
94+
95+
return _remove_discard_keys(gst_data)
9196

9297

9398
def gst_to_kore(gst_data: Any, schedule: str, mode: str, chainid: int, usegas: bool) -> App:

kevm-pyk/src/kevm_pyk/kproj/evm-semantics/driver.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ To do so, we'll extend sort `JSON` with some EVM specific syntax, and provide a
9797
rule <k> loadTx(ACCTFROM)
9898
=> #accessAccounts ACCTFROM #newAddr(ACCTFROM, NONCE) #precompiledAccountsSet(SCHED)
9999
~> #loadAccessList(TA)
100+
~> #checkCreate ACCTFROM VALUE
100101
~> #create ACCTFROM #newAddr(ACCTFROM, NONCE) VALUE CODE
101102
~> #finishTx ~> #finalizeTx(false) ~> startTx
102103
...
@@ -121,15 +122,18 @@ To do so, we'll extend sort `JSON` with some EVM specific syntax, and provide a
121122
<acctID> ACCTFROM </acctID>
122123
<balance> BAL => BAL -Int (GLIMIT *Int #effectiveGasPrice(TXID)) </balance>
123124
<nonce> NONCE </nonce>
125+
<code> ACCTCODE </code>
124126
...
125127
</account>
126128
<accessedAccounts> _ => #if Ghaswarmcoinbase << SCHED >> #then SetItem(MINER) #else .Set #fi </accessedAccounts>
127129
<touchedAccounts> _ => SetItem(MINER) </touchedAccounts>
128130
requires #hasValidInitCode(lengthBytes(CODE), SCHED)
131+
andBool ACCTCODE ==K .Bytes
129132
130133
rule <k> loadTx(ACCTFROM)
131134
=> #accessAccounts ACCTFROM ACCTTO #precompiledAccountsSet(SCHED)
132135
~> #loadAccessList(TA)
136+
~> #checkCall ACCTFROM VALUE
133137
~> #call ACCTFROM ACCTTO ACCTTO VALUE VALUE DATA false
134138
~> #finishTx ~> #finalizeTx(false) ~> startTx
135139
...
@@ -154,11 +158,23 @@ To do so, we'll extend sort `JSON` with some EVM specific syntax, and provide a
154158
<acctID> ACCTFROM </acctID>
155159
<balance> BAL => BAL -Int (GLIMIT *Int #effectiveGasPrice(TXID)) </balance>
156160
<nonce> NONCE => NONCE +Int 1 </nonce>
161+
<code> ACCTCODE </code>
157162
...
158163
</account>
159164
<accessedAccounts> _ => #if Ghaswarmcoinbase << SCHED >> #then SetItem(MINER) #else .Set #fi </accessedAccounts>
160165
<touchedAccounts> _ => SetItem(MINER) </touchedAccounts>
161166
requires ACCTTO =/=K .Account
167+
andBool ACCTCODE ==K .Bytes
168+
169+
rule <k> loadTx(ACCTFROM) => startTx ... </k>
170+
<statusCode> _ => EVMC_FAILURE </statusCode>
171+
<txPending> ListItem(_TXID:Int) REST => REST </txPending>
172+
<account>
173+
<acctID> ACCTFROM </acctID>
174+
<code> ACCTCODE </code>
175+
...
176+
</account>
177+
requires notBool ACCTCODE ==K .Bytes
162178
163179
syntax EthereumCommand ::= "#finishTx"
164180
// --------------------------------------
@@ -231,7 +247,14 @@ To do so, we'll extend sort `JSON` with some EVM specific syntax, and provide a
231247
rule <statusCode> _:ExceptionalStatusCode </statusCode>
232248
<k> #halt ~> exception => .K ... </k>
233249
234-
rule <k> status SC => .K ... </k> <statusCode> SC </statusCode>
250+
rule <statusCode> _:ExceptionalStatusCode </statusCode>
251+
<k> exception ~> check _ => exception ... </k>
252+
253+
rule <statusCode> _:ExceptionalStatusCode </statusCode>
254+
<k> exception ~> run TEST => run TEST ~> exception ... </k>
255+
256+
rule <statusCode> _:ExceptionalStatusCode </statusCode>
257+
<k> exception ~> clear => clear ... </k>
235258
236259
syntax EthereumCommand ::= "failure" String | "success"
237260
// -------------------------------------------------------
@@ -293,6 +316,15 @@ Note that `TEST` is sorted here so that key `"network"` comes before key `"pre"`
293316
294317
syntax EthereumCommand ::= "process" JSON
295318
// -----------------------------------------
319+
rule <k> process TESTID : { "expectException" : _ , REST } => exception ~> process TESTID : { REST } ... </k>
320+
321+
rule <k> exception ~> process _TESTID : { "rlp_decoded" : { KEY : VAL , REST1 => REST1 }, (REST2 => KEY : VAL , REST2 ) } ... </k>
322+
rule <k> exception ~> process _TESTID : { "rlp_decoded" : { .JSONs } , REST => REST} ... </k>
323+
324+
rule <k> exception ~> process TESTID : { KEY : VAL , REST } => load KEY : VAL ~> exception ~> process TESTID : { REST } ... </k> requires KEY in #loadKeys
325+
rule <k> exception ~> process TESTID : { KEY : VAL , REST } => exception ~> process TESTID : { REST } ~> check TESTID : {KEY : VAL} ... </k> requires KEY in #checkKeys
326+
rule <k> exception ~> process _TESTID : { .JSONs } => #startBlock ~> startTx ~> exception ... </k>
327+
296328
rule <k> process _TESTID : { "rlp_decoded" : { KEY : VAL , REST1 => REST1 }, (REST2 => KEY : VAL , REST2 ) } ... </k>
297329
rule <k> process _TESTID : { "rlp_decoded" : { .JSONs } , REST => REST} ... </k>
298330

0 commit comments

Comments
 (0)