Michelson: add SHA256 and SHA512
This commit is contained in:
parent
b17a44d7eb
commit
710998caf4
@ -180,6 +180,8 @@ module Script : sig
|
|||||||
| I_PACK
|
| I_PACK
|
||||||
| I_UNPACK
|
| I_UNPACK
|
||||||
| I_BLAKE2B
|
| I_BLAKE2B
|
||||||
|
| I_SHA256
|
||||||
|
| I_SHA512
|
||||||
| I_ABS
|
| I_ABS
|
||||||
| I_ADD
|
| I_ADD
|
||||||
| I_AMOUNT
|
| I_AMOUNT
|
||||||
|
@ -185,7 +185,7 @@ module Cost_of = struct
|
|||||||
let check_signature = step_cost 3
|
let check_signature = step_cost 3
|
||||||
let hash_key = step_cost 3
|
let hash_key = step_cost 3
|
||||||
(* TODO: This needs to be a function of the data being hashed *)
|
(* TODO: This needs to be a function of the data being hashed *)
|
||||||
let hash data = step_cost (MBytes.length data) +@ alloc_bytes_cost 32
|
let hash data len = step_cost (MBytes.length data) +@ alloc_bytes_cost len
|
||||||
let steps_to_quota = step_cost 1
|
let steps_to_quota = step_cost 1
|
||||||
let source = step_cost 3
|
let source = step_cost 3
|
||||||
let self = step_cost 3
|
let self = step_cost 3
|
||||||
|
@ -78,7 +78,7 @@ module Cost_of : sig
|
|||||||
val now : Gas.cost
|
val now : Gas.cost
|
||||||
val check_signature : Gas.cost
|
val check_signature : Gas.cost
|
||||||
val hash_key : Gas.cost
|
val hash_key : Gas.cost
|
||||||
val hash : MBytes.t -> Gas.cost
|
val hash : MBytes.t -> int -> Gas.cost
|
||||||
val steps_to_quota : Gas.cost
|
val steps_to_quota : Gas.cost
|
||||||
val source : Gas.cost
|
val source : Gas.cost
|
||||||
val self : Gas.cost
|
val self : Gas.cost
|
||||||
|
@ -29,6 +29,8 @@ type prim =
|
|||||||
| I_PACK
|
| I_PACK
|
||||||
| I_UNPACK
|
| I_UNPACK
|
||||||
| I_BLAKE2B
|
| I_BLAKE2B
|
||||||
|
| I_SHA256
|
||||||
|
| I_SHA512
|
||||||
| I_ABS
|
| I_ABS
|
||||||
| I_ADD
|
| I_ADD
|
||||||
| I_AMOUNT
|
| I_AMOUNT
|
||||||
@ -159,6 +161,8 @@ let string_of_prim = function
|
|||||||
| I_PACK -> "PACK"
|
| I_PACK -> "PACK"
|
||||||
| I_UNPACK -> "UNPACK"
|
| I_UNPACK -> "UNPACK"
|
||||||
| I_BLAKE2B -> "BLAKE2B"
|
| I_BLAKE2B -> "BLAKE2B"
|
||||||
|
| I_SHA256 -> "SHA256"
|
||||||
|
| I_SHA512 -> "SHA512"
|
||||||
| I_ABS -> "ABS"
|
| I_ABS -> "ABS"
|
||||||
| I_ADD -> "ADD"
|
| I_ADD -> "ADD"
|
||||||
| I_AMOUNT -> "AMOUNT"
|
| I_AMOUNT -> "AMOUNT"
|
||||||
@ -270,6 +274,8 @@ let prim_of_string = function
|
|||||||
| "PACK" -> ok I_PACK
|
| "PACK" -> ok I_PACK
|
||||||
| "UNPACK" -> ok I_UNPACK
|
| "UNPACK" -> ok I_UNPACK
|
||||||
| "BLAKE2B" -> ok I_BLAKE2B
|
| "BLAKE2B" -> ok I_BLAKE2B
|
||||||
|
| "SHA256" -> ok I_SHA256
|
||||||
|
| "SHA512" -> ok I_SHA512
|
||||||
| "ABS" -> ok I_ABS
|
| "ABS" -> ok I_ABS
|
||||||
| "ADD" -> ok I_ADD
|
| "ADD" -> ok I_ADD
|
||||||
| "AMOUNT" -> ok I_AMOUNT
|
| "AMOUNT" -> ok I_AMOUNT
|
||||||
@ -426,6 +432,8 @@ let prim_encoding =
|
|||||||
("PACK", I_PACK) ;
|
("PACK", I_PACK) ;
|
||||||
("UNPACK", I_UNPACK) ;
|
("UNPACK", I_UNPACK) ;
|
||||||
("BLAKE2B", I_BLAKE2B) ;
|
("BLAKE2B", I_BLAKE2B) ;
|
||||||
|
("SHA256", I_SHA256) ;
|
||||||
|
("SHA512", I_SHA512) ;
|
||||||
("ABS", I_ABS) ;
|
("ABS", I_ABS) ;
|
||||||
("ADD", I_ADD) ;
|
("ADD", I_ADD) ;
|
||||||
("AMOUNT", I_AMOUNT) ;
|
("AMOUNT", I_AMOUNT) ;
|
||||||
|
@ -27,6 +27,8 @@ type prim =
|
|||||||
| I_PACK
|
| I_PACK
|
||||||
| I_UNPACK
|
| I_UNPACK
|
||||||
| I_BLAKE2B
|
| I_BLAKE2B
|
||||||
|
| I_SHA256
|
||||||
|
| I_SHA512
|
||||||
| I_ABS
|
| I_ABS
|
||||||
| I_ADD
|
| I_ADD
|
||||||
| I_AMOUNT
|
| I_AMOUNT
|
||||||
|
@ -697,9 +697,17 @@ let rec interp
|
|||||||
Lwt.return (Gas.consume ctxt Interp_costs.hash_key) >>=? fun ctxt ->
|
Lwt.return (Gas.consume ctxt Interp_costs.hash_key) >>=? fun ctxt ->
|
||||||
logged_return (Item (Signature.Public_key.hash key, rest), ctxt)
|
logged_return (Item (Signature.Public_key.hash key, rest), ctxt)
|
||||||
| Blake2b, Item (bytes, rest) ->
|
| Blake2b, Item (bytes, rest) ->
|
||||||
Lwt.return (Gas.consume ctxt (Interp_costs.hash bytes)) >>=? fun ctxt ->
|
Lwt.return (Gas.consume ctxt (Interp_costs.hash bytes 32)) >>=? fun ctxt ->
|
||||||
let hash = Raw_hashes.blake2b bytes in
|
let hash = Raw_hashes.blake2b bytes in
|
||||||
logged_return (Item (hash, rest), ctxt)
|
logged_return (Item (hash, rest), ctxt)
|
||||||
|
| Sha256, Item (bytes, rest) ->
|
||||||
|
Lwt.return (Gas.consume ctxt (Interp_costs.hash bytes 32)) >>=? fun ctxt ->
|
||||||
|
let hash = Raw_hashes.sha256 bytes in
|
||||||
|
logged_return (Item (hash, rest), ctxt)
|
||||||
|
| Sha512, Item (bytes, rest) ->
|
||||||
|
Lwt.return (Gas.consume ctxt (Interp_costs.hash bytes 64)) >>=? fun ctxt ->
|
||||||
|
let hash = Raw_hashes.sha512 bytes in
|
||||||
|
logged_return (Item (hash, rest), ctxt)
|
||||||
| Steps_to_quota, rest ->
|
| Steps_to_quota, rest ->
|
||||||
Lwt.return (Gas.consume ctxt Interp_costs.steps_to_quota) >>=? fun ctxt ->
|
Lwt.return (Gas.consume ctxt Interp_costs.steps_to_quota) >>=? fun ctxt ->
|
||||||
let steps = match Gas.level ctxt with
|
let steps = match Gas.level ctxt with
|
||||||
|
@ -203,6 +203,8 @@ let number_of_generated_growing_types : type b a. (b, a) instr -> int = function
|
|||||||
| Check_signature -> 0
|
| Check_signature -> 0
|
||||||
| Hash_key -> 0
|
| Hash_key -> 0
|
||||||
| Blake2b -> 0
|
| Blake2b -> 0
|
||||||
|
| Sha256 -> 0
|
||||||
|
| Sha512 -> 0
|
||||||
| Steps_to_quota -> 0
|
| Steps_to_quota -> 0
|
||||||
| Source -> 0
|
| Source -> 0
|
||||||
| Sender -> 0
|
| Sender -> 0
|
||||||
@ -244,6 +246,8 @@ let namespace = function
|
|||||||
| I_PACK
|
| I_PACK
|
||||||
| I_UNPACK
|
| I_UNPACK
|
||||||
| I_BLAKE2B
|
| I_BLAKE2B
|
||||||
|
| I_SHA256
|
||||||
|
| I_SHA512
|
||||||
| I_ABS
|
| I_ABS
|
||||||
| I_ADD
|
| I_ADD
|
||||||
| I_AMOUNT
|
| I_AMOUNT
|
||||||
@ -2400,6 +2404,16 @@ and parse_instr
|
|||||||
parse_var_annot loc annot >>=? fun annot ->
|
parse_var_annot loc annot >>=? fun annot ->
|
||||||
typed ctxt loc Blake2b
|
typed ctxt loc Blake2b
|
||||||
(Item_t (Bytes_t None, rest, annot))
|
(Item_t (Bytes_t None, rest, annot))
|
||||||
|
| Prim (loc, I_SHA256, [], annot),
|
||||||
|
Item_t (Bytes_t _, rest, _) ->
|
||||||
|
parse_var_annot loc annot >>=? fun annot ->
|
||||||
|
typed ctxt loc Sha256
|
||||||
|
(Item_t (Bytes_t None, rest, annot))
|
||||||
|
| Prim (loc, I_SHA512, [], annot),
|
||||||
|
Item_t (Bytes_t _, rest, _) ->
|
||||||
|
parse_var_annot loc annot >>=? fun annot ->
|
||||||
|
typed ctxt loc Sha512
|
||||||
|
(Item_t (Bytes_t None, rest, annot))
|
||||||
| Prim (loc, I_STEPS_TO_QUOTA, [], annot),
|
| Prim (loc, I_STEPS_TO_QUOTA, [], annot),
|
||||||
stack ->
|
stack ->
|
||||||
parse_var_annot loc annot ~default:default_steps_annot >>=? fun annot ->
|
parse_var_annot loc annot ~default:default_steps_annot >>=? fun annot ->
|
||||||
@ -2440,7 +2454,7 @@ and parse_instr
|
|||||||
| I_CREATE_CONTRACT | I_SET_DELEGATE | I_NOW
|
| I_CREATE_CONTRACT | I_SET_DELEGATE | I_NOW
|
||||||
| I_IMPLICIT_ACCOUNT | I_AMOUNT | I_BALANCE
|
| I_IMPLICIT_ACCOUNT | I_AMOUNT | I_BALANCE
|
||||||
| I_CHECK_SIGNATURE | I_HASH_KEY | I_SOURCE | I_SENDER
|
| I_CHECK_SIGNATURE | I_HASH_KEY | I_SOURCE | I_SENDER
|
||||||
| I_BLAKE2B | I_STEPS_TO_QUOTA | I_ADDRESS
|
| I_BLAKE2B | I_SHA256 | I_SHA512 | I_STEPS_TO_QUOTA | I_ADDRESS
|
||||||
as name), (_ :: _ as l), _), _ ->
|
as name), (_ :: _ as l), _), _ ->
|
||||||
fail (Invalid_arity (loc, name, 0, List.length l))
|
fail (Invalid_arity (loc, name, 0, List.length l))
|
||||||
| Prim (loc, (I_NONE | I_LEFT | I_RIGHT | I_NIL | I_MAP | I_ITER
|
| Prim (loc, (I_NONE | I_LEFT | I_RIGHT | I_NIL | I_MAP | I_ITER
|
||||||
@ -2479,7 +2493,8 @@ and parse_instr
|
|||||||
| Prim (loc, I_TRANSFER_TOKENS, [], _),
|
| Prim (loc, I_TRANSFER_TOKENS, [], _),
|
||||||
stack ->
|
stack ->
|
||||||
fail (Bad_stack (loc, I_TRANSFER_TOKENS, 4, stack))
|
fail (Bad_stack (loc, I_TRANSFER_TOKENS, 4, stack))
|
||||||
| Prim (loc, (I_DROP | I_DUP | I_CAR | I_CDR | I_SOME | I_BLAKE2B | I_DIP
|
| Prim (loc, (I_DROP | I_DUP | I_CAR | I_CDR | I_SOME
|
||||||
|
| I_BLAKE2B | I_SHA256 | I_SHA512 | I_DIP
|
||||||
| I_IF_NONE | I_LEFT | I_RIGHT | I_IF_LEFT | I_IF
|
| I_IF_NONE | I_LEFT | I_RIGHT | I_IF_LEFT | I_IF
|
||||||
| I_LOOP | I_IF_CONS | I_IMPLICIT_ACCOUNT
|
| I_LOOP | I_IF_CONS | I_IMPLICIT_ACCOUNT
|
||||||
| I_NEG | I_ABS | I_INT | I_NOT
|
| I_NEG | I_ABS | I_INT | I_NOT
|
||||||
@ -2508,7 +2523,8 @@ and parse_instr
|
|||||||
I_LT ; I_GT ; I_LE ; I_GE ;
|
I_LT ; I_GT ; I_LE ; I_GE ;
|
||||||
I_TRANSFER_TOKENS ; I_CREATE_ACCOUNT ;
|
I_TRANSFER_TOKENS ; I_CREATE_ACCOUNT ;
|
||||||
I_CREATE_CONTRACT ; I_NOW ; I_AMOUNT ; I_BALANCE ;
|
I_CREATE_CONTRACT ; I_NOW ; I_AMOUNT ; I_BALANCE ;
|
||||||
I_IMPLICIT_ACCOUNT ; I_CHECK_SIGNATURE ; I_BLAKE2B ; I_HASH_KEY ;
|
I_IMPLICIT_ACCOUNT ; I_CHECK_SIGNATURE ;
|
||||||
|
I_BLAKE2B ; I_SHA256 ; I_SHA512 ; I_HASH_KEY ;
|
||||||
I_STEPS_TO_QUOTA ;
|
I_STEPS_TO_QUOTA ;
|
||||||
I_PUSH ; I_NONE ; I_LEFT ; I_RIGHT ; I_NIL ;
|
I_PUSH ; I_NONE ; I_LEFT ; I_RIGHT ; I_NIL ;
|
||||||
I_EMPTY_SET ; I_DIP ; I_LOOP ;
|
I_EMPTY_SET ; I_DIP ; I_LOOP ;
|
||||||
|
@ -345,6 +345,10 @@ and ('bef, 'aft) instr =
|
|||||||
(MBytes.t * 'rest, 'a option * 'rest) instr
|
(MBytes.t * 'rest, 'a option * 'rest) instr
|
||||||
| Blake2b :
|
| Blake2b :
|
||||||
(MBytes.t * 'rest, MBytes.t * 'rest) instr
|
(MBytes.t * 'rest, MBytes.t * 'rest) instr
|
||||||
|
| Sha256 :
|
||||||
|
(MBytes.t * 'rest, MBytes.t * 'rest) instr
|
||||||
|
| Sha512 :
|
||||||
|
(MBytes.t * 'rest, MBytes.t * 'rest) instr
|
||||||
| Steps_to_quota : (* TODO: check that it always returns a nat *)
|
| Steps_to_quota : (* TODO: check that it always returns a nat *)
|
||||||
('rest, n num * 'rest) instr
|
('rest, n num * 'rest) instr
|
||||||
| Source :
|
| Source :
|
||||||
|
Loading…
Reference in New Issue
Block a user