Skip to content

Commit e128e47

Browse files
anvacaruehildenb
andauthored
eip-7939: implement the CLZ opcode (#2825)
* bump test suite version * skip passing slow test * define Osaka hardfork * change to fixtures_stable release * sort failing.llvm * eip-7939: implement the CLZ opcode * Update kevm-pyk/src/kevm_pyk/kproj/evm-semantics/evm.md Co-authored-by: Everett Hildenbrandt <everett.hildenbrandt@gmail.com> * add helper clz function --------- Co-authored-by: Everett Hildenbrandt <everett.hildenbrandt@gmail.com>
1 parent 22d61de commit e128e47

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ Primitives provide the basic conversion from K's sorts `Int` and `Bool` to EVM's
5454
rule abs(I) => 0 requires sgn(I) ==Int 0
5555
```
5656

57+
- `clz` returns the number of leading zeros of a word, as specified in [EIP-7939](https://github.com/ethereum/EIPs/blob/31f1d01e474633119f9014765635346c06f5cc7d/EIPS/eip-7939.md).
58+
```k
59+
syntax Int ::= clz ( Int ) [symbol(clz), function, total]
60+
// ---------------------------------------------------------
61+
rule clz(0) => 256
62+
rule clz(I) => 255 -Int log2Int(I) requires 0 <Int I andBool I <Int pow256
63+
rule clz(I) => -1 requires I <Int 0 orBool pow256 <=Int I
64+
```
5765
Word Operations
5866
---------------
5967

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,10 @@ NOTE: We have to call the opcode `OR` by `EVMOR` instead, because K has trouble
12461246
// ----------------------------
12471247
rule <k> SHA3 MEMSTART MEMWIDTH => keccak(#range(LM, MEMSTART, MEMWIDTH)) ~> #push ... </k>
12481248
<localMem> LM </localMem>
1249+
1250+
syntax UnStackOp ::= "CLZ"
1251+
// -------------------------
1252+
rule <k> CLZ X => clz(X) ~> #push ... </k>
12491253
```
12501254

12511255
### Local State
@@ -3000,6 +3004,7 @@ The intrinsic gas calculation mirrors the style of the YellowPaper (appendix H).
30003004
rule <k> #gasExec(SCHED, SMOD _ _) => Glow < SCHED > ... </k>
30013005
rule <k> #gasExec(SCHED, SIGNEXTEND _ _) => Glow < SCHED > ... </k>
30023006
rule <k> #gasExec(SCHED, SELFBALANCE) => Glow < SCHED > ... </k>
3007+
rule <k> #gasExec(SCHED, CLZ _) => Glow < SCHED > ... </k>
30033008
30043009
// Wmid
30053010
rule <k> #gasExec(SCHED, ADDMOD _ _ _) => Gmid < SCHED > ... </k>
@@ -3217,6 +3222,7 @@ After interpreting the strings representing programs as a `WordStack`, it should
32173222
rule #dasmOpCode( 27, SCHED ) => SHL requires Ghasshift << SCHED >>
32183223
rule #dasmOpCode( 28, SCHED ) => SHR requires Ghasshift << SCHED >>
32193224
rule #dasmOpCode( 29, SCHED ) => SAR requires Ghasshift << SCHED >>
3225+
rule #dasmOpCode( 30, SCHED ) => CLZ requires Ghasclz << SCHED >>
32203226
rule #dasmOpCode( 32, _ ) => SHA3
32213227
rule #dasmOpCode( 48, _ ) => ADDRESS
32223228
rule #dasmOpCode( 49, _ ) => BALANCE

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ module SCHEDULE
3131
| "Ghaswarmcoinbase" | "Ghaswithdrawals" | "Ghastransient" | "Ghasmcopy"
3232
| "Ghasbeaconroot" | "Ghaseip6780" | "Ghasblobbasefee" | "Ghasblobhash"
3333
| "Ghasbls12msmdiscount" | "Ghashistory" | "Ghasrequests" | "Ghasauthority"
34-
| "Ghasfloorcost"
35-
// ---------------------------------------
34+
| "Ghasfloorcost" | "Ghasclz"
35+
// -------------------------------------------------------------
3636
```
3737

3838
### Schedule Constants
@@ -182,6 +182,7 @@ A `ScheduleConst` is a constant determined by the fee schedule.
182182
rule [Ghasbls12msmdiscountDefault]: Ghasbls12msmdiscount << DEFAULT >> => false
183183
rule [GhasauthorityDefault]: Ghasauthority << DEFAULT >> => false
184184
rule [GhasfloorcostDefault]: Ghasfloorcost << DEFAULT >> => false
185+
rule [GhasclzDefault]: Ghasclz << DEFAULT >> => false
185186
```
186187

187188
### Frontier Schedule
@@ -504,7 +505,11 @@ A `ScheduleConst` is a constant determined by the fee schedule.
504505
syntax Schedule ::= "OSAKA" [symbol(OSAKA_EVM), smtlib(schedule_OSAKA)]
505506
// -----------------------------------------------------------------------
506507
rule [SCHEDCONSTOsaka]: SCHEDCONST < OSAKA > => SCHEDCONST < PRAGUE >
508+
509+
rule [GhasclzOsaka]: Ghasclz << OSAKA >> => true
507510
rule [SCHEDFLAGOsaka]: SCHEDFLAG << OSAKA >> => SCHEDFLAG << PRAGUE >>
511+
requires notBool ( SCHEDFLAG ==K Ghasclz )
512+
508513
```
509514

510515
```k

0 commit comments

Comments
 (0)