Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions kevm-pyk/src/kevm_pyk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,8 @@ def evm_chain_args(self) -> ArgumentParser:
'SHANGHAI',
'CANCUN',
'PRAGUE',
'OSAKA',
'AMSTERDAM',
)
modes = ('NORMAL', 'VMTESTS')

Expand Down
10 changes: 10 additions & 0 deletions kevm-pyk/src/kevm_pyk/gst_to_kore.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
'Frontier': 'FRONTIER',
'Homestead': 'HOMESTEAD',
'EIP150': 'TANGERINE_WHISTLE',
'TangerineWhistle': 'TANGERINE_WHISTLE',
'EIP158': 'SPURIOUS_DRAGON',
'SpuriousDragon': 'SPURIOUS_DRAGON',
'Byzantium': 'BYZANTIUM',
'Constantinople': 'CONSTANTINOPLE',
'ConstantinopleFix': 'PETERSBURG',
Expand All @@ -51,6 +53,12 @@
'CancunToPragueAtTime15k': 'PRAGUE',
'Osaka': 'OSAKA',
'PragueToOsakaAtTime15k': 'OSAKA',
'Amsterdam': 'AMSTERDAM',
'BPO2ToAmsterdamAtTime15k': 'AMSTERDAM',
'OsakaToBPO1AtTime15k': 'OSAKA',
'BPO1ToBPO2AtTime15k': 'OSAKA',
'BPO2ToBPO3AtTime15k': 'AMSTERDAM',
'BPO3ToBPO4AtTime15k': 'AMSTERDAM',
}

_GST_DISCARD_KEYS: Final = frozenset(
Expand All @@ -65,6 +73,8 @@
'hasBigInt',
'config',
'network',
'receipts',
'blockAccessList',
]
)
_GST_LOAD_KEYS: Final = frozenset(
Expand Down
16 changes: 11 additions & 5 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ Here we check the other post-conditions associated with an EVM test.
SetItem("receiptTrie") SetItem("stateRoot") SetItem("timestamp")
SetItem("transactionsTrie") SetItem("uncleHash") SetItem("baseFeePerGas") SetItem("withdrawalsRoot")
SetItem("blobGasUsed") SetItem("excessBlobGas") SetItem("parentBeaconBlockRoot") SetItem("requestsHash")
SetItem("blockAccessListHash") SetItem("slotNumber")
)

rule <k> check "blockHeader" : { "bloom" : VALUE } => .K ... </k> <logsBloom> VALUE </logsBloom>
Expand All @@ -647,6 +648,8 @@ Here we check the other post-conditions associated with an EVM test.
rule <k> check "blockHeader" : { "excessBlobGas" : VALUE } => .K ... </k> <excessBlobGas> VALUE </excessBlobGas>
rule <k> check "blockHeader" : { "parentBeaconBlockRoot": VALUE } => .K ... </k> <beaconRoot> VALUE </beaconRoot>
rule <k> check "blockHeader" : { "requestsHash" : VALUE } => .K ... </k> <requestsRoot> VALUE </requestsRoot>
rule <k> check "blockHeader" : { "blockAccessListHash" : VALUE } => .K ... </k> <balHash> VALUE </balHash>
rule <k> check "blockHeader" : { "slotNumber" : VALUE } => .K ... </k> <slotNumber> VALUE </slotNumber>


rule <k> check "blockHeader" : { "hash": HASH:Bytes } => .K ...</k>
Expand All @@ -671,11 +674,14 @@ Here we check the other post-conditions associated with an EVM test.
<excessBlobGas> EB </excessBlobGas>
<beaconRoot> BR </beaconRoot>
<requestsRoot> RR </requestsRoot>
requires #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WR) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WR, UB, EB, BR) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WR, UB, EB, BR, RR) ==Int #asWord(HASH)
<balHash> BAL </balHash>
<slotNumber> SN </slotNumber>
requires #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WR) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WR, UB, EB, BR) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WR, UB, EB, BR, RR) ==Int #asWord(HASH)
orBool #blockHeaderHash(HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WR, UB, EB, BR, RR, BAL, SN) ==Int #asWord(HASH)

rule <k> check { "genesisBlockHeader" : BLOCKHEADER } => check "genesisBlockHeader" : BLOCKHEADER ... </k>
// ---------------------------------------------------------------------------------------------------------
Expand Down
80 changes: 78 additions & 2 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ In the comments next to each cell, we've marked which component of the YellowPap
<excessBlobGas> 0 </excessBlobGas>
<beaconRoot> 0 </beaconRoot>
<requestsRoot> 0 </requestsRoot>
<balHash> 0 </balHash>
<slotNumber> 0 </slotNumber>

