Commit c3ceaf1d authored by François Bobot's avatar François Bobot

[EVM] fix gaz consumption

parent e64117c7
......@@ -115,8 +115,8 @@ module A
add_gas 159 0;
let r = make n in
r[0] <- x;
r[n-1] <- x+1;
r[0] + r[n-1] - 1
r[n-1] <- x+(length r);
r[0] + r[n-1]
let g [@ evm:external] () : bool
raises { Error -> true }
......@@ -170,7 +170,7 @@ module A
(* test 10 *)
let () =
let r1 = g10 (0x10) (0x4) in
let o1 : uint32 = (0x8:uint32) in
let o1 : uint32 = (0x18:uint32) in
if not (r1 = o1) then raise Error
in
false
......
......@@ -185,11 +185,13 @@ end
module mach.evm.ArrayUInt32
(** the pointer is after the stored length *)
syntax val ([]) "[\"SWAP1\",[\"PUSH1\",32],\"MUL\",\"ADD\",\"MLOAD\"]"
syntax val ([]<-) "[\"SWAP1\",[\"PUSH1\",32],\"MUL\",\"ADD\",\"MSTORE\"]"
syntax val make "[\"ALLOCATE_DYN\"]"
syntax val length "[[\"PUSH1\",32],\"SWAP1\",\"SUB\",\"MLOAD\"]"
syntax val make "[\"DUP1\",[\"PUSH1\",1],\"ADD\",[\"PUSH1\",32],\"MUL\",\"ALLOCATE_DYN\",\"SWAP1\",\"DUP2\",\"MSTORE\",[\"PUSH1\",32],\"ADD\"]"
end
module mach.evm.ArrayUInt64
......@@ -197,5 +199,6 @@ module mach.evm.ArrayUInt64
syntax val ([]) "[\"SWAP1\",[\"PUSH1\",32],\"MUL\",\"ADD\",\"MLOAD\"]"
syntax val ([]<-) "[\"SWAP1\",[\"PUSH1\",32],\"MUL\",\"ADD\",\"MSTORE\"]"
syntax val make "[\"ALLOCATE_DYN\"]"
syntax val length "[[\"PUSH1\",1],\"SWAP1\",\"SUB\",\"MLOAD\"]"
syntax val make "[\"DUP1\",[\"PUSH1\",1],\"ADD\",\"ALLOCATE_DYN\",\"DUP1\",\"MSTORE\",[\"PUSH1\",1],\"ADD\"]"
end
......@@ -2035,7 +2035,7 @@ module EVMSimple = struct
i (BigInt.to_string (BigInt.sub BigInt.zero gas))
let gaz_checking l =
(* TODO loop handling, let rec naturally handled *)
(* TODO let rec naturally handled *)
let asmmap = Array.of_list l in
let rec count i gas alloc pc (** in fact index *) =
Debug.dprintf debug "%i %i: %s %s@." i pc (BigInt.to_string gas) (get_name asmmap.(pc));
......@@ -2439,12 +2439,14 @@ module Print = struct
| Efun (_varl, _e) ->
invalid_arg "unsupported Efun"
| Ewhile (e1, e2) ->
(** todo addgas handling *)
let start, stop = EVMSimple.new_startstop_addgas () in
let labstart = EVMSimple.new_label ~follow:false "whilestart" in
let labtest = EVMSimple.new_label ~follow:true "whiletest" in
EVMSimple.jump fmt labtest;
EVMSimple.jumpdest fmt labstart;
EVMSimple.add_auto fmt start;
print_expr info fmt e2;
EVMSimple.add_auto fmt stop;
EVMSimple.jumpdest fmt labtest;
print_expr info fmt e1;
EVMSimple.jumpi fmt labstart;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment