@@ -40,7 +40,7 @@ module EVM-DATA
40
40
imports JSON
41
41
```
42
42
43
- ``` {.k .concrete}
43
+ ``` {.k .concrete .bytes }
44
44
imports BYTES
45
45
```
46
46
@@ -517,10 +517,10 @@ The local memory of execution is a byte-array (instead of a word-array).
517
517
- ` #sizeByteArray ` calculates the size of a ` ByteArray ` .
518
518
- ` #padToWidth(N, WS) ` and ` #padRightToWidth ` make sure that a ` WordStack ` is the correct size.
519
519
520
- ``` {.k .concrete }
520
+ ``` {.k .bytes }
521
521
syntax ByteArray = Bytes
522
- syntax ByteArray ::= ".ByteArray" [function]
523
- // --------------------------------------------
522
+ syntax ByteArray ::= ".ByteArray" [function, functional ]
523
+ // --------------------------------------------------------
524
524
rule .ByteArray => .Bytes
525
525
526
526
syntax Int ::= #asWord ( ByteArray ) [function, smtlib(asWord)]
@@ -562,7 +562,7 @@ The local memory of execution is a byte-array (instead of a word-array).
562
562
rule #padToWidth(N, WS) => padLeftBytes(WS, N, 0)
563
563
```
564
564
565
- ``` {.k .symbolic }
565
+ ``` {.k .nobytes }
566
566
syntax ByteArray = WordStack
567
567
syntax ByteArray ::= ".ByteArray" [function]
568
568
// --------------------------------------------
@@ -721,7 +721,7 @@ We are using the polymorphic `Map` sort for these word maps.
721
721
- ` WM [ N := WS ] ` assigns a contiguous chunk of $WM$ to $WS$ starting at position $W$.
722
722
- ` #range(M, START, WIDTH) ` reads off $WIDTH$ elements from $WM$ beginning at position $START$ (padding with zeros as needed).
723
723
724
- ``` {.k .concrete }
724
+ ``` {.k .bytes }
725
725
syntax Map ::= Map "[" Int ":=" ByteArray "]" [function, klabel(mapWriteBytes)]
726
726
// -------------------------------------------------------------------------------
727
727
rule WM[ N := WS ] => WM [ N := WS, 0, #sizeByteArray(WS) ]
@@ -739,7 +739,7 @@ We are using the polymorphic `Map` sort for these word maps.
739
739
rule #range(WM, I, J, WIDTH, WS) => #range(WM, I +Int 1, J +Int 1, WIDTH, WS [ J <- {WM[I] orDefault 0}:>Int ]) [owise]
740
740
```
741
741
742
- ``` {.k .symbolic }
742
+ ``` {.k .nobytes }
743
743
syntax Map ::= Map "[" Int ":=" ByteArray "]" [function, functional]
744
744
// --------------------------------------------------------------------
745
745
rule [mapWriteBytes.base]: WM[ N := .WordStack ] => WM
@@ -788,6 +788,7 @@ These parsers can interperet hex-encoded strings as `Int`s, `ByteArray`s, and `M
788
788
789
789
- ` #parseHexWord ` interprets a string as a single hex-encoded ` Word ` .
790
790
- ` #parseHexBytes ` interprets a string as a hex-encoded stack of bytes.
791
+ - ` #alignHexString ` makes sure that the length of a (hex)string is even.
791
792
- ` #parseByteStack ` interprets a string as a hex-encoded stack of bytes, but makes sure to remove the leading "0x".
792
793
- ` #parseByteStackRaw ` casts a string as a stack of bytes, ignoring any encoding.
793
794
- ` #parseWordStack ` interprets a JSON list as a stack of ` Word ` .
@@ -805,36 +806,41 @@ These parsers can interperet hex-encoded strings as `Int`s, `ByteArray`s, and `M
805
806
rule #parseWord("") => 0
806
807
rule #parseWord(S) => #parseHexWord(S) requires lengthString(S) >=Int 2 andBool substrString(S, 0, 2) ==String "0x"
807
808
rule #parseWord(S) => String2Int(S) [owise]
809
+
810
+ syntax String ::= #alignHexString ( String ) [function, functional]
811
+ // -------------------------------------------------------------------
812
+ rule #alignHexString(S) => S requires lengthString(S) modInt 2 ==Int 0
813
+ rule #alignHexString(S) => "0" +String S requires notBool lengthString(S) modInt 2 ==Int 0
808
814
```
809
815
810
- ``` {.k .concrete }
816
+ ``` {.k .bytes }
811
817
syntax ByteArray ::= #parseHexBytes ( String ) [function]
812
- | #parseByteStack ( String ) [function]
818
+ | #parseHexBytesAux ( String ) [function]
819
+ | #parseByteStack ( String ) [function, memo]
813
820
| #parseByteStackRaw ( String ) [function]
814
- // -------------------------------------------------------------
821
+ // -------------------------------------------------------------------
815
822
rule #parseByteStack(S) => #parseHexBytes(replaceAll(S, "0x", ""))
816
- rule #parseHexBytes("") => .ByteArray
817
- rule #parseHexBytes(S) => #parseHexBytes("0" +String S)
818
- requires notBool lengthString(S) modInt 2 ==Int 0
819
- rule #parseHexBytes(S) => Int2Bytes(1, #parseHexWord(substrString(S, 0, 2)), BE) +Bytes #parseHexBytes(substrString(S, 2, lengthString(S)))
820
- requires lengthString(S) modInt 2 ==Int 0
821
- andBool lengthString(S) >Int 0
823
+
824
+ rule #parseHexBytes(S) => #parseHexBytesAux(#alignHexString(S))
825
+ rule #parseHexBytesAux("") => .ByteArray
826
+ rule #parseHexBytesAux(S) => Int2Bytes(1, String2Base(substrString(S, 0, 2), 16), BE) +Bytes #parseHexBytesAux(substrString(S, 2, lengthString(S)))
827
+ requires lengthString(S) >=Int 2
822
828
823
829
rule #parseByteStackRaw(S) => String2Bytes(S)
824
830
```
825
831
826
- ``` {.k .symbolic }
832
+ ``` {.k .nobytes }
827
833
syntax ByteArray ::= #parseHexBytes ( String ) [function]
834
+ | #parseHexBytesAux ( String ) [function]
828
835
| #parseByteStack ( String ) [function]
829
836
| #parseByteStackRaw ( String ) [function]
830
837
// -------------------------------------------------------------
831
838
rule #parseByteStack(S) => #parseHexBytes(replaceAll(S, "0x", ""))
832
- rule #parseHexBytes("") => .WordStack
833
- rule #parseHexBytes(S) => #parseHexBytes("0" +String S)
834
- requires notBool lengthString(S) modInt 2 ==Int 0
835
- rule #parseHexBytes(S) => #parseHexWord(substrString(S, 0, 2)) : #parseHexBytes(substrString(S, 2, lengthString(S)))
836
- requires lengthString(S) modInt 2 ==Int 0
837
- andBool lengthString(S) >Int 0
839
+
840
+ rule #parseHexBytes(S) => #parseHexBytesAux(#alignHexString(S))
841
+ rule #parseHexBytesAux("") => .WordStack
842
+ rule #parseHexBytesAux(S) => #parseHexWord(substrString(S, 0, 2)) : #parseHexBytesAux(substrString(S, 2, lengthString(S)))
843
+ requires lengthString(S) >=Int 2
838
844
839
845
rule #parseByteStackRaw(S) => ordChar(substrString(S, 0, 1)) : #parseByteStackRaw(substrString(S, 1, lengthString(S))) requires lengthString(S) >=Int 1
840
846
rule #parseByteStackRaw("") => .WordStack
@@ -860,13 +866,13 @@ We need to interperet a `ByteArray` as a `String` again so that we can call `Kec
860
866
- ` #unparseByteStack ` turns a stack of bytes (as a ` ByteArray ` ) into a ` String ` .
861
867
- ` #padByte ` ensures that the ` String ` interperetation of a ` Int ` is wide enough.
862
868
863
- ``` {.k .concrete }
869
+ ``` {.k .bytes }
864
870
syntax String ::= #unparseByteStack ( ByteArray ) [function, klabel(unparseByteStack), symbol]
865
871
// ----------------------------------------------------------------------------------------------
866
872
rule #unparseByteStack(WS) => Bytes2String(WS)
867
873
```
868
874
869
- ``` {.k .symbolic }
875
+ ``` {.k .nobytes }
870
876
syntax String ::= #unparseByteStack ( ByteArray ) [function, klabel(unparseByteStack), symbol]
871
877
| #unparseByteStack ( ByteArray , StringBuffer ) [function, klabel(#unparseByteStackAux)]
872
878
// ---------------------------------------------------------------------------------------------------------
0 commit comments