<ommerBlockHeaders> [ .JSONs ] </ommerBlockHeaders>
</block>
Expand Down Expand Up @@ -408,6 +410,9 @@ The `#next [_]` operator initiates execution by:
rule #stackNeeded(_QOP:QuadStackOp) => 4
rule #stackNeeded(DUP(N)) => N
rule #stackNeeded(SWAP(N)) => N +Int 1
rule #stackNeeded(DUPN) => 0
rule #stackNeeded(SWAPN) => 0
rule #stackNeeded(EXCHANGE) => 0
rule #stackNeeded(LOG(N)) => N +Int 2
rule #stackNeeded(_CSOP:CallSixOp) => 6
rule #stackNeeded(COP:CallOp) => 7 requires notBool isCallSixOp(COP)
Expand All @@ -433,6 +438,9 @@ The `#next [_]` operator initiates execution by:
rule #stackAdded(LOG(_)) => 0
rule #stackAdded(SWAP(N)) => N +Int 1
rule #stackAdded(DUP(N)) => N +Int 1
rule #stackAdded(DUPN) => 1
rule #stackAdded(SWAPN) => 0
rule #stackAdded(EXCHANGE) => 0
rule #stackAdded(_IOP:InvalidOp) => 0
rule #stackAdded(_OP) => 1 [owise]

Expand Down Expand Up @@ -558,8 +566,11 @@ The arguments to `PUSH` must be skipped over (as they are inline), and the opcod

