From f53cb4091534e04941404c57300fdcd1fe26630c Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Wed, 6 Jun 2018 11:28:07 +0200 Subject: [PATCH] Michelson: do not padd nat-encoded addresses that are now fixed sized --- .../lib_protocol/src/script_ir_translator.ml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/src/script_ir_translator.ml b/src/proto_alpha/lib_protocol/src/script_ir_translator.ml index 57463008e..ad2cc507b 100644 --- a/src/proto_alpha/lib_protocol/src/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/src/script_ir_translator.ml @@ -949,6 +949,11 @@ let signature_size = | None -> assert false | Some size -> size +let address_size = + match Data_encoding.Binary.fixed_length Contract.encoding with + | None -> assert false + | Some size -> size + let rec parse_data : type a. ?type_logger: (int -> Script.expr list -> Script.expr list -> unit) -> @@ -1133,8 +1138,9 @@ let rec parse_data (* Addresses *) | Address_t, Int (_, z) (* As unparsed with [O[ptimized]. *) -> Lwt.return (Gas.consume ctxt Typecheck_costs.contract) >>=? fun ctxt -> - bytes_of_padded_z z >>=? fun bytes -> - begin match Data_encoding.Binary.of_bytes Contract.encoding bytes with + begin + let bytes = Z.to_bits ~pad_to:address_size z in + match Data_encoding.Binary.of_bytes Contract.encoding bytes with | Some c -> return (c, ctxt) | None -> fail (error ()) end @@ -1147,8 +1153,9 @@ let rec parse_data (* Contracts *) | Contract_t ty, Int (loc, z) (* As unparsed with [Optimized]. *) -> Lwt.return (Gas.consume ctxt Typecheck_costs.contract) >>=? fun ctxt -> - bytes_of_padded_z z >>=? fun bytes -> - begin match Data_encoding.Binary.of_bytes Contract.encoding bytes with + begin + let bytes = Z.to_bits ~pad_to:address_size z in + match Data_encoding.Binary.of_bytes Contract.encoding bytes with | Some c -> traced (parse_contract ctxt loc ty c) >>=? fun (ctxt, _) -> return ((ty, c), ctxt) @@ -2328,7 +2335,7 @@ let rec unparse_data match mode with | Optimized -> let bytes = Data_encoding.Binary.to_bytes_exn Contract.encoding c in - return (Int (-1, padded_z_of_bytes bytes), ctxt) + return (Int (-1, Z.of_bits bytes), ctxt) | Readable -> return (String (-1, Contract.to_b58check c), ctxt) end | Contract_t _, (_, c) -> @@ -2337,7 +2344,7 @@ let rec unparse_data match mode with | Optimized -> let bytes = Data_encoding.Binary.to_bytes_exn Contract.encoding c in - return (Int (-1, padded_z_of_bytes bytes), ctxt) + return (Int (-1, Z.of_bits bytes), ctxt) | Readable -> return (String (-1, Contract.to_b58check c), ctxt) end | Signature_t, s ->