Michelson: BLAKE2B now takes bytes
This commit is contained in:
parent
197b29b040
commit
b17a44d7eb
@ -24,7 +24,7 @@ code { DUP; CAR;
|
||||
{ DUP; DUP; DUP; DUP;
|
||||
# Check signature on data
|
||||
CAR %from;
|
||||
DIIP{ CDAR %withdraw_amount; BLAKE2B @signed_amount };
|
||||
DIIP{ CDAR %withdraw_amount; PACK ; BLAKE2B @signed_amount };
|
||||
DIP{ CDDR %sig }; CHECK_SIGNATURE;
|
||||
IF {} { PUSH string "Bad signature"; FAILWITH };
|
||||
# Get user account information
|
||||
|
@ -2,7 +2,7 @@ parameter key;
|
||||
storage (pair signature string);
|
||||
code { DUP; DUP;
|
||||
DIP{ CDR; DUP; CAR;
|
||||
DIP{CDR; BLAKE2B}; PAIR};
|
||||
DIP{CDR; PACK ; BLAKE2B}; PAIR};
|
||||
CAR; DIP {UNPAIR}; CHECK_SIGNATURE;
|
||||
IF {} {FAIL} ;
|
||||
CDR; NIL operation ; PAIR};
|
||||
|
@ -1,7 +1,7 @@
|
||||
parameter (pair signature (pair string nat));
|
||||
storage (pair (pair key nat) string);
|
||||
code { DUP; CAR; DIP{CDR; DUP};
|
||||
SWAP; DIP{DUP}; CAAR; DIP{DUP; CAR; DIP{CDR; BLAKE2B}};
|
||||
SWAP; DIP{DUP}; CAAR; DIP{DUP; CAR; DIP{CDR; PACK ; BLAKE2B}};
|
||||
CHECK_SIGNATURE;
|
||||
IF { CDR; DUP; DIP{CAR; DIP{CAAR}}; CDR; PUSH nat 1; ADD;
|
||||
DIP{SWAP}; SWAP; PAIR; PAIR; NIL operation; PAIR}
|
||||
|
@ -1,3 +1,3 @@
|
||||
parameter (pair mutez (pair timestamp int)) ;
|
||||
storage bytes ;
|
||||
code { CAR ; BLAKE2B ; NIL operation ; PAIR }
|
||||
code { CAR ; PACK ; BLAKE2B ; NIL operation ; PAIR }
|
@ -1,3 +1,3 @@
|
||||
parameter string;
|
||||
storage bytes;
|
||||
code {CAR; BLAKE2B; NIL operation; PAIR};
|
||||
code {CAR; PACK ; BLAKE2B; NIL operation; PAIR};
|
||||
|
@ -7,7 +7,7 @@ code {DUP; DUP; CAR;
|
||||
# Provide the data
|
||||
CDR; DIP {CDDR}}
|
||||
{DUP; DIP{SWAP}; SWAP; CDAR; # Move key to the top
|
||||
DIP {DUP; CAR; DIP {CDR; BLAKE2B}}; # Arrange the new piece of data
|
||||
DIP {DUP; CAR; DIP {CDR; PACK ; BLAKE2B}}; # Arrange the new piece of data
|
||||
CHECK_SIGNATURE; # Check to ensure the data is authentic
|
||||
# Update data
|
||||
IF {CDR; SWAP; DIP{DUP}; CDAR; PAIR}
|
||||
|
@ -5,7 +5,7 @@ code { DUP; CAR; DIP{CDDR}; # Stack rangling
|
||||
IF_NONE { PUSH bool False} # If not referenced, reject
|
||||
{ DUP; CAR; DIP{CDR}; AND};
|
||||
PAIR}
|
||||
{ DUP; CAR; DIP{CDR; DUP; BLAKE2B}; PAIR; SWAP; # Create the signature pair
|
||||
{ DUP; CAR; DIP{CDR; DUP; PACK ; BLAKE2B}; PAIR; SWAP; # Create the signature pair
|
||||
DIP{ DIP{DUP; CDR; DIP{CAR}; DUP};
|
||||
SWAP; CAR; DIP{DUP; UNPAIR}; CHECK_SIGNATURE }; # Check the first signature
|
||||
SWAP;
|
||||
|
@ -4,7 +4,7 @@ storage (pair (pair (contract %under_key unit)
|
||||
(contract %over_key unit))
|
||||
(pair (nat :rain %rain_level) (key %weather_service_key)));
|
||||
code { DUP; DUP;
|
||||
CAR; MAP_CDR{BLAKE2B};
|
||||
CAR; MAP_CDR{PACK ; BLAKE2B};
|
||||
SWAP; CDDDR %weather_service_key;
|
||||
DIP {UNPAIR} ; CHECK_SIGNATURE @sigok; # Check if the data has been correctly signed
|
||||
ASSERT; # If signature is not correct, end the execution
|
||||
|
@ -185,7 +185,7 @@ module Cost_of = struct
|
||||
let check_signature = step_cost 3
|
||||
let hash_key = step_cost 3
|
||||
(* TODO: This needs to be a function of the data being hashed *)
|
||||
let hash _data = step_cost 3
|
||||
let hash data = step_cost (MBytes.length data) +@ alloc_bytes_cost 32
|
||||
let steps_to_quota = step_cost 1
|
||||
let source = step_cost 3
|
||||
let self = step_cost 3
|
||||
|
@ -78,7 +78,7 @@ module Cost_of : sig
|
||||
val now : Gas.cost
|
||||
val check_signature : Gas.cost
|
||||
val hash_key : Gas.cost
|
||||
val hash : 'a -> Gas.cost
|
||||
val hash : MBytes.t -> Gas.cost
|
||||
val steps_to_quota : Gas.cost
|
||||
val source : Gas.cost
|
||||
val self : Gas.cost
|
||||
|
@ -600,10 +600,7 @@ let rec interp
|
||||
logged_return (Item (cmpres, rest), ctxt)
|
||||
(* packing *)
|
||||
| Pack t, Item (value, rest) ->
|
||||
unparse_data ctxt Optimized t value >>=? fun (expr, ctxt) ->
|
||||
let expr = (Micheline.strip_locations expr) in
|
||||
let bytes = Data_encoding.Binary.to_bytes_exn Script.expr_encoding expr in
|
||||
Lwt.return (Gas.consume ctxt (Interp_costs.unpack bytes)) >>=? fun ctxt ->
|
||||
Script_ir_translator.pack_data ctxt t value >>=? fun (bytes, ctxt) ->
|
||||
logged_return (Item (bytes, rest), ctxt)
|
||||
| Unpack t, Item (bytes, rest) ->
|
||||
Lwt.return (Gas.consume ctxt (Interp_costs.pack bytes)) >>=? fun ctxt ->
|
||||
@ -699,10 +696,9 @@ let rec interp
|
||||
| Hash_key, Item (key, rest) ->
|
||||
Lwt.return (Gas.consume ctxt Interp_costs.hash_key) >>=? fun ctxt ->
|
||||
logged_return (Item (Signature.Public_key.hash key, rest), ctxt)
|
||||
| Blake2b ty, Item (v, rest) ->
|
||||
Lwt.return (Gas.consume ctxt (Interp_costs.hash v)) >>=? fun ctxt ->
|
||||
hash_data ctxt ty v >>=? fun (hash, ctxt) ->
|
||||
let hash = Script_expr_hash.to_bytes hash in
|
||||
| Blake2b, Item (bytes, rest) ->
|
||||
Lwt.return (Gas.consume ctxt (Interp_costs.hash bytes)) >>=? fun ctxt ->
|
||||
let hash = Raw_hashes.blake2b bytes in
|
||||
logged_return (Item (hash, rest), ctxt)
|
||||
| Steps_to_quota, rest ->
|
||||
Lwt.return (Gas.consume ctxt Interp_costs.steps_to_quota) >>=? fun ctxt ->
|
||||
|
@ -202,7 +202,7 @@ let number_of_generated_growing_types : type b a. (b, a) instr -> int = function
|
||||
| Balance -> 0
|
||||
| Check_signature -> 0
|
||||
| Hash_key -> 0
|
||||
| Blake2b _ -> 0
|
||||
| Blake2b -> 0
|
||||
| Steps_to_quota -> 0
|
||||
| Source -> 0
|
||||
| Sender -> 0
|
||||
@ -2396,9 +2396,9 @@ and parse_instr
|
||||
typed ctxt loc Check_signature
|
||||
(Item_t (Bool_t None, rest, annot))
|
||||
| Prim (loc, I_BLAKE2B, [], annot),
|
||||
Item_t (t, rest, _) ->
|
||||
Item_t (Bytes_t _, rest, _) ->
|
||||
parse_var_annot loc annot >>=? fun annot ->
|
||||
typed ctxt loc (Blake2b t)
|
||||
typed ctxt loc Blake2b
|
||||
(Item_t (Bytes_t None, rest, annot))
|
||||
| Prim (loc, I_STEPS_TO_QUOTA, [], annot),
|
||||
stack ->
|
||||
|
@ -343,8 +343,8 @@ and ('bef, 'aft) instr =
|
||||
('a * 'rest, MBytes.t * 'rest) instr
|
||||
| Unpack : 'a ty ->
|
||||
(MBytes.t * 'rest, 'a option * 'rest) instr
|
||||
| Blake2b : 'a ty ->
|
||||
('a * 'rest, MBytes.t * 'rest) instr
|
||||
| Blake2b :
|
||||
(MBytes.t * 'rest, MBytes.t * 'rest) instr
|
||||
| Steps_to_quota : (* TODO: check that it always returns a nat *)
|
||||
('rest, n num * 'rest) instr
|
||||
| Source :
|
||||
|
Loading…
Reference in New Issue
Block a user