syntax Int ::= #widthOp ( OpCode ) [symbol(#widthOp), function, total]
// ----------------------------------------------------------------------
rule #widthOp(PUSH(N)) => 1 +Int N
rule #widthOp(_) => 1 [owise]
rule #widthOp(PUSH(N)) => 1 +Int N
rule #widthOp(DUPN) => 2
rule #widthOp(SWAPN) => 2
rule #widthOp(EXCHANGE) => 2
rule #widthOp(_) => 1 [owise]
```

After executing a transaction, it's necessary to have the effect of the substate log recorded.
Expand Down Expand Up @@ -1150,6 +1161,64 @@ Some operators don't calculate anything, they just push the stack around a bit.
rule <k> DUP(N) WS:WordStack => #setStack ((WS [ N -Int 1 ]) : WS) ... </k>
rule <k> SWAP(N) (W0 : WS) => #setStack ((WS [ N -Int 1 ]) : (WS [ N -Int 1 := W0 ])) ... </k>

syntax StackOp ::= "DUPN" | "SWAPN" | "EXCHANGE"
// ------------------------------------------------
rule <k> DUPN WS:WordStack => #setStack ((WS [ #decodeSingle(#immByte(PGM, PCOUNT)) -Int 1 ]) : WS) ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires #validSingle(#immByte(PGM, PCOUNT)) andBool #decodeSingle(#immByte(PGM, PCOUNT)) <=Int #sizeWordStack(WS)
rule <k> DUPN WS:WordStack => #end EVMC_STACK_UNDERFLOW ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires #validSingle(#immByte(PGM, PCOUNT)) andBool #decodeSingle(#immByte(PGM, PCOUNT)) >Int #sizeWordStack(WS)
rule <k> DUPN _:WordStack => #end EVMC_INVALID_INSTRUCTION ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires notBool #validSingle(#immByte(PGM, PCOUNT))

rule <k> SWAPN (W0 : WS) => #setStack ((WS [ #decodeSingle(#immByte(PGM, PCOUNT)) -Int 1 ]) : (WS [ #decodeSingle(#immByte(PGM, PCOUNT)) -Int 1 := W0 ])) ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires #validSingle(#immByte(PGM, PCOUNT)) andBool #decodeSingle(#immByte(PGM, PCOUNT)) +Int 1 <=Int #sizeWordStack(W0 : WS)
rule <k> SWAPN WS:WordStack => #end EVMC_STACK_UNDERFLOW ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires #validSingle(#immByte(PGM, PCOUNT)) andBool #decodeSingle(#immByte(PGM, PCOUNT)) +Int 1 >Int #sizeWordStack(WS)
rule <k> SWAPN _:WordStack => #end EVMC_INVALID_INSTRUCTION ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires notBool #validSingle(#immByte(PGM, PCOUNT))

rule <k> EXCHANGE WS:WordStack => #setStack (WS [ #decodePairA(#immByte(PGM, PCOUNT)) := WS [ #decodePairB(#immByte(PGM, PCOUNT)) ] ] [ #decodePairB(#immByte(PGM, PCOUNT)) := WS [ #decodePairA(#immByte(PGM, PCOUNT)) ] ]) ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires #validPair(#immByte(PGM, PCOUNT)) andBool maxInt(#decodePairA(#immByte(PGM, PCOUNT)), #decodePairB(#immByte(PGM, PCOUNT))) <Int #sizeWordStack(WS)
rule <k> EXCHANGE WS:WordStack => #end EVMC_STACK_UNDERFLOW ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires #validPair(#immByte(PGM, PCOUNT)) andBool maxInt(#decodePairA(#immByte(PGM, PCOUNT)), #decodePairB(#immByte(PGM, PCOUNT))) >=Int #sizeWordStack(WS)
rule <k> EXCHANGE _:WordStack => #end EVMC_INVALID_INSTRUCTION ... </k>
<program> PGM </program> <pc> PCOUNT </pc>
requires notBool #validPair(#immByte(PGM, PCOUNT))

syntax Int ::= "#immByte" "(" Bytes "," Int ")" [function, total]
// -----------------------------------------------------------------
rule #immByte(PGM, PCOUNT) => #asWord(#range(PGM, PCOUNT +Int 1, 1))

syntax Int ::= "#decodeSingle" "(" Int ")" [function, total]
| "#decodePairA" "(" Int ")" [function, total]
| "#decodePairB" "(" Int ")" [function, total]
| "#decodePairA" "(" Int "," Int ")" [function, total]
| "#decodePairB" "(" Int "," Int ")" [function, total]
// -------------------------------------------------------------------
rule #decodeSingle(X) => (X +Int 145) modInt 256

rule #decodePairA(X) => #decodePairA((X xorInt 143) /Int 16, (X xorInt 143) modInt 16)
rule #decodePairA(Q, R) => Q +Int 1 requires Q <Int R
rule #decodePairA(Q, R) => R +Int 1 requires Q >=Int R

rule #decodePairB(X) => #decodePairB((X xorInt 143) /Int 16, (X xorInt 143) modInt 16)
rule #decodePairB(Q, R) => R +Int 1 requires Q <Int R
rule #decodePairB(Q, R) => 29 -Int Q requires Q >=Int R

syntax Bool ::= "#validSingle" "(" Int ")" [function, total]
| "#validPair" "(" Int ")" [function, total]
// ------------------------------------------------------------
rule #validSingle(X) => X <=Int 90 orBool X >=Int 128
rule #validPair(X) => X <=Int 81 orBool X >=Int 128

syntax PushOp ::= "PUSHZERO"
| PUSH ( Int ) [symbol(PUSH)]
// ---------------------------------------------
Expand Down Expand Up @@ -2190,6 +2259,7 @@ Precompiled Contracts
rule #precompiledAccountsUB(CANCUN) => 10
rule #precompiledAccountsUB(PRAGUE) => 17
rule #precompiledAccountsUB(OSAKA) => #precompiledAccountsUB(PRAGUE)
rule #precompiledAccountsUB(AMSTERDAM) => #precompiledAccountsUB(OSAKA)


syntax Set ::= #precompiledAccountsSet ( Schedule ) [symbol(#precompiledAccountsSet), function, total]
Expand Down Expand Up @@ -2990,6 +3060,9 @@ The intrinsic gas calculation mirrors the style of the YellowPaper (appendix H).
rule <k> #gasExec(SCHED, PUSH(_)) => Gverylow < SCHED > ... </k>
rule <k> #gasExec(SCHED, DUP(_) _) => Gverylow < SCHED > ... </k>
rule <k> #gasExec(SCHED, SWAP(_) _) => Gverylow < SCHED > ... </k>
rule <k> #gasExec(SCHED, DUPN _) => Gverylow < SCHED > ... </k>
rule <k> #gasExec(SCHED, SWAPN _) => Gverylow < SCHED > ... </k>
rule <k> #gasExec(SCHED, EXCHANGE _) => Gverylow < SCHED > ... </k>
rule <k> #gasExec(SCHED, BLOBHASH _) => Gverylow < SCHED > ... </k>

// Wlow
Expand Down Expand Up @@ -3333,6 +3406,9 @@ After interpreting the strings representing programs as a `WordStack`, it should
rule #dasmOpCode( 162, _ ) => LOG(2)
rule #dasmOpCode( 163, _ ) => LOG(3)
rule #dasmOpCode( 164, _ ) => LOG(4)
rule #dasmOpCode( 230, SCHED ) => DUPN requires Ghaseip8024 << SCHED >>
rule #dasmOpCode( 231, SCHED ) => SWAPN requires Ghaseip8024 << SCHED >>
rule #dasmOpCode( 232, SCHED ) => EXCHANGE requires Ghaseip8024 << SCHED >>
rule #dasmOpCode( 240, _ ) => CREATE
rule #dasmOpCode( 241, _ ) => CALL
rule #dasmOpCode( 242, _ ) => CALLCODE
Expand Down
26 changes: 23 additions & 3 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module SCHEDULE
| "Ghaswarmcoinbase" | "Ghaswithdrawals" | "Ghastransient" | "Ghasmcopy"
| "Ghasbeaconroot" | "Ghaseip6780" | "Ghasblobbasefee" | "Ghasblobhash"
| "Ghasbls12msmdiscount" | "Ghashistory" | "Ghasrequests" | "Ghasauthority"
| "Ghasfloorcost" | "Ghasclz"
// -------------------------------------------------------------
| "Ghasfloorcost" | "Ghasclz" | "Ghaseip8024"
// ---------------------------------------------------------------------------------------
```

