From 51c523d6b01f82bef45f60ed7b4c6db1fc985fee Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Tue, 8 Aug 2023 15:55:43 +0200 Subject: [PATCH] Allow arbitrary sized msg in signature verification --- CHANGELOG.md | 2 ++ docs/sophia_stdlib.md | 7 +++++-- src/aeso_ast_infer_types.erl | 2 +- test/contracts/unapplied_builtins.aes | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ea1a0e..8766f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 sized byte arrays. - `Chain.network_id` - a function to get hold of the Chain's network id. ### Changed +- `Crypto.verify_sig` is changed to have `msg : bytes()`. I.e. the + signed data can be of any length (used to be limited to `bytes(32)`/`hash`). ### Removed - `Bitwise.aes` standard library is removed - the builtin operations are superior. diff --git a/docs/sophia_stdlib.md b/docs/sophia_stdlib.md index b07e4a1..ad8b89d 100644 --- a/docs/sophia_stdlib.md +++ b/docs/sophia_stdlib.md @@ -834,11 +834,14 @@ Hash any object to blake2b #### verify_sig ``` -Crypto.verify_sig(msg : hash, pubkey : address, sig : signature) : bool +Crypto.verify_sig(msg : bytes(), pubkey : address, sig : signature) : bool ``` Checks if the signature of `msg` was made using private key corresponding to -the `pubkey` +the `pubkey`. + +Note: before v8 of the compiler, `msg` had type `hash` (i.e. `bytes(32)`). + #### ecverify_secp256k1 ``` diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 92001fd..7056024 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -775,7 +775,7 @@ global_env() -> %% Crypto/Curve operations CryptoScope = #scope { funs = MkDefs( - [{"verify_sig", Fun([Hash, Address, SignId], Bool)}, + [{"verify_sig", Fun([Bytes('_'), Address, SignId], Bool)}, {"verify_sig_secp256k1", Fun([Hash, Bytes(64), SignId], Bool)}, {"ecverify_secp256k1", Fun([Hash, Bytes(20), Bytes(65)], Bool)}, {"ecrecover_secp256k1", Fun([Hash, Bytes(65)], Option(Bytes(20)))}, diff --git a/test/contracts/unapplied_builtins.aes b/test/contracts/unapplied_builtins.aes index 5a8b340..f0be4c9 100644 --- a/test/contracts/unapplied_builtins.aes +++ b/test/contracts/unapplied_builtins.aes @@ -36,7 +36,7 @@ contract UnappliedBuiltins = function map_delete() = Map.delete : (_, m) => _ function map_from_list() = Map.from_list : _ => m function map_to_list() = Map.to_list : m => _ - function crypto_verify_sig() = Crypto.verify_sig + function crypto_verify_sig() = Crypto.verify_sig : (bytes(), _, _) => _ function crypto_verify_sig_secp256k1() = Crypto.verify_sig_secp256k1 function crypto_ecverify_secp256k1() = Crypto.ecverify_secp256k1 function crypto_ecrecover_secp256k1() = Crypto.ecrecover_secp256k1