File tree Expand file tree Collapse file tree 12 files changed +75
-10
lines changed Expand file tree Collapse file tree 12 files changed +75
-10
lines changed Original file line number Diff line number Diff line change @@ -240,9 +240,9 @@ and compile_expression env = function
240240 | FunctionCall ("get" , [Identifier _ ; Identifier _ ]) -> (* TODO *)
241241 [
242242 EVM. from_int 0x80 ; (* 128 bits *)
243- EVM. from_int 2 ; EVM. EXP ; EVM. MUL ; (* equivalent to EVM.SHL *)
243+ EVM. two ; EVM. EXP ; EVM. MUL ; (* equivalent to EVM.SHL *)
244244 EVM. from_int 0x80 ; (* 128 bits *)
245- EVM. from_int 2 ; EVM. EXP ; EVM. SWAP 1 ; EVM. DIV ; (* equivalent to EVM.SWAP 1; EVM.SHR *)
245+ EVM. two ; EVM. EXP ; EVM. SWAP 1 ; EVM. DIV ; (* equivalent to EVM.SWAP 1; EVM.SHR *)
246246 ]
247247
248248 | FunctionCall ("hash160" , [value ]) ->
@@ -376,7 +376,7 @@ and compile_tuple_literal = function
376376
377377and compile_packed_word hi lo =
378378 (* [EVM.from_big_int hi; EVM.from_int 0x80; EVM.SHL; EVM.from_big_int lo; EVM.OR] *)
379- [EVM. from_big_int hi; EVM. from_int 0x80 ; EVM. from_int 2 ; EVM. EXP ; EVM. MUL ; EVM. from_big_int lo; EVM. OR ]
379+ [EVM. from_big_int hi; EVM. from_int 0x80 ; EVM. two ; EVM. EXP ; EVM. MUL ; EVM. from_big_int lo; EVM. OR ]
380380
381381and compile_param (_ , type' ) =
382382 compile_type type '
Original file line number Diff line number Diff line change 22
33let unreachable () = failwith " unreachable"
44
5- let unimplemented what = failwith (Printf. sprintf " %s not implemented yet" what)
5+ let unimplemented what =
6+ let message =
7+ if what = " " then " not implemented yet"
8+ else Printf. sprintf " %s not implemented yet" what
9+ in
10+ failwith message
611
7- let unsupported what = failwith (Printf. sprintf " %s not supported" what)
12+ let unsupported what =
13+ let message =
14+ if what = " " then " not supported"
15+ else Printf. sprintf " %s not supported" what
16+ in
17+ failwith message
818
919let rec last = function
1020 | [] -> None
Original file line number Diff line number Diff line change 11(* This is free and unencumbered software released into the public domain. *)
22
3+ #include " utility.ml"
34#include " opcodes.ml"
45#include " abi.ml"
56#include " construct.ml"
Original file line number Diff line number Diff line change 11(* This is free and unencumbered software released into the public domain. *)
22
3+ #include " utility.mli"
34#include " opcodes.ml"
45#include " abi.mli"
56#include " construct.mli"
Original file line number Diff line number Diff line change @@ -10,4 +10,23 @@ module ABI = struct
1010
1111 and encode_function_signature signature =
1212 String. sub (keccak256 signature) 0 4
13+
14+ and encode_int_parameter_as_uint256 z =
15+ encode_int64_parameter_as_uint256 (Int64. of_int z)
16+
17+ and encode_int32_parameter_as_uint256 z =
18+ encode_int64_parameter_as_uint256 (Int64. of_int32 z)
19+
20+ and encode_int64_parameter_as_uint256 z =
21+ let buffer = Buffer. create 32 in
22+ Buffer. add_int64_be buffer 0L ;
23+ Buffer. add_int64_be buffer 0L ;
24+ Buffer. add_int64_be buffer 0L ;
25+ Buffer. add_int64_be buffer z;
26+ Buffer. contents buffer
27+
28+ and encode_bigint_parameter_as_uint256 z =
29+ match Big_int. int64_of_big_int_opt z with
30+ | Some z -> encode_int64_parameter_as_uint256 z
31+ | None -> unimplemented " " (* TODO *)
1332end
Original file line number Diff line number Diff line change 33module ABI : sig
44 val encode_function : string -> string list -> string
55 val encode_function_signature : string -> string
6+ val encode_int_parameter_as_uint256 : int -> string
7+ val encode_int32_parameter_as_uint256 : int32 -> string
8+ val encode_int64_parameter_as_uint256 : int64 -> string
9+ val encode_bigint_parameter_as_uint256 : Big_int .big_int -> string
610end
Original file line number Diff line number Diff line change @@ -6,13 +6,15 @@ let from_string s =
66let rec from_big_int z =
77 match Big_int. int_of_big_int_opt z with
88 | Some z -> from_int z
9- | None -> failwith " not implemented yet " (* TODO * )
9+ | None -> PUSH ( 32 , ABI. encode_bigint_parameter_as_uint256 z )
1010
1111and from_int z =
12- if z < 0 then failwith " not implemented yet " (* TODO *)
12+ if z < 0 then unimplemented " encoding of negative integers " (* FIXME *)
1313 else if z < = 0xFF then PUSH (1 , Char. chr z |> String. make 1 )
14- else failwith " not implemented yet " (* TODO * )
14+ else PUSH ( 32 , ABI. encode_int_parameter_as_uint256 z )
1515
1616let zero = from_int 0
1717
1818let one = from_int 1
19+
20+ let two = from_int 2
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ val zero : opcode
44
55val one : opcode
66
7+ val two : opcode
8+
79val from_big_int : Big_int .big_int -> opcode
810
911val from_int : int -> opcode
Original file line number Diff line number Diff line change 1616 metrics.mli
1717 opcodes.ml
1818 print.ml
19- print.mli)
19+ print.mli
20+ utility.ml
21+ utility.mli)
2022 (libraries cryptokit num))
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ and encode_opcode = function
100100 | MSIZE -> 0x59
101101 | GAS -> 0x5A
102102 | JUMPDEST -> 0x5B
103- | PUSH (0 , _ ) -> failwith " unreachable"
103+ | PUSH (0 , _ ) -> unreachable ()
104104 | PUSH (n , _ ) -> 0x60 + n - 1
105105 | DUP n -> 0x80 + n - 1
106106 | SWAP n -> 0x90 + n - 1
You can’t perform that action at this time.
0 commit comments