### Schedule Constants
Expand Down Expand Up @@ -183,6 +183,7 @@ A `ScheduleConst` is a constant determined by the fee schedule.
rule [GhasauthorityDefault]: Ghasauthority << DEFAULT >> => false
rule [GhasfloorcostDefault]: Ghasfloorcost << DEFAULT >> => false
rule [GhasclzDefault]: Ghasclz << DEFAULT >> => false
rule [Ghaseip8024Default]: Ghaseip8024 << DEFAULT >> => false
```

### Frontier Schedule
Expand Down Expand Up @@ -509,7 +510,26 @@ A `ScheduleConst` is a constant determined by the fee schedule.
rule [GhasclzOsaka]: Ghasclz << OSAKA >> => true
rule [SCHEDFLAGOsaka]: SCHEDFLAG << OSAKA >> => SCHEDFLAG << PRAGUE >>
requires notBool ( SCHEDFLAG ==K Ghasclz )


```

### Amsterdam Schedule

```k
syntax Schedule ::= "AMSTERDAM" [symbol(AMSTERDAM_EVM), smtlib(schedule_AMSTERDAM)]
// -----------------------------------------------------------------------------------
rule [GmaxblobgasAmsterdam]: Gmaxblobgas < AMSTERDAM > => 2752512
rule [GtargetblobgasAmsterdam]: Gtargetblobgas < AMSTERDAM > => 1835008
rule [BlobbasefeeupdatefractionAmsterdam]: Blobbasefeeupdatefraction < AMSTERDAM > => 11684671
rule [SCHEDCONSTAmsterdam]: SCHEDCONST < AMSTERDAM > => SCHEDCONST < OSAKA >
requires notBool ( SCHEDCONST ==K Gmaxblobgas
orBool SCHEDCONST ==K Gtargetblobgas
orBool SCHEDCONST ==K Blobbasefeeupdatefraction
)

rule [Ghaseip8024Amsterdam]: Ghaseip8024 << AMSTERDAM >> => true
rule [SCHEDFLAGAmsterdam]: SCHEDFLAG << AMSTERDAM >> => SCHEDFLAG << OSAKA >>
requires notBool ( SCHEDFLAG ==K Ghaseip8024 )
```

```k
Expand Down
17 changes: 17 additions & 0 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ Address/Hash Helpers
| #blockHeaderHash(Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes ) [function, symbol(blockHashHeaderBlobBeacon) ]
| #blockHeaderHash(Int , Int , Int , Int , Int , Int , Bytes, Int , Int , Int , Int , Int , Bytes, Int , Int , Int , Int , Int , Int , Int , Int ) [function, symbol(blockHeaderHashRequestsRoot) ]
| #blockHeaderHash(Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes) [function, symbol(blockHashHeaderRequestsRoot) ]
| #blockHeaderHash(Int , Int , Int , Int , Int , Int , Bytes, Int , Int , Int , Int , Int , Bytes, Int , Int , Int , Int , Int , Int , Int , Int , Int , Int ) [function, symbol(blockHeaderHashBALSlot)]
| #blockHeaderHash(Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes, Bytes) [function, symbol(blockHashHeaderBALSlot)]
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

rule #blockHeaderHash(HP:Bytes, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN)
Expand Down Expand Up @@ -199,6 +201,21 @@ Address/Hash Helpers
)
)
)

rule #blockHeaderHash(HP:Bytes, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WF, UB, EB, BR, RR, HA, SN)
=> #parseHexWord( Keccak256( #rlpEncode( [ HP, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WF, UB, EB, BR, RR, HA, SN] ) ) )

rule #blockHeaderHash(HP:Int, HO, HC, HR, HT, HE, HB, HD, HI, HL, HG, HS, HX, HM, HN, HF, WF, UB, EB, BR, RR, HA, SN)
=> #parseHexWord( Keccak256( #rlpEncode( [ #wordBytes(HP), #wordBytes(HO), #addrBytes(HC)
, #wordBytes(HR), #wordBytes(HT), #wordBytes(HE)
, HB, HD, HI, HL, HG, HS, HX
, #wordBytes(HM), #padToWidth(8, #asByteStack(HN))
, HF , #wordBytes(WF) , UB , EB , #wordBytes(BR)
, #wordBytes(RR) , #wordBytes(HA) , SN
]
)
)
)
```

- `#hashTxData` returns the Keccak-256 message hash `HT` to be signed.
Expand Down
Loading