From 1de1b5b6f5981fbadf17b383689750f3a9838e9b Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Thu, 22 Aug 2024 15:23:04 +0200 Subject: [PATCH 01/12] impl new crypto opcodes --- framework/base/src/api/crypto_api.rs | 21 +++++++++++ .../api/uncallable/crypto_api_uncallable.rs | 27 ++++++++++++++ .../src/api/core_api_vh/crypto_api_vh.rs | 27 ++++++++++++++ .../wasm-adapter/src/api/crypto_api_node.rs | 37 +++++++++++++++++++ 4 files changed, 112 insertions(+) diff --git a/framework/base/src/api/crypto_api.rs b/framework/base/src/api/crypto_api.rs index 3c5c374a87..235e44919a 100644 --- a/framework/base/src/api/crypto_api.rs +++ b/framework/base/src/api/crypto_api.rs @@ -76,4 +76,25 @@ pub trait CryptoApiImpl: ManagedTypeApiImpl { s: Self::ManagedBufferHandle, dest: Self::ManagedBufferHandle, ); + + fn verify_secp256r1_managed( + &self, + key: Self::ManagedBufferHandle, + message: Self::ManagedBufferHandle, + signature: Self::ManagedBufferHandle, + ) -> bool; + + fn verify_bls_signature_share_managed( + &self, + key: Self::ManagedBufferHandle, + message: Self::ManagedBufferHandle, + signature: Self::ManagedBufferHandle, + ) -> bool; + + fn verify_bls_aggregated_signature_managed( + &self, + key: Self::ManagedBufferHandle, + message: Self::ManagedBufferHandle, + signature: Self::ManagedBufferHandle, + ) -> bool; } diff --git a/framework/base/src/api/uncallable/crypto_api_uncallable.rs b/framework/base/src/api/uncallable/crypto_api_uncallable.rs index 59195618c9..bb42aa04bb 100644 --- a/framework/base/src/api/uncallable/crypto_api_uncallable.rs +++ b/framework/base/src/api/uncallable/crypto_api_uncallable.rs @@ -82,4 +82,31 @@ impl CryptoApiImpl for UncallableApi { ) { unreachable!() } + + fn verify_secp256r1_managed( + &self, + _key: Self::ManagedBufferHandle, + _message: Self::ManagedBufferHandle, + _signature: Self::ManagedBufferHandle, + ) -> bool { + unreachable!() + } + + fn verify_bls_signature_share_managed( + &self, + _key: Self::ManagedBufferHandle, + _message: Self::ManagedBufferHandle, + _signature: Self::ManagedBufferHandle, + ) -> bool { + unreachable!() + } + + fn verify_bls_aggregated_signature_managed( + &self, + _key: Self::ManagedBufferHandle, + _message: Self::ManagedBufferHandle, + _signature: Self::ManagedBufferHandle, + ) -> bool { + unreachable!() + } } diff --git a/framework/scenario/src/api/core_api_vh/crypto_api_vh.rs b/framework/scenario/src/api/core_api_vh/crypto_api_vh.rs index f3789181e7..aa4c2dab94 100644 --- a/framework/scenario/src/api/core_api_vh/crypto_api_vh.rs +++ b/framework/scenario/src/api/core_api_vh/crypto_api_vh.rs @@ -99,4 +99,31 @@ impl CryptoApiImpl for VMHooksApi { ) { panic!("encode_secp256k1_signature not implemented yet!") } + + fn verify_secp256r1_managed( + &self, + _key: Self::ManagedBufferHandle, + _message: Self::ManagedBufferHandle, + _signature: Self::ManagedBufferHandle, + ) -> bool { + panic!("verify_secp256r1 not implemented yet!") + } + + fn verify_bls_signature_share_managed( + &self, + _key: Self::ManagedBufferHandle, + _message: Self::ManagedBufferHandle, + _signature: Self::ManagedBufferHandle, + ) -> bool { + panic!("verify_bls_signature_share not implemented yet!") + } + + fn verify_bls_aggregated_signature_managed( + &self, + _key: Self::ManagedBufferHandle, + _message: Self::ManagedBufferHandle, + _signature: Self::ManagedBufferHandle, + ) -> bool { + panic!("verify_bls_aggregated_signature not implemented yet!") + } } diff --git a/framework/wasm-adapter/src/api/crypto_api_node.rs b/framework/wasm-adapter/src/api/crypto_api_node.rs index eb16e25e6a..0cbe24fad5 100644 --- a/framework/wasm-adapter/src/api/crypto_api_node.rs +++ b/framework/wasm-adapter/src/api/crypto_api_node.rs @@ -25,6 +25,16 @@ extern "C" { ) -> i32; fn managedEncodeSecp256k1DerSignature(rHandle: i32, sHandle: i32, sigHandle: i32) -> i32; + + fn managedVerifySecp256r1(keyHandle: i32, messageHandle: i32, sigHandle: i32) -> i32; + + fn managedVerifyBLSSignatureShare(keyHandle: i32, messageHandle: i32, sigHandle: i32) -> i32; + + fn managedVerifyBLSAggregatedSignature( + keyHandle: i32, + messageHandle: i32, + sigHandle: i32, + ) -> i32; } impl CryptoApi for VmApiImpl { @@ -123,4 +133,31 @@ impl CryptoApiImpl for VmApiImpl { let _ = managedEncodeSecp256k1DerSignature(r, s, dest_sig_handle); } } + + fn verify_secp256r1_managed( + &self, + key: Self::ManagedBufferHandle, + message: Self::ManagedBufferHandle, + signature: Self::ManagedBufferHandle, + ) -> bool { + unsafe { managedVerifySecp256r1(key, message, signature) == 0 } + } + + fn verify_bls_signature_share_managed( + &self, + key: Self::ManagedBufferHandle, + message: Self::ManagedBufferHandle, + signature: Self::ManagedBufferHandle, + ) -> bool { + unsafe { managedVerifyBLSSignatureShare(key, message, signature) == 0 } + } + + fn verify_bls_aggregated_signature_managed( + &self, + key: Self::ManagedBufferHandle, + message: Self::ManagedBufferHandle, + signature: Self::ManagedBufferHandle, + ) -> bool { + unsafe { managedVerifyBLSAggregatedSignature(key, message, signature) == 0 } + } } From 9543e03aab14eeb01b2e72aec2b6454bae724a78 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Thu, 22 Aug 2024 16:30:59 +0200 Subject: [PATCH 02/12] added in crypto wrapper and test contract --- .../basic-features/sc-config.toml | 3 ++ .../basic-features/src/crypto_features.rs | 30 ++++++++++++++ .../basic-features/wasm/src/lib.rs | 7 +++- .../contract_base/wrappers/crypto_wrapper.rs | 39 +++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/contracts/feature-tests/basic-features/sc-config.toml b/contracts/feature-tests/basic-features/sc-config.toml index 82698d1dab..6b24db99b9 100644 --- a/contracts/feature-tests/basic-features/sc-config.toml +++ b/contracts/feature-tests/basic-features/sc-config.toml @@ -1,6 +1,9 @@ [settings] main = "basic-features" +[contracts.basic-features] +ei = "1.4" + [contracts.basic-features.profile] overflow-checks = true # needed for overflow tests diff --git a/contracts/feature-tests/basic-features/src/crypto_features.rs b/contracts/feature-tests/basic-features/src/crypto_features.rs index 56c543163c..2c08b850e5 100644 --- a/contracts/feature-tests/basic-features/src/crypto_features.rs +++ b/contracts/feature-tests/basic-features/src/crypto_features.rs @@ -64,4 +64,34 @@ pub trait CryptoFeatures { fn compute_secp256k1_der_signature(&self, r: ManagedBuffer, s: ManagedBuffer) -> ManagedBuffer { self.crypto().encode_secp256k1_der_signature(&r, &s) } + + #[endpoint] + fn verify_secp256r1_signature( + &self, + key: ManagedBuffer, + message: ManagedBuffer, + signature: ManagedBuffer, + ) -> bool { + self.crypto().verify_secp256r1(&key, &message, &signature) + } + #[endpoint] + fn verify_bls_signature_share_managed( + &self, + key: ManagedBuffer, + message: ManagedBuffer, + signature: ManagedBuffer, + ) -> bool { + self.crypto() + .verify_bls_signature_share(&key, &message, &signature) + } + #[endpoint] + fn verify_bls_aggregated_signature_managed( + &self, + key: ManagedBuffer, + message: ManagedBuffer, + signature: ManagedBuffer, + ) -> bool { + self.crypto() + .verify_bls_aggregated_signature(&key, &message, &signature) + } } diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index 887b75bcd5..c602f6e198 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 403 +// Endpoints: 406 // Async Callback: 1 -// Total number of exported functions: 405 +// Total number of exported functions: 408 #![no_std] @@ -145,6 +145,9 @@ multiversx_sc_wasm_adapter::endpoints! { verify_secp256k1_signature => verify_secp256k1_signature verify_custom_secp256k1_signature => verify_custom_secp256k1_signature compute_secp256k1_der_signature => compute_secp256k1_der_signature + verify_secp256r1_signature => verify_secp256r1_signature + verify_bls_signature_share_managed => verify_bls_signature_share_managed + verify_bls_aggregated_signature_managed => verify_bls_aggregated_signature_managed echo_u64 => echo_u64 echo_i64 => echo_i64 echo_i32 => echo_i32 diff --git a/framework/base/src/contract_base/wrappers/crypto_wrapper.rs b/framework/base/src/contract_base/wrappers/crypto_wrapper.rs index c314899eaa..76b8fcd996 100644 --- a/framework/base/src/contract_base/wrappers/crypto_wrapper.rs +++ b/framework/base/src/contract_base/wrappers/crypto_wrapper.rs @@ -129,4 +129,43 @@ where ); ManagedBuffer::from_handle(new_handle) } + + pub fn verify_secp256r1( + &self, + key: &ManagedBuffer, + message: &ManagedBuffer, + signature: &ManagedBuffer, + ) -> bool { + A::crypto_api_impl().verify_secp256r1_managed( + key.get_handle(), + message.get_handle(), + signature.get_handle(), + ) + } + + pub fn verify_bls_signature_share( + &self, + key: &ManagedBuffer, + message: &ManagedBuffer, + signature: &ManagedBuffer, + ) -> bool { + A::crypto_api_impl().verify_bls_signature_share_managed( + key.get_handle(), + message.get_handle(), + signature.get_handle(), + ) + } + + pub fn verify_bls_aggregated_signature( + &self, + key: &ManagedBuffer, + message: &ManagedBuffer, + signature: &ManagedBuffer, + ) -> bool { + A::crypto_api_impl().verify_bls_aggregated_signature_managed( + key.get_handle(), + message.get_handle(), + signature.get_handle(), + ) + } } From 3fc082a04f42d54f7c9bebb764c9485266708221 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Thu, 22 Aug 2024 17:30:17 +0200 Subject: [PATCH 03/12] added tests --- .../scenarios/crypto_verify_bls.scen.json | 52 +++++++- .../crypto_verify_secp256r1.scen.json | 121 ++++++++++++++++++ .../basic-features/src/crypto_features.rs | 6 +- .../tests/basic_features_scenario_go_test.rs | 5 + .../tests/basic_features_scenario_rs_test.rs | 6 + .../basic-features/wasm/src/lib.rs | 4 +- 6 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json index ead18354dc..7b07232695 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json @@ -41,6 +41,56 @@ "gas": "*", "refund": "*" } + }, + { + "step": "scCall", + "id": "4", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "verify_bls_signature_share", + "arguments": [ + "0xb5823f6e564251cc03ce7bad3da83e72576e92795d3500bba1acb30ec9a94dce87bb8aa794d67b2d61d15c33f28f6c0c23ba1dfcbf21e8f8b46286ff871afabac925303ddcaddce6254fcff6d3155797db40b3d3b5865e8fc0bd770b3d79b381", + "0x6d65737361676520746f206265207369676e6564", + "0xaf32a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "5", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "verify_bls_aggregated_signature", + "arguments": [ + "0xb5823f6e564251cc03ce7bad3da83e72576e92795d3500bba1acb30ec9a94dce87bb8aa794d67b2d61d15c33f28f6c0c23ba1dfcbf21e8f8b46286ff871afabac925303ddcaddce6254fcff6d3155797db40b3d3b5865e8fc0bd770b3d79b381", + "0x6d65737361676520746f206265207369676e6564", + "0xaf32a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } } ] -} +} \ No newline at end of file diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json new file mode 100644 index 0000000000..e87822db95 --- /dev/null +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json @@ -0,0 +1,121 @@ +{ + "name": "crypto", + "comment": "", + "gasSchedule": "v3", + "steps": [ + { + "step": "setState", + "accounts": { + "sc:basic-features": { + "nonce": "0", + "balance": "0", + "code": "mxsc:../output/basic-features.mxsc.json" + }, + "address:an_account": { + "nonce": "0", + "balance": "0" + } + } + }, + { + "step": "scCall", + "id": "5 - compressed key", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "verify_secp256r1_signature", + "arguments": [ + "0x02a673638cb9587cb68ea08dbef685c6f2d2a751a8b3c6f2a7e9a4999e6e4bfaf5", + "0x6d65737361676520746f207369676e", + "0x3045022100fab29dbcb623e7e96f44665f312b89ffdb9e4d2e2f53353236fbbcf57b2f49bf02203d6f9c63df8be43121042970a549a2d3baeca093fd37b726ddcc0924638409f5" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "6 - uncompressed key", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "verify_secp256r1_signature", + "arguments": [ + "0x04a673638cb9587cb68ea08dbef685c6f2d2a751a8b3c6f2a7e9a4999e6e4bfaf5ca1d22fe57c6103dbaac10cf15d15c0791cab8bb9a04f800e4d215276cb3e008", + "0x6d65737361676520746f207369676e", + "0x3045022100fab29dbcb623e7e96f44665f312b89ffdb9e4d2e2f53353236fbbcf57b2f49bf02203d6f9c63df8be43121042970a549a2d3baeca093fd37b726ddcc0924638409f5" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "7 - encode key from r and s", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "compute_secp256k1_der_signature", + "arguments": [ + "0x90f27b8b488db00b00606796d2987f6a5f59ae62ea05effe84fef5b8b0e54998", + "0x4a691139ad57a3f0b906637673aa2f63d1f55cb1a69199d4009eea23ceaddc93" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x304502210090f27b8b488db00b00606796d2987f6a5f59ae62ea05effe84fef5b8b0e5499802204a691139ad57a3f0b906637673aa2f63d1f55cb1a69199d4009eea23ceaddc93" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "8 - verify custom secp256k1", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "verify_custom_secp256k1_signature", + "arguments": [ + "0x04e32df42865e97135acfb65f3bae71bdc86f4d49150ad6a440b6f15878109880a0a2b2667f7e725ceea70c673093bf67663e0312623c8e091b13cf2c0f11ef652", + "0xce0677bb30baa8cf067c88db9811f4333d131bf8bcf12fe7065d211dce971008", + "0x304502210090f27b8b488db00b00606796d2987f6a5f59ae62ea05effe84fef5b8b0e5499802204a691139ad57a3f0b906637673aa2f63d1f55cb1a69199d4009eea23ceaddc93", + "0" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + } + ] +} diff --git a/contracts/feature-tests/basic-features/src/crypto_features.rs b/contracts/feature-tests/basic-features/src/crypto_features.rs index 2c08b850e5..f66479026c 100644 --- a/contracts/feature-tests/basic-features/src/crypto_features.rs +++ b/contracts/feature-tests/basic-features/src/crypto_features.rs @@ -74,8 +74,9 @@ pub trait CryptoFeatures { ) -> bool { self.crypto().verify_secp256r1(&key, &message, &signature) } + #[endpoint] - fn verify_bls_signature_share_managed( + fn verify_bls_signature_share( &self, key: ManagedBuffer, message: ManagedBuffer, @@ -84,8 +85,9 @@ pub trait CryptoFeatures { self.crypto() .verify_bls_signature_share(&key, &message, &signature) } + #[endpoint] - fn verify_bls_aggregated_signature_managed( + fn verify_bls_aggregated_signature( &self, key: ManagedBuffer, message: ManagedBuffer, diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs index 9c39d06ae5..f5a9a10726 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs @@ -94,6 +94,11 @@ fn crypto_verify_secp_256_k_1_go() { world().run("scenarios/crypto_verify_secp256k1.scen.json"); } +#[test] +fn crypto_verify_secp_256_r_1_go() { + world().run("scenarios/crypto_verify_secp256r1.scen.json"); +} + #[test] fn echo_array_u_8_go() { world().run("scenarios/echo_array_u8.scen.json"); diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs index f35c4779e6..95a617e20c 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs @@ -109,6 +109,12 @@ fn crypto_verify_secp_256_k_1_rs() { world().run("scenarios/crypto_verify_secp256k1.scen.json"); } +#[test] +#[ignore] +fn crypto_verify_secp_256_r_1_rs() { + world().run("scenarios/crypto_verify_secp256r1.scen.json"); +} + #[test] fn echo_array_u_8_rs() { world().run("scenarios/echo_array_u8.scen.json"); diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index c602f6e198..90986ec90b 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -146,8 +146,8 @@ multiversx_sc_wasm_adapter::endpoints! { verify_custom_secp256k1_signature => verify_custom_secp256k1_signature compute_secp256k1_der_signature => compute_secp256k1_der_signature verify_secp256r1_signature => verify_secp256r1_signature - verify_bls_signature_share_managed => verify_bls_signature_share_managed - verify_bls_aggregated_signature_managed => verify_bls_aggregated_signature_managed + verify_bls_signature_share => verify_bls_signature_share + verify_bls_aggregated_signature => verify_bls_aggregated_signature echo_u64 => echo_u64 echo_i64 => echo_i64 echo_i32 => echo_i32 From 6e59c53c981f86059622da9d4eba376f03e294f1 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 23 Aug 2024 15:33:53 +0200 Subject: [PATCH 04/12] created contract variant from new crypto endpoints --- .../basic-features/sc-config.toml | 11 ++++++ .../wasm-basic-features-crypto/Cargo.toml | 35 +++++++++++++++++++ .../wasm-basic-features-crypto/src/lib.rs | 27 ++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 contracts/feature-tests/basic-features/wasm-basic-features-crypto/Cargo.toml create mode 100644 contracts/feature-tests/basic-features/wasm-basic-features-crypto/src/lib.rs diff --git a/contracts/feature-tests/basic-features/sc-config.toml b/contracts/feature-tests/basic-features/sc-config.toml index 6b24db99b9..b21719850f 100644 --- a/contracts/feature-tests/basic-features/sc-config.toml +++ b/contracts/feature-tests/basic-features/sc-config.toml @@ -12,6 +12,17 @@ add-unlabelled = false add-endpoints = ["init", "load_bytes", "store_bytes"] kill_legacy_callback = true +[contracts.basic-features-crypto] +ei = "1.4" +add-unlabelled = false +add-endpoints = [ + "init", + "verify_secp256r1_signature", + "verify_bls_signature_share", + "verify_bls_aggregated_signature", +] +kill_legacy_callback = true + [[proxy]] path = "src/basic_features_proxy.rs" add-unlabelled = false diff --git a/contracts/feature-tests/basic-features/wasm-basic-features-crypto/Cargo.toml b/contracts/feature-tests/basic-features/wasm-basic-features-crypto/Cargo.toml new file mode 100644 index 0000000000..46f40289e3 --- /dev/null +++ b/contracts/feature-tests/basic-features/wasm-basic-features-crypto/Cargo.toml @@ -0,0 +1,35 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "basic-features-crypto-wasm" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.basic-features] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.52.3" +path = "../../../../framework/wasm-adapter" + +[workspace] +members = ["."] diff --git a/contracts/feature-tests/basic-features/wasm-basic-features-crypto/src/lib.rs b/contracts/feature-tests/basic-features/wasm-basic-features-crypto/src/lib.rs new file mode 100644 index 0000000000..134138a65f --- /dev/null +++ b/contracts/feature-tests/basic-features/wasm-basic-features-crypto/src/lib.rs @@ -0,0 +1,27 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 3 +// Async Callback (empty): 1 +// Total number of exported functions: 5 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + basic_features + ( + init => init + verify_secp256r1_signature => verify_secp256r1_signature + verify_bls_signature_share => verify_bls_signature_share + verify_bls_aggregated_signature => verify_bls_aggregated_signature + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} From 97c63ab5f81283313f99412902236d8320862a6a Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Fri, 23 Aug 2024 17:12:25 +0300 Subject: [PATCH 05/12] basic features sc-config fix --- .../basic-features/sc-config.toml | 9 +- .../basic-features/src/crypto_features.rs | 3 + .../wasm-basic-features-crypto/Cargo.lock | 186 ++++++++++++++++++ .../basic-features/wasm/src/lib.rs | 7 +- 4 files changed, 193 insertions(+), 12 deletions(-) create mode 100644 contracts/feature-tests/basic-features/wasm-basic-features-crypto/Cargo.lock diff --git a/contracts/feature-tests/basic-features/sc-config.toml b/contracts/feature-tests/basic-features/sc-config.toml index b21719850f..42c4880f67 100644 --- a/contracts/feature-tests/basic-features/sc-config.toml +++ b/contracts/feature-tests/basic-features/sc-config.toml @@ -2,7 +2,6 @@ main = "basic-features" [contracts.basic-features] -ei = "1.4" [contracts.basic-features.profile] overflow-checks = true # needed for overflow tests @@ -15,12 +14,8 @@ kill_legacy_callback = true [contracts.basic-features-crypto] ei = "1.4" add-unlabelled = false -add-endpoints = [ - "init", - "verify_secp256r1_signature", - "verify_bls_signature_share", - "verify_bls_aggregated_signature", -] +add-endpoints = ["init"] +add-labels = ["crypto-ei-1.4"] kill_legacy_callback = true [[proxy]] diff --git a/contracts/feature-tests/basic-features/src/crypto_features.rs b/contracts/feature-tests/basic-features/src/crypto_features.rs index f66479026c..4a9c7dbb6f 100644 --- a/contracts/feature-tests/basic-features/src/crypto_features.rs +++ b/contracts/feature-tests/basic-features/src/crypto_features.rs @@ -66,6 +66,7 @@ pub trait CryptoFeatures { } #[endpoint] + #[label("crypto-ei-1.4")] fn verify_secp256r1_signature( &self, key: ManagedBuffer, @@ -76,6 +77,7 @@ pub trait CryptoFeatures { } #[endpoint] + #[label("crypto-ei-1.4")] fn verify_bls_signature_share( &self, key: ManagedBuffer, @@ -87,6 +89,7 @@ pub trait CryptoFeatures { } #[endpoint] + #[label("crypto-ei-1.4")] fn verify_bls_aggregated_signature( &self, key: ManagedBuffer, diff --git a/contracts/feature-tests/basic-features/wasm-basic-features-crypto/Cargo.lock b/contracts/feature-tests/basic-features/wasm-basic-features-crypto/Cargo.lock new file mode 100644 index 0000000000..1666820785 --- /dev/null +++ b/contracts/feature-tests/basic-features/wasm-basic-features-crypto/Cargo.lock @@ -0,0 +1,186 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "basic-features" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-modules", +] + +[[package]] +name = "basic-features-crypto-wasm" +version = "0.0.0" +dependencies = [ + "basic-features", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.52.3" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-modules" +version = "0.52.3" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index 90986ec90b..887b75bcd5 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 406 +// Endpoints: 403 // Async Callback: 1 -// Total number of exported functions: 408 +// Total number of exported functions: 405 #![no_std] @@ -145,9 +145,6 @@ multiversx_sc_wasm_adapter::endpoints! { verify_secp256k1_signature => verify_secp256k1_signature verify_custom_secp256k1_signature => verify_custom_secp256k1_signature compute_secp256k1_der_signature => compute_secp256k1_der_signature - verify_secp256r1_signature => verify_secp256r1_signature - verify_bls_signature_share => verify_bls_signature_share - verify_bls_aggregated_signature => verify_bls_aggregated_signature echo_u64 => echo_u64 echo_i64 => echo_i64 echo_i32 => echo_i32 From e437447b3bd6806ad3989c2186052f5b6918393c Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 23 Aug 2024 18:52:52 +0200 Subject: [PATCH 06/12] test reorg --- .../scenarios/crypto_verify_bls.scen.json | 50 ---------- ..._verify_bls_aggregated_signature.scen.json | 71 ++++++++++++++ .../crypto_verify_bls_share.scen.json | 96 +++++++++++++++++++ .../crypto_verify_secp256r1.scen.json | 74 +++----------- .../tests/basic_features_scenario_go_test.rs | 10 ++ .../tests/basic_features_scenario_rs_test.rs | 16 ++++ 6 files changed, 205 insertions(+), 112 deletions(-) create mode 100644 contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json create mode 100644 contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json index 7b07232695..f5c6ef194c 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json @@ -41,56 +41,6 @@ "gas": "*", "refund": "*" } - }, - { - "step": "scCall", - "id": "4", - "tx": { - "from": "address:an_account", - "to": "sc:basic-features", - "function": "verify_bls_signature_share", - "arguments": [ - "0xb5823f6e564251cc03ce7bad3da83e72576e92795d3500bba1acb30ec9a94dce87bb8aa794d67b2d61d15c33f28f6c0c23ba1dfcbf21e8f8b46286ff871afabac925303ddcaddce6254fcff6d3155797db40b3d3b5865e8fc0bd770b3d79b381", - "0x6d65737361676520746f206265207369676e6564", - "0xaf32a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696" - ], - "gasLimit": "50,000,000", - "gasPrice": "0" - }, - "expect": { - "out": [ - "0x01" - ], - "status": "", - "logs": "*", - "gas": "*", - "refund": "*" - } - }, - { - "step": "scCall", - "id": "5", - "tx": { - "from": "address:an_account", - "to": "sc:basic-features", - "function": "verify_bls_aggregated_signature", - "arguments": [ - "0xb5823f6e564251cc03ce7bad3da83e72576e92795d3500bba1acb30ec9a94dce87bb8aa794d67b2d61d15c33f28f6c0c23ba1dfcbf21e8f8b46286ff871afabac925303ddcaddce6254fcff6d3155797db40b3d3b5865e8fc0bd770b3d79b381", - "0x6d65737361676520746f206265207369676e6564", - "0xaf32a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696" - ], - "gasLimit": "50,000,000", - "gasPrice": "0" - }, - "expect": { - "out": [ - "0x01" - ], - "status": "", - "logs": "*", - "gas": "*", - "refund": "*" - } } ] } \ No newline at end of file diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json new file mode 100644 index 0000000000..46617194c5 --- /dev/null +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json @@ -0,0 +1,71 @@ +{ + "name": "crypto", + "comment": "does not currently work with scenarios-rs, because verify_bls function is not yet mocked", + "gasSchedule": "v3", + "steps": [ + { + "step": "setState", + "accounts": { + "sc:basic-features-crypto": { + "nonce": "0", + "balance": "0", + "code": "mxsc:../output/basic-features-crypto.mxsc.json" + }, + "address:an_account": { + "nonce": "0", + "balance": "0" + } + } + }, + { + "step": "scCall", + "id": "1", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features-crypto", + "function": "verify_bls_aggregated_signature", + "arguments": [ + "0x9cfb3532e21737e8f9eec99b04f000b27ec277d2477d881273ea07d3af96dc3e153878ed002bcd10e8320242caab49024b8c934b437b17e743b9706757f0e7b2e9fb28295d7f82af8875e0776ae8918c25206519b3f73dcbbd53cafeb5cec716", + "0x6d65737361676530", + "0x84737000b07fbce9b649449f9de6aae76347f5bb5eefcd017f53e874601ccf5f96c9b4ca5f85ea5f6ef6243c38c9ab99" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "2", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features-crypto", + "function": "verify_bls_aggregated_signature", + "arguments": [ + "0x9cfb3532e21737e8f9eec99b04f000b27ec277d2477d881273ea07d3af96dc3e153878ed002bcd10e8320242caab49024b8c934b437b17e743b9706757f0e7b2e9fb28295d7f82af8875e0776ae8918c25206519b3f73dcbbd53cafeb5cec716", + "0x6d657373616765323133", + "0x84737000b07fbce9b649449f9de6aae76347f5bb5eefcd017f53e874601ccf5f96c9b4ca5f85ea5f6ef6243c38c9ab99" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x00" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + } + ] +} \ No newline at end of file diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json new file mode 100644 index 0000000000..046b015d86 --- /dev/null +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json @@ -0,0 +1,96 @@ +{ + "name": "crypto", + "comment": "does not currently work with scenarios-rs, because verify_bls function is not yet mocked", + "gasSchedule": "v3", + "steps": [ + { + "step": "setState", + "accounts": { + "sc:basic-features-crypto": { + "nonce": "0", + "balance": "0", + "code": "mxsc:../output/basic-features-crypto.mxsc.json" + }, + "address:an_account": { + "nonce": "0", + "balance": "0" + } + } + }, + { + "step": "scCall", + "id": "1", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features-crypto", + "function": "verify_bls_signature_share", + "arguments": [ + "0x3e886a4c6e109a151f4105aee65a5192d150ef1fa68d3cd76964a0b086006dbe4324c989deb0e4416c6d6706db1b1910eb2732f08842fb4886067b9ed191109ac2188d76002d2e11da80a3f0ea89fee6b59c834cc478a6bd49cb8a193b1abb16", + "0xe96bd0f36b70c5ccc0c4396343bd7d8255b8a526c55fa1e218511fafe6539b8e", + "0x04725db195e37aa237cdbbda76270d4a229b6e7a3651104dc58c4349c0388e8546976fe54a04240530b99064e434c90f" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "2", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features-crypto", + "function": "verify_bls_signature_share", + "arguments": [ + "0x2c9a358953f61d34401d7ee4175eec105c476b18baacab371e2f47270035b539d84ad79ba587552b7e38802be00ff7148fc2a9c7a7034ff1e63ee24602ee952235ad14ca7d36e2be617fb2c99ed22a7a2729d86ae9fbb4df06f957ba07fec50e", + "0x1e46d9cbb995e30b82485525c29f80ac78aca295a6e88a11c3df8f9a445494bb", + "0xbe8c460db180d6254c712ead3aa81935bc9be15b919dd45cb152b3dece04762569778c5e70e7af03fa1c66409d4f4711" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x00" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "2", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "verify_bls_aggregated_signature", + "arguments": [ + "0xb5823f6e564251cc03ce7bad3da83e72576e92795d3500bba1acb30ec9a94dce87bb8aa794d67b2d61d15c33f28f6c0c23ba1dfcbf21e8f8b46286ff871afabac925303ddcaddce6254fcff6d3155797db40b3d3b5865e8fc0bd770b3d79b381", + "0x6d65737361676520746f206265207369676e6564", + "0xaf32a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + } + ] +} \ No newline at end of file diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json index e87822db95..0de6016ef6 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json @@ -6,10 +6,10 @@ { "step": "setState", "accounts": { - "sc:basic-features": { + "sc:basic-features-crypto": { "nonce": "0", "balance": "0", - "code": "mxsc:../output/basic-features.mxsc.json" + "code": "mxsc:../output/basic-features-crypto.mxsc.json" }, "address:an_account": { "nonce": "0", @@ -19,15 +19,15 @@ }, { "step": "scCall", - "id": "5 - compressed key", + "id": "1", "tx": { "from": "address:an_account", - "to": "sc:basic-features", + "to": "sc:basic-features-crypto", "function": "verify_secp256r1_signature", "arguments": [ - "0x02a673638cb9587cb68ea08dbef685c6f2d2a751a8b3c6f2a7e9a4999e6e4bfaf5", - "0x6d65737361676520746f207369676e", - "0x3045022100fab29dbcb623e7e96f44665f312b89ffdb9e4d2e2f53353236fbbcf57b2f49bf02203d6f9c63df8be43121042970a549a2d3baeca093fd37b726ddcc0924638409f5" + "0x03e4d20902182b89cd5ed7984ebcf063f2fd2508d9f034e4109be487be9e2cf54d", + "0xa607fab72e13d6b625942bd5c56cc32792c2c7c7f16053b2fb6d62dd9cf36fdacf9d5a8af3537eaf5eb93335b36cf8f1d6e5bb2dfffce9055a2608d5e1a5b839eacf36dd5dec6d2fa156133acf064cc26487d543873f3b3837a3c09b5f4cb509bbc6585d", + "0xd5065c32582bf0bc8f96b34177cbf47f61d4705d64daaebff884693b6dd94afd50d3ac647aeb14d325c28bb00ab68b23280c1c480cac0e72b5a58176ac8cd1b9" ], "gasLimit": "50,000,000", "gasPrice": "0" @@ -44,14 +44,14 @@ }, { "step": "scCall", - "id": "6 - uncompressed key", + "id": "2", "tx": { "from": "address:an_account", - "to": "sc:basic-features", + "to": "sc:basic-features-crypto", "function": "verify_secp256r1_signature", "arguments": [ "0x04a673638cb9587cb68ea08dbef685c6f2d2a751a8b3c6f2a7e9a4999e6e4bfaf5ca1d22fe57c6103dbaac10cf15d15c0791cab8bb9a04f800e4d215276cb3e008", - "0x6d65737361676520746f207369676e", + "0x00", "0x3045022100fab29dbcb623e7e96f44665f312b89ffdb9e4d2e2f53353236fbbcf57b2f49bf02203d6f9c63df8be43121042970a549a2d3baeca093fd37b726ddcc0924638409f5" ], "gasLimit": "50,000,000", @@ -59,57 +59,7 @@ }, "expect": { "out": [ - "0x01" - ], - "status": "", - "logs": "*", - "gas": "*", - "refund": "*" - } - }, - { - "step": "scCall", - "id": "7 - encode key from r and s", - "tx": { - "from": "address:an_account", - "to": "sc:basic-features", - "function": "compute_secp256k1_der_signature", - "arguments": [ - "0x90f27b8b488db00b00606796d2987f6a5f59ae62ea05effe84fef5b8b0e54998", - "0x4a691139ad57a3f0b906637673aa2f63d1f55cb1a69199d4009eea23ceaddc93" - ], - "gasLimit": "50,000,000", - "gasPrice": "0" - }, - "expect": { - "out": [ - "0x304502210090f27b8b488db00b00606796d2987f6a5f59ae62ea05effe84fef5b8b0e5499802204a691139ad57a3f0b906637673aa2f63d1f55cb1a69199d4009eea23ceaddc93" - ], - "status": "", - "logs": "*", - "gas": "*", - "refund": "*" - } - }, - { - "step": "scCall", - "id": "8 - verify custom secp256k1", - "tx": { - "from": "address:an_account", - "to": "sc:basic-features", - "function": "verify_custom_secp256k1_signature", - "arguments": [ - "0x04e32df42865e97135acfb65f3bae71bdc86f4d49150ad6a440b6f15878109880a0a2b2667f7e725ceea70c673093bf67663e0312623c8e091b13cf2c0f11ef652", - "0xce0677bb30baa8cf067c88db9811f4333d131bf8bcf12fe7065d211dce971008", - "0x304502210090f27b8b488db00b00606796d2987f6a5f59ae62ea05effe84fef5b8b0e5499802204a691139ad57a3f0b906637673aa2f63d1f55cb1a69199d4009eea23ceaddc93", - "0" - ], - "gasLimit": "50,000,000", - "gasPrice": "0" - }, - "expect": { - "out": [ - "0x01" + "0x00" ], "status": "", "logs": "*", @@ -118,4 +68,4 @@ } } ] -} +} \ No newline at end of file diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs index f5a9a10726..3a7a5dc515 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs @@ -84,6 +84,16 @@ fn crypto_verify_bls_go() { world().run("scenarios/crypto_verify_bls.scen.json"); } +#[test] +fn crypto_verify_bls_share_go() { + world().run("scenarios/crypto_verify_bls_share.scen.json"); +} + +#[test] +fn crypto_verify_bls_aggregated_go() { + world().run("scenarios/crypto_verify_bls_aggregated_signature.scen.json"); +} + #[test] fn crypto_verify_ed_25519_go() { world().run("scenarios/crypto_verify_ed25519.scen.json"); diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs index 95a617e20c..2689d7f3ec 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs @@ -11,6 +11,10 @@ fn world() -> ScenarioWorld { "mxsc:../esdt-system-sc-mock/output/esdt-system-sc-mock.mxsc.json", esdt_system_sc_mock::ContractBuilder, ); + blockchain.register_contract( + "mxsc:output/basic-features-crypto.mxsc.json", + basic_features::ContractBuilder, + ); blockchain } @@ -98,6 +102,18 @@ fn crypto_verify_bls_rs() { world().run("scenarios/crypto_verify_bls.scen.json"); } +#[test] +#[ignore] +fn crypto_verify_bls_share_rs() { + world().run("scenarios/crypto_verify_bls_share.scen.json"); +} + +#[test] +#[ignore] +fn crypto_verify_bls_aggregated_rs() { + world().run("scenarios/crypto_verify_bls_aggregated_signature.scen.json"); +} + #[test] fn crypto_verify_ed_25519_rs() { world().run("scenarios/crypto_verify_ed25519.scen.json"); From e2daf814025e18ddb82d47e4eed652caf98111b8 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Tue, 27 Aug 2024 15:06:47 +0300 Subject: [PATCH 07/12] verify_bls_aggregated_signature test fix --- ..._verify_bls_aggregated_signature.scen.json | 37 ++++++++++++------- .../basic-features/src/crypto_features.rs | 2 +- .../contract_base/wrappers/crypto_wrapper.rs | 4 +- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json index 46617194c5..d8e46f2389 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json @@ -19,22 +19,28 @@ }, { "step": "scCall", - "id": "1", + "id": "bls multi - ok", "tx": { "from": "address:an_account", "to": "sc:basic-features-crypto", "function": "verify_bls_aggregated_signature", "arguments": [ - "0x9cfb3532e21737e8f9eec99b04f000b27ec277d2477d881273ea07d3af96dc3e153878ed002bcd10e8320242caab49024b8c934b437b17e743b9706757f0e7b2e9fb28295d7f82af8875e0776ae8918c25206519b3f73dcbbd53cafeb5cec716", - "0x6d65737361676530", - "0x84737000b07fbce9b649449f9de6aae76347f5bb5eefcd017f53e874601ccf5f96c9b4ca5f85ea5f6ef6243c38c9ab99" + [ + "nested:0x95f1d96b582f35294eb7dd4589b158e108e1d94cd0dd71ef16140e9b37126ec52dac6f57397f1e041acd7bb77df1d214f9f894e3b7fbf7abeaabc9fab8ff5c2ef05f9841322f301fdb900ac59479c334ac76a2d4ff992cd49bc9b530c25ee293", + "nested:0x97aa2862418eb4ea74fddcb511eef9b771e07ff901e7e6abb35847a4bb81e58f189fc9bce4186c6129014fb43002300e959702ef4b9d0c32ebe4d795457095d65b5414efb36edbb8dc66d84a445a92472d4a31cedd4700d5ebb885eb11d3430b", + "nested:0x37b73265936a2aaafe652a4dd451a1851c2dbbb32208604787479b31033e2a354615562ea2a5488f9134843362477a139050a0e798dd5ce0f01b35b8d473454ae99633aadde9237f84c87eb366144cca4de3d2cc6acc35e522a3294bf1186800", + "nested:0xf46c10d114dcd3019dd4bcd4152fda678c56144eb177c67a6411213b86e206e4e56a9aad1eab0313b13031fda046d715ec4a02612b083dfae0d82a23b643e1a89756c0df3d65c27e87a9c1289628d1a8404f0668a3d87c7451ba1c78fc452693", + "nested:0xaa0a97917df9240c537c89e873d7baa5ce1796e8fedfb23cf682b80fa19b8baae35af3754f9b8149985cb2a1fbda0f02c2942d2c99d9af556c9a5e90b8170e6a96379a45dd69351abfb814a16b5665abb7ddb8b096ee9f273de81845cda9728a" + ], + "str:message0", + "0xae12858363e8caa5b398d3febdd7bc01bc2fae1fef8f486ff4d84a5f3342f2d38085904eb10b73c0879a45d23585ce8f" ], "gasLimit": "50,000,000", "gasPrice": "0" }, "expect": { "out": [ - "0x01" + "true" ], "status": "", "logs": "*", @@ -44,24 +50,29 @@ }, { "step": "scCall", - "id": "2", + "id": "bls multi - fail", "tx": { "from": "address:an_account", "to": "sc:basic-features-crypto", "function": "verify_bls_aggregated_signature", "arguments": [ - "0x9cfb3532e21737e8f9eec99b04f000b27ec277d2477d881273ea07d3af96dc3e153878ed002bcd10e8320242caab49024b8c934b437b17e743b9706757f0e7b2e9fb28295d7f82af8875e0776ae8918c25206519b3f73dcbbd53cafeb5cec716", - "0x6d657373616765323133", - "0x84737000b07fbce9b649449f9de6aae76347f5bb5eefcd017f53e874601ccf5f96c9b4ca5f85ea5f6ef6243c38c9ab99" + [ + "nested:0x95f1d96b582f35294eb7dd4589b158e108e1d94cd0dd71ef16140e9b37126ec52dac6f57397f1e041acd7bb77df1d214f9f894e3b7fbf7abeaabc9fab8ff5c2ef05f9841322f301fdb900ac59479c334ac76a2d4ff992cd49bc9b530c25ee293", + "nested:0x97aa2862418eb4ea74fddcb511eef9b771e07ff901e7e6abb35847a4bb81e58f189fc9bce4186c6129014fb43002300e959702ef4b9d0c32ebe4d795457095d65b5414efb36edbb8dc66d84a445a92472d4a31cedd4700d5ebb885eb11d3430b", + "nested:0x37b73265936a2aaafe652a4dd451a1851c2dbbb32208604787479b31033e2a354615562ea2a5488f9134843362477a139050a0e798dd5ce0f01b35b8d473454ae99633aadde9237f84c87eb366144cca4de3d2cc6acc35e522a3294bf1186800", + "nested:0xf46c10d114dcd3019dd4bcd4152fda678c56144eb177c67a6411213b86e206e4e56a9aad1eab0313b13031fda046d715ec4a02612b083dfae0d82a23b643e1a89756c0df3d65c27e87a9c1289628d1a8404f0668a3d87c7451ba1c78fc452693", + "nested:0xaa0a97917df9240c537c89e873d7baa5ce1796e8fedfb23cf682b80fa19b8baae35af3754f9b8149985cb2a1fbda0f02c2942d2c99d9af556c9a5e90b8170e6a96379a45dd69351abfb814a16b5665abb7ddb8b096ee9f273de81845cda9728a" + ], + "str:message0", + "0x0012858363e8caa5b398d3febdd7bc01bc2fae1fef8f486ff4d84a5f3342f2d38085904eb10b73c0879a45d23585ce8f" ], "gasLimit": "50,000,000", "gasPrice": "0" }, "expect": { - "out": [ - "0x00" - ], - "status": "", + "out": [], + "status": "10", + "message": "str:err blsSignatureDeserialize 0012858363e8caa5b398d3febdd7bc01bc2fae1fef8f486ff4d84a5f3342f2d38085904eb10b73c0879a45d23585ce8f", "logs": "*", "gas": "*", "refund": "*" diff --git a/contracts/feature-tests/basic-features/src/crypto_features.rs b/contracts/feature-tests/basic-features/src/crypto_features.rs index 4a9c7dbb6f..8da0c83984 100644 --- a/contracts/feature-tests/basic-features/src/crypto_features.rs +++ b/contracts/feature-tests/basic-features/src/crypto_features.rs @@ -92,7 +92,7 @@ pub trait CryptoFeatures { #[label("crypto-ei-1.4")] fn verify_bls_aggregated_signature( &self, - key: ManagedBuffer, + key: ManagedVec, message: ManagedBuffer, signature: ManagedBuffer, ) -> bool { diff --git a/framework/base/src/contract_base/wrappers/crypto_wrapper.rs b/framework/base/src/contract_base/wrappers/crypto_wrapper.rs index 76b8fcd996..eb98f93a56 100644 --- a/framework/base/src/contract_base/wrappers/crypto_wrapper.rs +++ b/framework/base/src/contract_base/wrappers/crypto_wrapper.rs @@ -5,7 +5,7 @@ use crate::{ use_raw_handle, CryptoApi, CryptoApiImpl, StaticVarApiImpl, KECCAK256_RESULT_LEN, SHA256_RESULT_LEN, }, - types::{ManagedBuffer, ManagedByteArray, ManagedType, MessageHashType}, + types::{ManagedBuffer, ManagedByteArray, ManagedType, ManagedVec, MessageHashType}, }; #[derive(Default)] @@ -158,7 +158,7 @@ where pub fn verify_bls_aggregated_signature( &self, - key: &ManagedBuffer, + key: &ManagedVec>, message: &ManagedBuffer, signature: &ManagedBuffer, ) -> bool { From d31ffa7ecf04343ed6e913391dfabf8354f0572f Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Fri, 30 Aug 2024 11:37:13 +0300 Subject: [PATCH 08/12] crypto EI 1.4 tests ignored --- .../basic-features/tests/basic_features_scenario_go_test.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs index 3a7a5dc515..58bee7c1da 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs @@ -85,11 +85,13 @@ fn crypto_verify_bls_go() { } #[test] +#[ignore = "requires EI 1.4 in mx-scenario-go"] fn crypto_verify_bls_share_go() { world().run("scenarios/crypto_verify_bls_share.scen.json"); } #[test] +#[ignore = "requires EI 1.4 in mx-scenario-go"] fn crypto_verify_bls_aggregated_go() { world().run("scenarios/crypto_verify_bls_aggregated_signature.scen.json"); } @@ -105,6 +107,7 @@ fn crypto_verify_secp_256_k_1_go() { } #[test] +#[ignore = "requires EI 1.4 in mx-scenario-go"] fn crypto_verify_secp_256_r_1_go() { world().run("scenarios/crypto_verify_secp256r1.scen.json"); } From 4517c25151fd0c0c69ea1a49be7052d449d4e7f0 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Fri, 30 Aug 2024 17:38:57 +0300 Subject: [PATCH 09/12] crypto_verify_secp256r1 test fix --- .../crypto_verify_secp256r1.scen.json | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json index 0de6016ef6..c1287b32d9 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json @@ -19,22 +19,22 @@ }, { "step": "scCall", - "id": "1", + "id": "secp256r1 - ok", "tx": { "from": "address:an_account", "to": "sc:basic-features-crypto", "function": "verify_secp256r1_signature", "arguments": [ - "0x03e4d20902182b89cd5ed7984ebcf063f2fd2508d9f034e4109be487be9e2cf54d", - "0xa607fab72e13d6b625942bd5c56cc32792c2c7c7f16053b2fb6d62dd9cf36fdacf9d5a8af3537eaf5eb93335b36cf8f1d6e5bb2dfffce9055a2608d5e1a5b839eacf36dd5dec6d2fa156133acf064cc26487d543873f3b3837a3c09b5f4cb509bbc6585d", - "0xd5065c32582bf0bc8f96b34177cbf47f61d4705d64daaebff884693b6dd94afd50d3ac647aeb14d325c28bb00ab68b23280c1c480cac0e72b5a58176ac8cd1b9" + "0x02bc52274edebbef8878eacc4d1e0ed4fb213e5b0737389701ae8d59c403325720", + "0xbf9facf48b2219db73b50c7ff59ceef2ada56632c71afc555d6bb4072d7634d1d9353acd53517ffb9a06935a89a6454fcaa40c69becf9f8029a271fd252ea55307d00d6e97a30719d48d6b7f993af24e9c54381cba02a113238eaee9d741cababeb21aaf", + "0xc7877497444274267a4ea6f42deefde23a12e44f1ec1b437018e5c0e2834ce376dec1b81ebeacf5fbc6882e69af7cafad47bbb96cfb09e8d77d12afff7543052" ], "gasLimit": "50,000,000", "gasPrice": "0" }, "expect": { "out": [ - "0x01" + "true" ], "status": "", "logs": "*", @@ -44,24 +44,23 @@ }, { "step": "scCall", - "id": "2", + "id": "secp256r1 - fail", "tx": { "from": "address:an_account", "to": "sc:basic-features-crypto", "function": "verify_secp256r1_signature", "arguments": [ - "0x04a673638cb9587cb68ea08dbef685c6f2d2a751a8b3c6f2a7e9a4999e6e4bfaf5ca1d22fe57c6103dbaac10cf15d15c0791cab8bb9a04f800e4d215276cb3e008", - "0x00", - "0x3045022100fab29dbcb623e7e96f44665f312b89ffdb9e4d2e2f53353236fbbcf57b2f49bf02203d6f9c63df8be43121042970a549a2d3baeca093fd37b726ddcc0924638409f5" + "0x02bc52274edebbef8878eacc4d1e0ed4fb213e5b0737389701ae8d59c403325720", + "0xbf9facf48b2219db73b50c7ff59ceef2ada56632c71afc555d6bb4072d7634d1d9353acd53517ffb9a06935a89a6454fcaa40c69becf9f8029a271fd252ea55307d00d6e97a30719d48d6b7f993af24e9c54381cba02a113238eaee9d741cababeb21aaf", + "0x00877497444274267a4ea6f42deefde23a12e44f1ec1b437018e5c0e2834ce376dec1b81ebeacf5fbc6882e69af7cafad47bbb96cfb09e8d77d12afff7543052" ], "gasLimit": "50,000,000", "gasPrice": "0" }, "expect": { - "out": [ - "0x00" - ], - "status": "", + "out": [], + "status": "10", + "message": "str:signature verification failed", "logs": "*", "gas": "*", "refund": "*" From f58b4f3fbcb8f87950a9be593a0f885e32f9de2b Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Sun, 1 Sep 2024 01:55:33 +0300 Subject: [PATCH 10/12] crypto_verify_bls_share test fix --- .../crypto_verify_bls_share.scen.json | 44 ++++--------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json index 046b015d86..6aa653a9cd 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json @@ -1,6 +1,6 @@ { "name": "crypto", - "comment": "does not currently work with scenarios-rs, because verify_bls function is not yet mocked", + "comment": "does not currently work with scenarios-rs, because function is not yet mocked", "gasSchedule": "v3", "steps": [ { @@ -19,7 +19,7 @@ }, { "step": "scCall", - "id": "1", + "id": "verify_bls_signature_share - Ok", "tx": { "from": "address:an_account", "to": "sc:basic-features-crypto", @@ -44,49 +44,23 @@ }, { "step": "scCall", - "id": "2", + "id": "verify_bls_signature_share - Fail", "tx": { "from": "address:an_account", "to": "sc:basic-features-crypto", "function": "verify_bls_signature_share", "arguments": [ - "0x2c9a358953f61d34401d7ee4175eec105c476b18baacab371e2f47270035b539d84ad79ba587552b7e38802be00ff7148fc2a9c7a7034ff1e63ee24602ee952235ad14ca7d36e2be617fb2c99ed22a7a2729d86ae9fbb4df06f957ba07fec50e", - "0x1e46d9cbb995e30b82485525c29f80ac78aca295a6e88a11c3df8f9a445494bb", - "0xbe8c460db180d6254c712ead3aa81935bc9be15b919dd45cb152b3dece04762569778c5e70e7af03fa1c66409d4f4711" - ], - "gasLimit": "50,000,000", - "gasPrice": "0" - }, - "expect": { - "out": [ - "0x00" - ], - "status": "", - "logs": "*", - "gas": "*", - "refund": "*" - } - }, - { - "step": "scCall", - "id": "2", - "tx": { - "from": "address:an_account", - "to": "sc:basic-features", - "function": "verify_bls_aggregated_signature", - "arguments": [ - "0xb5823f6e564251cc03ce7bad3da83e72576e92795d3500bba1acb30ec9a94dce87bb8aa794d67b2d61d15c33f28f6c0c23ba1dfcbf21e8f8b46286ff871afabac925303ddcaddce6254fcff6d3155797db40b3d3b5865e8fc0bd770b3d79b381", - "0x6d65737361676520746f206265207369676e6564", - "0xaf32a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696" + "0x3e886a4c6e109a151f4105aee65a5192d150ef1fa68d3cd76964a0b086006dbe4324c989deb0e4416c6d6706db1b1910eb2732f08842fb4886067b9ed191109ac2188d76002d2e11da80a3f0ea89fee6b59c834cc478a6bd49cb8a193b1abb16", + "0xe96bd0f36b70c5ccc0c4396343bd7d8255b8a526c55fa1e218511fafe6539b8e", + "0xff725db195e37aa237cdbbda76270d4a229b6e7a3651104dc58c4349c0388e8546976fe54a04240530b99064e434c90f" ], "gasLimit": "50,000,000", "gasPrice": "0" }, "expect": { - "out": [ - "0x01" - ], - "status": "", + "out": [], + "status": "10", + "message": "str:err blsSignatureDeserialize ff725db195e37aa237cdbbda76270d4a229b6e7a3651104dc58c4349c0388e8546976fe54a04240530b99064e434c90f", "logs": "*", "gas": "*", "refund": "*" From d31643cc848e6e4671031da9283841e9d79fde70 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Sun, 1 Sep 2024 02:33:54 +0300 Subject: [PATCH 11/12] crypto functions that fail directly no longer return bool --- .../scenarios/crypto_verify_bls.scen.json | 32 ++++++++++++++++--- ..._verify_bls_aggregated_signature.scen.json | 6 ++-- .../crypto_verify_bls_share.scen.json | 6 ++-- .../crypto_verify_secp256r1.scen.json | 7 ++-- .../managed_decimal_logarithm.scen.json | 2 +- .../basic-features/src/crypto_features.rs | 8 ++--- framework/base/src/api/crypto_api.rs | 8 ++--- .../api/uncallable/crypto_api_uncallable.rs | 8 ++--- .../contract_base/wrappers/crypto_wrapper.rs | 25 +++++++++++---- .../src/api/core_api_vh/crypto_api_vh.rs | 8 ++--- .../wasm-adapter/src/api/crypto_api_node.rs | 24 +++++++++----- 11 files changed, 84 insertions(+), 50 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json index f5c6ef194c..fc67a3745b 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls.scen.json @@ -19,7 +19,7 @@ }, { "step": "scCall", - "id": "3", + "id": "verify_bls_signature - Ok", "tx": { "from": "address:an_account", "to": "sc:basic-features", @@ -33,14 +33,36 @@ "gasPrice": "0" }, "expect": { - "out": [ - "0x01" - ], + "out": [], "status": "", "logs": "*", "gas": "*", "refund": "*" } + }, + { + "step": "scCall", + "id": "verify_bls_signature - Fail", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "verify_bls_signature", + "arguments": [ + "0xb5823f6e564251cc03ce7bad3da83e72576e92795d3500bba1acb30ec9a94dce87bb8aa794d67b2d61d15c33f28f6c0c23ba1dfcbf21e8f8b46286ff871afabac925303ddcaddce6254fcff6d3155797db40b3d3b5865e8fc0bd770b3d79b381", + "0x6d65737361676520746f206265207369676e6564", + "0x0032a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "10", + "message": "str:err blsSignatureDeserialize 0032a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696", + "logs": "*", + "gas": "*", + "refund": "*" + } } ] -} \ No newline at end of file +} diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json index d8e46f2389..546c0d4c9f 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json @@ -39,9 +39,7 @@ "gasPrice": "0" }, "expect": { - "out": [ - "true" - ], + "out": [], "status": "", "logs": "*", "gas": "*", @@ -79,4 +77,4 @@ } } ] -} \ No newline at end of file +} diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json index 6aa653a9cd..fa7c21611b 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_bls_share.scen.json @@ -33,9 +33,7 @@ "gasPrice": "0" }, "expect": { - "out": [ - "0x01" - ], + "out": [], "status": "", "logs": "*", "gas": "*", @@ -67,4 +65,4 @@ } } ] -} \ No newline at end of file +} diff --git a/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json b/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json index c1287b32d9..1c35b46271 100644 --- a/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/crypto_verify_secp256r1.scen.json @@ -1,6 +1,5 @@ { "name": "crypto", - "comment": "", "gasSchedule": "v3", "steps": [ { @@ -33,9 +32,7 @@ "gasPrice": "0" }, "expect": { - "out": [ - "true" - ], + "out": [], "status": "", "logs": "*", "gas": "*", @@ -67,4 +64,4 @@ } } ] -} \ No newline at end of file +} diff --git a/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json b/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json index da54f8ccec..065e92988c 100644 --- a/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json @@ -24,7 +24,7 @@ "arguments": [ "23,000000000" ], - "gasLimit": "9,000,000", + "gasLimit": "25,000,000", "gasPrice": "0" }, "expect": { diff --git a/contracts/feature-tests/basic-features/src/crypto_features.rs b/contracts/feature-tests/basic-features/src/crypto_features.rs index 8da0c83984..0588146780 100644 --- a/contracts/feature-tests/basic-features/src/crypto_features.rs +++ b/contracts/feature-tests/basic-features/src/crypto_features.rs @@ -24,7 +24,7 @@ pub trait CryptoFeatures { key: ManagedBuffer, message: ManagedBuffer, signature: ManagedBuffer, - ) -> bool { + ) { self.crypto().verify_bls(&key, &message, &signature) } @@ -72,7 +72,7 @@ pub trait CryptoFeatures { key: ManagedBuffer, message: ManagedBuffer, signature: ManagedBuffer, - ) -> bool { + ) { self.crypto().verify_secp256r1(&key, &message, &signature) } @@ -83,7 +83,7 @@ pub trait CryptoFeatures { key: ManagedBuffer, message: ManagedBuffer, signature: ManagedBuffer, - ) -> bool { + ) { self.crypto() .verify_bls_signature_share(&key, &message, &signature) } @@ -95,7 +95,7 @@ pub trait CryptoFeatures { key: ManagedVec, message: ManagedBuffer, signature: ManagedBuffer, - ) -> bool { + ) { self.crypto() .verify_bls_aggregated_signature(&key, &message, &signature) } diff --git a/framework/base/src/api/crypto_api.rs b/framework/base/src/api/crypto_api.rs index 235e44919a..f6eaf80fe4 100644 --- a/framework/base/src/api/crypto_api.rs +++ b/framework/base/src/api/crypto_api.rs @@ -44,7 +44,7 @@ pub trait CryptoApiImpl: ManagedTypeApiImpl { key: Self::ManagedBufferHandle, message: Self::ManagedBufferHandle, signature: Self::ManagedBufferHandle, - ) -> bool; + ); fn verify_ed25519_managed( &self, @@ -82,19 +82,19 @@ pub trait CryptoApiImpl: ManagedTypeApiImpl { key: Self::ManagedBufferHandle, message: Self::ManagedBufferHandle, signature: Self::ManagedBufferHandle, - ) -> bool; + ); fn verify_bls_signature_share_managed( &self, key: Self::ManagedBufferHandle, message: Self::ManagedBufferHandle, signature: Self::ManagedBufferHandle, - ) -> bool; + ); fn verify_bls_aggregated_signature_managed( &self, key: Self::ManagedBufferHandle, message: Self::ManagedBufferHandle, signature: Self::ManagedBufferHandle, - ) -> bool; + ); } diff --git a/framework/base/src/api/uncallable/crypto_api_uncallable.rs b/framework/base/src/api/uncallable/crypto_api_uncallable.rs index bb42aa04bb..fe0547c5d7 100644 --- a/framework/base/src/api/uncallable/crypto_api_uncallable.rs +++ b/framework/base/src/api/uncallable/crypto_api_uncallable.rs @@ -42,7 +42,7 @@ impl CryptoApiImpl for UncallableApi { _key: Self::ManagedBufferHandle, _message: Self::ManagedBufferHandle, _signature: Self::ManagedBufferHandle, - ) -> bool { + ) { unreachable!() } @@ -88,7 +88,7 @@ impl CryptoApiImpl for UncallableApi { _key: Self::ManagedBufferHandle, _message: Self::ManagedBufferHandle, _signature: Self::ManagedBufferHandle, - ) -> bool { + ) { unreachable!() } @@ -97,7 +97,7 @@ impl CryptoApiImpl for UncallableApi { _key: Self::ManagedBufferHandle, _message: Self::ManagedBufferHandle, _signature: Self::ManagedBufferHandle, - ) -> bool { + ) { unreachable!() } @@ -106,7 +106,7 @@ impl CryptoApiImpl for UncallableApi { _key: Self::ManagedBufferHandle, _message: Self::ManagedBufferHandle, _signature: Self::ManagedBufferHandle, - ) -> bool { + ) { unreachable!() } } diff --git a/framework/base/src/contract_base/wrappers/crypto_wrapper.rs b/framework/base/src/contract_base/wrappers/crypto_wrapper.rs index eb98f93a56..369cca1a63 100644 --- a/framework/base/src/contract_base/wrappers/crypto_wrapper.rs +++ b/framework/base/src/contract_base/wrappers/crypto_wrapper.rs @@ -61,7 +61,7 @@ where key: &ManagedBuffer, message: &ManagedBuffer, signature: &ManagedBuffer, - ) -> bool { + ) { A::crypto_api_impl().verify_bls_managed( key.get_handle(), message.get_handle(), @@ -69,7 +69,9 @@ where ) } - /// Will crash if the verification fails. + /// Calls the Vm to verify ed25519 signature. + /// + /// Does not return result, will fail tx directly! /// /// The error comes straight form the VM, the message is "invalid signature". pub fn verify_ed25519( @@ -130,12 +132,15 @@ where ManagedBuffer::from_handle(new_handle) } + /// Calls the Vm to verify secp256r1 signature. + /// + /// Does not return result, will fail tx directly! pub fn verify_secp256r1( &self, key: &ManagedBuffer, message: &ManagedBuffer, signature: &ManagedBuffer, - ) -> bool { + ) { A::crypto_api_impl().verify_secp256r1_managed( key.get_handle(), message.get_handle(), @@ -143,12 +148,15 @@ where ) } + /// Calls the Vm to verify BLS signature share. + /// + /// Does not return result, will fail tx directly! pub fn verify_bls_signature_share( &self, key: &ManagedBuffer, message: &ManagedBuffer, signature: &ManagedBuffer, - ) -> bool { + ) { A::crypto_api_impl().verify_bls_signature_share_managed( key.get_handle(), message.get_handle(), @@ -156,14 +164,17 @@ where ) } + /// Calls the Vm to verify BLS aggregated signature. + /// + /// Does not return result, will fail tx directly! pub fn verify_bls_aggregated_signature( &self, - key: &ManagedVec>, + keys: &ManagedVec>, message: &ManagedBuffer, signature: &ManagedBuffer, - ) -> bool { + ) { A::crypto_api_impl().verify_bls_aggregated_signature_managed( - key.get_handle(), + keys.get_handle(), message.get_handle(), signature.get_handle(), ) diff --git a/framework/scenario/src/api/core_api_vh/crypto_api_vh.rs b/framework/scenario/src/api/core_api_vh/crypto_api_vh.rs index aa4c2dab94..305b3d6be9 100644 --- a/framework/scenario/src/api/core_api_vh/crypto_api_vh.rs +++ b/framework/scenario/src/api/core_api_vh/crypto_api_vh.rs @@ -53,7 +53,7 @@ impl CryptoApiImpl for VMHooksApi { _key: Self::ManagedBufferHandle, _message: Self::ManagedBufferHandle, _signature: Self::ManagedBufferHandle, - ) -> bool { + ) { panic!("verify_bls not implemented yet!") } @@ -105,7 +105,7 @@ impl CryptoApiImpl for VMHooksApi { _key: Self::ManagedBufferHandle, _message: Self::ManagedBufferHandle, _signature: Self::ManagedBufferHandle, - ) -> bool { + ) { panic!("verify_secp256r1 not implemented yet!") } @@ -114,7 +114,7 @@ impl CryptoApiImpl for VMHooksApi { _key: Self::ManagedBufferHandle, _message: Self::ManagedBufferHandle, _signature: Self::ManagedBufferHandle, - ) -> bool { + ) { panic!("verify_bls_signature_share not implemented yet!") } @@ -123,7 +123,7 @@ impl CryptoApiImpl for VMHooksApi { _key: Self::ManagedBufferHandle, _message: Self::ManagedBufferHandle, _signature: Self::ManagedBufferHandle, - ) -> bool { + ) { panic!("verify_bls_aggregated_signature not implemented yet!") } } diff --git a/framework/wasm-adapter/src/api/crypto_api_node.rs b/framework/wasm-adapter/src/api/crypto_api_node.rs index 0cbe24fad5..df62b30df9 100644 --- a/framework/wasm-adapter/src/api/crypto_api_node.rs +++ b/framework/wasm-adapter/src/api/crypto_api_node.rs @@ -84,8 +84,10 @@ impl CryptoApiImpl for VmApiImpl { key: Self::ManagedBufferHandle, message: Self::ManagedBufferHandle, signature: Self::ManagedBufferHandle, - ) -> bool { - unsafe { managedVerifyBLS(key, message, signature) == 0 } + ) { + unsafe { + let _ = managedVerifyBLS(key, message, signature); + } } #[inline] @@ -139,8 +141,10 @@ impl CryptoApiImpl for VmApiImpl { key: Self::ManagedBufferHandle, message: Self::ManagedBufferHandle, signature: Self::ManagedBufferHandle, - ) -> bool { - unsafe { managedVerifySecp256r1(key, message, signature) == 0 } + ) { + unsafe { + let _ = managedVerifySecp256r1(key, message, signature); + } } fn verify_bls_signature_share_managed( @@ -148,8 +152,10 @@ impl CryptoApiImpl for VmApiImpl { key: Self::ManagedBufferHandle, message: Self::ManagedBufferHandle, signature: Self::ManagedBufferHandle, - ) -> bool { - unsafe { managedVerifyBLSSignatureShare(key, message, signature) == 0 } + ) { + unsafe { + let _ = managedVerifyBLSSignatureShare(key, message, signature); + } } fn verify_bls_aggregated_signature_managed( @@ -157,7 +163,9 @@ impl CryptoApiImpl for VmApiImpl { key: Self::ManagedBufferHandle, message: Self::ManagedBufferHandle, signature: Self::ManagedBufferHandle, - ) -> bool { - unsafe { managedVerifyBLSAggregatedSignature(key, message, signature) == 0 } + ) { + unsafe { + let _ = managedVerifyBLSAggregatedSignature(key, message, signature); + } } } From 0b43a3bafeb1e8dc3447e576291a66e23e77707b Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Sun, 1 Sep 2024 02:34:06 +0300 Subject: [PATCH 12/12] scenario fmt --- .../basic-features/scenarios/managed_decimal.scen.json | 2 +- .../scenarios/managed_decimal_logarithm.scen.json | 2 +- .../scenarios/storage_mapper_get_at_address.scen.json | 2 +- .../scenarios/storage_mapper_get_at_address_extra_key.scen.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json b/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json index e19612ae29..b723c07b6d 100644 --- a/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json @@ -143,4 +143,4 @@ } } ] -} \ No newline at end of file +} diff --git a/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json b/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json index 065e92988c..193517275c 100644 --- a/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json @@ -107,4 +107,4 @@ } } ] -} \ No newline at end of file +} diff --git a/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address.scen.json b/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address.scen.json index 77ffdda1ee..2a0ff501a8 100644 --- a/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address.scen.json @@ -372,4 +372,4 @@ } } ] -} \ No newline at end of file +} diff --git a/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address_extra_key.scen.json b/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address_extra_key.scen.json index e124fd7e1a..d2802f41d2 100644 --- a/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address_extra_key.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address_extra_key.scen.json @@ -87,4 +87,4 @@ } } ] -} \ No newline at end of file +}