Michelson: unpair input of CHECK_SIGNATURE

This commit is contained in:
Benjamin Canou 2018-04-22 22:59:15 +02:00 committed by Grégoire Henry
parent 8e28c790ea
commit 530427c813
16 changed files with 18 additions and 18 deletions

View File

@ -1538,7 +1538,7 @@ Cryptographic primitives
:: ::
:: key : pair signature string : 'S -> bool : 'S :: key : signature : string : 'S -> bool : 'S
- ``COMPARE``: - ``COMPARE``:

View File

@ -17,7 +17,7 @@ code { DUP; CAR;
# Withdrawl # Withdrawl
{ DUP; DUP; DUP; DUP; { DUP; DUP; DUP; DUP;
# Check signature on data # Check signature on data
CAR; DIIP{ CDAR; H }; DIP{ CDDR; PAIR }; CHECK_SIGNATURE; CAR; DIIP{ CDAR; H }; DIP{ CDDR }; CHECK_SIGNATURE;
IF {} { FAIL }; IF {} { FAIL };
# Get user account information # Get user account information
DIIP{ CDR; DUP }; CAR; HASH_KEY; DIP{ SWAP }; GET; DIIP{ CDR; DUP }; CAR; HASH_KEY; DIP{ SWAP }; GET;

View File

@ -3,6 +3,6 @@ storage (pair signature string);
code { DUP; DUP; code { DUP; DUP;
DIP{ CDR; DUP; CAR; DIP{ CDR; DUP; CAR;
DIP{CDR; H}; PAIR}; DIP{CDR; H}; PAIR};
CAR; CHECK_SIGNATURE; CAR; DIP {UNPAIR}; CHECK_SIGNATURE;
IF {} {FAIL} ; IF {} {FAIL} ;
CDR; NIL operation ; PAIR}; CDR; NIL operation ; PAIR};

View File

@ -1,7 +1,7 @@
parameter (pair signature (pair string nat)); parameter (pair signature (pair string nat));
storage (pair (pair key nat) string); storage (pair (pair key nat) string);
code { DUP; CAR; DIP{CDR; DUP}; code { DUP; CAR; DIP{CDR; DUP};
SWAP; DIP{DUP}; CAAR; DIP{DUP; CAR; DIP{CDR; H}; PAIR}; SWAP; DIP{DUP}; CAAR; DIP{DUP; CAR; DIP{CDR; H}};
CHECK_SIGNATURE; CHECK_SIGNATURE;
IF { CDR; DUP; DIP{CAR; DIP{CAAR}}; CDR; PUSH nat 1; ADD; IF { CDR; DUP; DIP{CAR; DIP{CAAR}}; CDR; PUSH nat 1; ADD;
DIP{SWAP}; SWAP; PAIR; PAIR; NIL operation; PAIR} DIP{SWAP}; SWAP; PAIR; PAIR; NIL operation; PAIR}

View File

@ -7,7 +7,7 @@ code {DUP; DUP; CAR;
# Provide the data # Provide the data
CDR; DIP {CDDR}} CDR; DIP {CDDR}}
{DUP; DIP{SWAP}; SWAP; CDAR; # Move key to the top {DUP; DIP{SWAP}; SWAP; CDAR; # Move key to the top
DIP {DUP; CAR; DIP {CDR; H}; PAIR}; # Arrange the new piece of data DIP {DUP; CAR; DIP {CDR; H}}; # Arrange the new piece of data
CHECK_SIGNATURE; # Check to ensure the data is authentic CHECK_SIGNATURE; # Check to ensure the data is authentic
# Update data # Update data
IF {CDR; SWAP; DIP{DUP}; CDAR; PAIR} IF {CDR; SWAP; DIP{DUP}; CDAR; PAIR}

View File

@ -7,14 +7,14 @@ code { DUP; CAR; DIP{CDDR}; # Stack rangling
PAIR} PAIR}
{ DUP; CAR; DIP{CDR; DUP; H}; PAIR; SWAP; # Create the signature pair { DUP; CAR; DIP{CDR; DUP; H}; PAIR; SWAP; # Create the signature pair
DIP{ DIP{DUP; CDR; DIP{CAR}; DUP}; DIP{ DIP{DUP; CDR; DIP{CAR}; DUP};
SWAP; CAR; DIP{DUP}; CHECK_SIGNATURE }; # Check the first signature SWAP; CAR; DIP{DUP; UNPAIR}; CHECK_SIGNATURE }; # Check the first signature
SWAP; SWAP;
# If the signature typechecked, get and update the first element of the pair # If the signature typechecked, get and update the first element of the pair
IF { DIP{DROP; SWAP; DUP}; DUP; IF { DIP{DROP; SWAP; DUP}; DUP;
DIP{ GET; IF_NONE{PUSH (pair bool bool) (Pair False False)} {}; DIP{ GET; IF_NONE{PUSH (pair bool bool) (Pair False False)} {};
CDR; PUSH bool True; PAIR; SOME }} CDR; PUSH bool True; PAIR; SOME }}
# Check the second signature # Check the second signature
{ DIP{DIP{DUP; CDR}; SWAP; CHECK_SIGNATURE}; SWAP; { DIP{DIP{DUP; CDR}; SWAP; DIP {UNPAIR}; CHECK_SIGNATURE}; SWAP;
IF { DUP; DIP{DIP{SWAP; DUP}; GET}; SWAP; IF { DUP; DIP{DIP{SWAP; DUP}; GET}; SWAP;
IF_NONE {PUSH (pair bool bool) (Pair False False)} {}; IF_NONE {PUSH (pair bool bool) (Pair False False)} {};
CAR; PUSH bool True; SWAP; PAIR; SOME; SWAP} CAR; PUSH bool True; SWAP; PAIR; SOME; SWAP}

View File

@ -6,7 +6,7 @@ storage (pair (pair (contract @lt unit)
(pair nat key)); (pair nat key));
code { DUP; DUP; code { DUP; DUP;
CAR; MAP_CDR{H}; CAR; MAP_CDR{H};
SWAP; CDDDR; CHECK_SIGNATURE; # Check if the data has been correctly signed SWAP; CDDDR; DIP {UNPAIR} ; CHECK_SIGNATURE; # Check if the data has been correctly signed
ASSERT; # If signature is not correct, end the execution ASSERT; # If signature is not correct, end the execution
DUP; DUP; DUP; DIIIP{CDR}; # Place storage type on bottom of stack DUP; DUP; DUP; DIIIP{CDR}; # Place storage type on bottom of stack
DIIP{CDAR}; # Place contracts below numbers DIIP{CDAR}; # Place contracts below numbers

View File

@ -714,7 +714,7 @@ let rec interp
Lwt.return (Gas.consume ctxt Interp_costs.now) >>=? fun ctxt -> Lwt.return (Gas.consume ctxt Interp_costs.now) >>=? fun ctxt ->
let now = Script_timestamp.now ctxt in let now = Script_timestamp.now ctxt in
logged_return (Item (now, rest), ctxt) logged_return (Item (now, rest), ctxt)
| Check_signature, Item (key, Item ((signature, message), rest)) -> | Check_signature, Item (key, Item (signature, Item (message, rest))) ->
Lwt.return (Gas.consume ctxt Interp_costs.check_signature) >>=? fun ctxt -> Lwt.return (Gas.consume ctxt Interp_costs.check_signature) >>=? fun ctxt ->
let message = MBytes.of_string message in let message = MBytes.of_string message in
let res = Signature.check key signature message in let res = Signature.check key signature message in

View File

@ -2134,7 +2134,7 @@ and parse_instr
typed ctxt loc Hash_key typed ctxt loc Hash_key
(Item_t (Key_hash_t, rest, instr_annot)) (Item_t (Key_hash_t, rest, instr_annot))
| Prim (loc, I_CHECK_SIGNATURE, [], instr_annot), | Prim (loc, I_CHECK_SIGNATURE, [], instr_annot),
Item_t (Key_t, Item_t (Pair_t ((Signature_t, _), (String_t, _)), rest, _), _) -> Item_t (Key_t, Item_t (Signature_t, Item_t (String_t, rest, _), _), _) ->
typed ctxt loc Check_signature typed ctxt loc Check_signature
(Item_t (Bool_t, rest, instr_annot)) (Item_t (Bool_t, rest, instr_annot))
| Prim (loc, I_H, [], instr_annot), | Prim (loc, I_H, [], instr_annot),

View File

@ -351,7 +351,7 @@ and ('bef, 'aft) instr =
| Balance : | Balance :
('rest, Tez.t * 'rest) instr ('rest, Tez.t * 'rest) instr
| Check_signature : | Check_signature :
(public_key * ((signature * string) * 'rest), bool * 'rest) instr (public_key * (signature * (string * 'rest)), bool * 'rest) instr
| Hash_key : | Hash_key :
(public_key * 'rest, public_key_hash * 'rest) instr (public_key * 'rest, public_key_hash * 'rest) instr
| H : 'a ty -> | H : 'a ty ->

View File

@ -17,7 +17,7 @@ code { DUP; CAR;
# Withdrawl # Withdrawl
{ DUP; DUP; DUP; DUP; { DUP; DUP; DUP; DUP;
# Check signature on data # Check signature on data
CAR; DIIP{ CDAR; H }; DIP{ CDDR; PAIR }; CHECK_SIGNATURE; CAR; DIIP{ CDAR; H }; DIP{ CDDR }; CHECK_SIGNATURE;
IF {} { FAIL }; IF {} { FAIL };
# Get user account information # Get user account information
DIIP{ CDR; DUP }; CAR; HASH_KEY; DIP{ SWAP }; GET; DIIP{ CDR; DUP }; CAR; HASH_KEY; DIP{ SWAP }; GET;

View File

@ -3,6 +3,6 @@ storage (pair signature string);
code { DUP; DUP; code { DUP; DUP;
DIP{ CDR; DUP; CAR; DIP{ CDR; DUP; CAR;
DIP{CDR; H}; PAIR}; DIP{CDR; H}; PAIR};
CAR; CHECK_SIGNATURE; CAR; DIP {UNPAIR}; CHECK_SIGNATURE;
IF {} {FAIL} ; IF {} {FAIL} ;
CDR; NIL operation ; PAIR}; CDR; NIL operation ; PAIR};

View File

@ -1,7 +1,7 @@
parameter (pair signature (pair string nat)); parameter (pair signature (pair string nat));
storage (pair (pair key nat) string); storage (pair (pair key nat) string);
code { DUP; CAR; DIP{CDR; DUP}; code { DUP; CAR; DIP{CDR; DUP};
SWAP; DIP{DUP}; CAAR; DIP{DUP; CAR; DIP{CDR; H}; PAIR}; SWAP; DIP{DUP}; CAAR; DIP{DUP; CAR; DIP{CDR; H}};
CHECK_SIGNATURE; CHECK_SIGNATURE;
IF { CDR; DUP; DIP{CAR; DIP{CAAR}}; CDR; PUSH nat 1; ADD; IF { CDR; DUP; DIP{CAR; DIP{CAAR}}; CDR; PUSH nat 1; ADD;
DIP{SWAP}; SWAP; PAIR; PAIR; NIL operation; PAIR} DIP{SWAP}; SWAP; PAIR; PAIR; NIL operation; PAIR}

View File

@ -7,7 +7,7 @@ code {DUP; DUP; CAR;
# Provide the data # Provide the data
CDR; DIP {CDDR}} CDR; DIP {CDDR}}
{DUP; DIP{SWAP}; SWAP; CDAR; # Move key to the top {DUP; DIP{SWAP}; SWAP; CDAR; # Move key to the top
DIP {DUP; CAR; DIP {CDR; H}; PAIR}; # Arrange the new piece of data DIP {DUP; CAR; DIP {CDR; H}}; # Arrange the new piece of data
CHECK_SIGNATURE; # Check to ensure the data is authentic CHECK_SIGNATURE; # Check to ensure the data is authentic
# Update data # Update data
IF {CDR; SWAP; DIP{DUP}; CDAR; PAIR} IF {CDR; SWAP; DIP{DUP}; CDAR; PAIR}

View File

@ -7,14 +7,14 @@ code { DUP; CAR; DIP{CDDR}; # Stack rangling
PAIR} PAIR}
{ DUP; CAR; DIP{CDR; DUP; H}; PAIR; SWAP; # Create the signature pair { DUP; CAR; DIP{CDR; DUP; H}; PAIR; SWAP; # Create the signature pair
DIP{ DIP{DUP; CDR; DIP{CAR}; DUP}; DIP{ DIP{DUP; CDR; DIP{CAR}; DUP};
SWAP; CAR; DIP{DUP}; CHECK_SIGNATURE }; # Check the first signature SWAP; CAR; DIP{DUP; UNPAIR}; CHECK_SIGNATURE }; # Check the first signature
SWAP; SWAP;
# If the signature typechecked, get and update the first element of the pair # If the signature typechecked, get and update the first element of the pair
IF { DIP{DROP; SWAP; DUP}; DUP; IF { DIP{DROP; SWAP; DUP}; DUP;
DIP{ GET; IF_NONE{PUSH (pair bool bool) (Pair False False)} {}; DIP{ GET; IF_NONE{PUSH (pair bool bool) (Pair False False)} {};
CDR; PUSH bool True; PAIR; SOME }} CDR; PUSH bool True; PAIR; SOME }}
# Check the second signature # Check the second signature
{ DIP{DIP{DUP; CDR}; SWAP; CHECK_SIGNATURE}; SWAP; { DIP{DIP{DUP; CDR}; SWAP; DIP {UNPAIR}; CHECK_SIGNATURE}; SWAP;
IF { DUP; DIP{DIP{SWAP; DUP}; GET}; SWAP; IF { DUP; DIP{DIP{SWAP; DUP}; GET}; SWAP;
IF_NONE {PUSH (pair bool bool) (Pair False False)} {}; IF_NONE {PUSH (pair bool bool) (Pair False False)} {};
CAR; PUSH bool True; SWAP; PAIR; SOME; SWAP} CAR; PUSH bool True; SWAP; PAIR; SOME; SWAP}

View File

@ -6,7 +6,7 @@ storage (pair (pair (contract @lt unit)
(pair nat key)); (pair nat key));
code { DUP; DUP; code { DUP; DUP;
CAR; MAP_CDR{H}; CAR; MAP_CDR{H};
SWAP; CDDDR; CHECK_SIGNATURE; # Check if the data has been correctly signed SWAP; CDDDR; DIP {UNPAIR} ; CHECK_SIGNATURE; # Check if the data has been correctly signed
ASSERT; # If signature is not correct, end the execution ASSERT; # If signature is not correct, end the execution
DUP; DUP; DUP; DIIIP{CDR}; # Place storage type on bottom of stack DUP; DUP; DUP; DIIIP{CDR}; # Place storage type on bottom of stack
DIIP{CDAR}; # Place contracts below numbers DIIP{CDAR}; # Place contracts below numbers