From c2594e3e4b1714b80149a449dd0654e671619390 Mon Sep 17 00:00:00 2001 From: loloicci Date: Tue, 28 May 2024 11:05:08 +0900 Subject: [PATCH] fix: remove the sha1-calculate API --- packages/crypto/benches/main.rs | 30 ---- packages/crypto/src/lib.rs | 3 - packages/crypto/src/sha1.rs | 26 ---- .../std/src/errors/hash_calculation_error.rs | 86 ----------- packages/std/src/errors/mod.rs | 2 - packages/std/src/errors/std_error.rs | 38 +---- packages/std/src/imports.rs | 23 --- packages/std/src/lib.rs | 2 - packages/std/src/testing/mock.rs | 6 +- packages/std/src/traits.rs | 4 +- packages/std/src/uuid.rs | 134 ------------------ packages/vm/src/environment.rs | 4 - packages/vm/src/imports.rs | 52 +------ packages/vm/src/instance.rs | 6 +- 14 files changed, 10 insertions(+), 406 deletions(-) delete mode 100644 packages/crypto/src/sha1.rs delete mode 100644 packages/std/src/errors/hash_calculation_error.rs delete mode 100644 packages/std/src/uuid.rs diff --git a/packages/crypto/benches/main.rs b/packages/crypto/benches/main.rs index b395724b6..9135759c5 100644 --- a/packages/crypto/benches/main.rs +++ b/packages/crypto/benches/main.rs @@ -13,7 +13,6 @@ use sha2::Sha256; use cosmwasm_crypto::{ ed25519_batch_verify, ed25519_verify, secp256k1_recover_pubkey, secp256k1_verify, - sha1_calculate, }; use std::cmp::min; @@ -75,8 +74,6 @@ fn read_decode_cosmos_sigs() -> (Vec>, Vec>, Vec>) { } fn bench_crypto(c: &mut Criterion) { - // same as vm::imports::MAX_LENGTH_SHA1_MESSAGE (=80) - const MAX_LENGTH_SHA1_MESSAGE: usize = 80; let mut group = c.benchmark_group("Crypto"); group.bench_function("secp256k1_verify", |b| { @@ -110,33 +107,6 @@ fn bench_crypto(c: &mut Criterion) { }); }); - group.bench_function("sha1_calculate_one", |b| { - let inputs: Vec<&[u8]> = vec![&[0; MAX_LENGTH_SHA1_MESSAGE]]; - b.iter(|| { - let hash = sha1_calculate(&inputs).unwrap(); - assert_eq!(hash.len(), 20); - }); - }); - group.bench_function("sha1_calculate_two", |b| { - let inputs: Vec<&[u8]> = vec![&[0; MAX_LENGTH_SHA1_MESSAGE], &[1; MAX_LENGTH_SHA1_MESSAGE]]; - b.iter(|| { - let hash = sha1_calculate(&inputs).unwrap(); - assert_eq!(hash.len(), 20); - }); - }); - group.bench_function("sha1_calculate_four", |b| { - let inputs: Vec<&[u8]> = vec![ - &[0; MAX_LENGTH_SHA1_MESSAGE], - &[1; MAX_LENGTH_SHA1_MESSAGE], - &[2; MAX_LENGTH_SHA1_MESSAGE], - &[3; MAX_LENGTH_SHA1_MESSAGE], - ]; - b.iter(|| { - let hash = sha1_calculate(&inputs).unwrap(); - assert_eq!(hash.len(), 20); - }); - }); - group.bench_function("ed25519_verify", |b| { let message = hex::decode(COSMOS_ED25519_MSG_HEX).unwrap(); let signature = hex::decode(COSMOS_ED25519_SIGNATURE_HEX).unwrap(); diff --git a/packages/crypto/src/lib.rs b/packages/crypto/src/lib.rs index 2bf21cbfa..97bf244c4 100644 --- a/packages/crypto/src/lib.rs +++ b/packages/crypto/src/lib.rs @@ -8,7 +8,6 @@ mod ed25519; mod errors; mod identity_digest; mod secp256k1; -mod sha1; #[doc(hidden)] pub use crate::ed25519::EDDSA_PUBKEY_LEN; @@ -20,5 +19,3 @@ pub use crate::errors::{CryptoError, CryptoResult}; pub use crate::secp256k1::{secp256k1_recover_pubkey, secp256k1_verify}; #[doc(hidden)] pub use crate::secp256k1::{ECDSA_PUBKEY_MAX_LEN, ECDSA_SIGNATURE_LEN, MESSAGE_HASH_MAX_LEN}; -#[doc(hidden)] -pub use crate::sha1::sha1_calculate; diff --git a/packages/crypto/src/sha1.rs b/packages/crypto/src/sha1.rs deleted file mode 100644 index 6dc6f2d69..000000000 --- a/packages/crypto/src/sha1.rs +++ /dev/null @@ -1,26 +0,0 @@ -use sha1::{Digest, Sha1}; - -use crate::errors::CryptoResult; - -pub fn sha1_calculate(hash_inputs: &[&[u8]]) -> CryptoResult<[u8; 20]> { - let mut hasher = Sha1::new(); - for &hash_input in hash_inputs.iter() { - hasher.update(hash_input); - } - let buffer: [u8; 20] = hasher.finalize().into(); - Ok(buffer) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_sha1_calculate() { - let input1: &str = "input_data1"; - let input2: &str = "input_data2"; - let inputs = &[input1.as_bytes(), input2.as_bytes()]; - let calc_result = sha1_calculate(inputs).unwrap(); - assert_eq!(20, calc_result.len()) - } -} diff --git a/packages/std/src/errors/hash_calculation_error.rs b/packages/std/src/errors/hash_calculation_error.rs deleted file mode 100644 index b5715aaea..000000000 --- a/packages/std/src/errors/hash_calculation_error.rs +++ /dev/null @@ -1,86 +0,0 @@ -#[cfg(feature = "backtraces")] -use std::backtrace::Backtrace; -use std::fmt::Debug; -use thiserror::Error; - -#[cfg(not(target_arch = "wasm32"))] -use cosmwasm_crypto::CryptoError; - -#[derive(Error, Debug)] -pub enum HashCalculationError { - #[error("Inputs are larger than supported")] - InputsTooLarger, - #[error("Input is longer than supported")] - InputTooLonger, - #[error("Unknown error: {error_code}")] - UnknownErr { - error_code: u32, - #[cfg(feature = "backtraces")] - backtrace: Backtrace, - }, -} - -impl HashCalculationError { - pub fn unknown_err(error_code: u32) -> Self { - HashCalculationError::UnknownErr { - error_code, - #[cfg(feature = "backtraces")] - backtrace: Backtrace::capture(), - } - } -} - -impl PartialEq for HashCalculationError { - fn eq(&self, rhs: &HashCalculationError) -> bool { - match self { - HashCalculationError::InputsTooLarger => { - matches!(rhs, HashCalculationError::InputsTooLarger) - } - HashCalculationError::InputTooLonger => { - matches!(rhs, HashCalculationError::InputTooLonger) - } - HashCalculationError::UnknownErr { error_code, .. } => { - if let HashCalculationError::UnknownErr { - error_code: rhs_error_code, - .. - } = rhs - { - error_code == rhs_error_code - } else { - false - } - } - } - } -} - -#[cfg(not(target_arch = "wasm32"))] -impl From for HashCalculationError { - fn from(original: CryptoError) -> Self { - match original { - CryptoError::InputsTooLarger { .. } => HashCalculationError::InputsTooLarger, - CryptoError::InputTooLong { .. } => HashCalculationError::InputTooLonger, - CryptoError::InvalidHashFormat { .. } - | CryptoError::InvalidPubkeyFormat { .. } - | CryptoError::InvalidSignatureFormat { .. } - | CryptoError::GenericErr { .. } - | CryptoError::InvalidRecoveryParam { .. } - | CryptoError::BatchErr { .. } => panic!("Conversion not supported"), - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - // constructors - #[test] - fn unknown_err_works() { - let error = HashCalculationError::unknown_err(123); - match error { - HashCalculationError::UnknownErr { error_code, .. } => assert_eq!(error_code, 123), - _ => panic!("wrong error type!"), - } - } -} diff --git a/packages/std/src/errors/mod.rs b/packages/std/src/errors/mod.rs index d11c5604e..bf7e61f43 100644 --- a/packages/std/src/errors/mod.rs +++ b/packages/std/src/errors/mod.rs @@ -1,10 +1,8 @@ -mod hash_calculation_error; mod recover_pubkey_error; mod std_error; mod system_error; mod verification_error; -pub use hash_calculation_error::HashCalculationError; pub use recover_pubkey_error::RecoverPubkeyError; pub use std_error::{ CheckedFromRatioError, CheckedMultiplyRatioError, ConversionOverflowError, DivideByZeroError, diff --git a/packages/std/src/errors/std_error.rs b/packages/std/src/errors/std_error.rs index ede4b87a5..fa5c27f32 100644 --- a/packages/std/src/errors/std_error.rs +++ b/packages/std/src/errors/std_error.rs @@ -3,7 +3,7 @@ use std::backtrace::Backtrace; use std::fmt; use thiserror::Error; -use crate::errors::{HashCalculationError, RecoverPubkeyError, VerificationError}; +use crate::errors::{RecoverPubkeyError, VerificationError}; /// Structured error type for init, execute and query. /// @@ -34,12 +34,6 @@ pub enum StdError { #[cfg(feature = "backtraces")] backtrace: Backtrace, }, - #[error("Hash Calculation error: {source}")] - HashCalculationError { - source: HashCalculationError, - #[cfg(feature = "backtraces")] - backtrace: Backtrace, - }, /// Whenever there is no specific error type available #[error("Generic error: {msg}")] GenericErr { @@ -133,14 +127,6 @@ impl StdError { } } - pub fn hash_calculation_err(source: HashCalculationError) -> Self { - StdError::HashCalculationError { - source, - #[cfg(feature = "backtraces")] - backtrace: Backtrace::capture(), - } - } - pub fn generic_err(msg: impl Into) -> Self { StdError::GenericErr { msg: msg.into(), @@ -261,22 +247,6 @@ impl PartialEq for StdError { false } } - StdError::HashCalculationError { - source, - #[cfg(feature = "backtraces")] - backtrace: _, - } => { - if let StdError::HashCalculationError { - source: rhs_source, - #[cfg(feature = "backtraces")] - backtrace: _, - } = rhs - { - source == rhs_source - } else { - false - } - } StdError::GenericErr { msg, #[cfg(feature = "backtraces")] @@ -487,12 +457,6 @@ impl From for StdError { } } -impl From for StdError { - fn from(source: HashCalculationError) -> Self { - Self::hash_calculation_err(source) - } -} - impl From for StdError { fn from(source: OverflowError) -> Self { Self::overflow(source) diff --git a/packages/std/src/imports.rs b/packages/std/src/imports.rs index b8b50bd05..82966bd9d 100644 --- a/packages/std/src/imports.rs +++ b/packages/std/src/imports.rs @@ -68,7 +68,6 @@ extern "C" { /// Returns 0 on verification success, 1 on verification failure, and values /// greater than 1 in case of error. fn ed25519_batch_verify(messages_ptr: u32, signatures_ptr: u32, public_keys_ptr: u32) -> u32; - fn sha1_calculate(inputs_ptr: u32) -> u64; /// Writes a debug message (UFT-8 encoded) to the host for debugging purposes. /// The host is free to log or process this in any way it considers appropriate. @@ -360,28 +359,6 @@ impl Api for ExternalApi { } } - fn sha1_calculate(&self, inputs: &[&[u8]]) -> Result<[u8; 20], HashCalculationError> { - let inputs_encoded = encode_sections(inputs); - let inputs_send = build_region(&inputs_encoded); - let inputs_send_ptr = &*inputs_send as *const Region as u32; - - let result = unsafe { sha1_calculate(inputs_send_ptr) }; - let error_code = from_high_half(result); - let hash_ptr = from_low_half(result); - match error_code { - 0 => { - let hash = unsafe { consume_region(hash_ptr as *mut Region) }; - let hash_array: [u8; 20] = hash.try_into().unwrap_or_else(|v: Vec| { - panic!("Expected a Vec of length {} but it was {}", 20, v.len()) - }); - Ok(hash_array) - } - 1 => Err(HashCalculationError::InputsTooLarger), - 2 => panic!("Error code 2 unused since CosmWasm 0.15. This is a bug in the VM."), - error_code => Err(HashCalculationError::unknown_err(error_code)), - } - } - fn debug(&self, message: &str) { // keep the boxes in scope, so we free it at the end (don't cast to pointers same line as build_region) let region = build_region(message.as_bytes()); diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 683153f4d..c1e27debf 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -24,7 +24,6 @@ mod storage; mod timestamp; mod traits; mod types; -mod uuid; pub use crate::addresses::{Addr, CanonicalAddr}; pub use crate::binary::Binary; @@ -78,7 +77,6 @@ pub use crate::storage::MemoryStorage; pub use crate::timestamp::Timestamp; pub use crate::traits::{Api, Querier, QuerierResult, QuerierWrapper, Storage}; pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, TransactionInfo}; -pub use crate::uuid::{new_uuid, Uuid}; // Exposed in wasm build only diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index 350c16927..bab393b48 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -9,7 +9,7 @@ use crate::binary::Binary; use crate::coin::Coin; use crate::deps::OwnedDeps; use crate::errors::{ - HashCalculationError, RecoverPubkeyError, StdError, StdResult, SystemError, VerificationError, + RecoverPubkeyError, StdError, StdResult, SystemError, VerificationError, }; #[cfg(feature = "stargate")] use crate::ibc::{ @@ -216,10 +216,6 @@ impl Api for MockApi { )?) } - fn sha1_calculate(&self, inputs: &[&[u8]]) -> Result<[u8; 20], HashCalculationError> { - Ok(cosmwasm_crypto::sha1_calculate(inputs)?) - } - fn debug(&self, message: &str) { println!("{}", message); } diff --git a/packages/std/src/traits.rs b/packages/std/src/traits.rs index 8097db0b5..8f9dd3a9e 100644 --- a/packages/std/src/traits.rs +++ b/packages/std/src/traits.rs @@ -6,7 +6,7 @@ use crate::addresses::{Addr, CanonicalAddr}; use crate::binary::Binary; use crate::coin::Coin; use crate::errors::{ - HashCalculationError, RecoverPubkeyError, StdError, StdResult, VerificationError, + RecoverPubkeyError, StdError, StdResult, VerificationError, }; #[cfg(feature = "iterator")] use crate::iterator::{Order, Record}; @@ -138,8 +138,6 @@ pub trait Api { public_keys: &[&[u8]], ) -> Result; - fn sha1_calculate(&self, inputs: &[&[u8]]) -> Result<[u8; 20], HashCalculationError>; - /// Emits a debugging message that is handled depending on the environment (typically printed to console or ignored). /// Those messages are not persisted to chain. fn debug(&self, message: &str); diff --git a/packages/std/src/uuid.rs b/packages/std/src/uuid.rs deleted file mode 100644 index 41798b408..000000000 --- a/packages/std/src/uuid.rs +++ /dev/null @@ -1,134 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use std::ops::Deref; -use std::str::FromStr; -use uuid as raw_uuid; - -use crate::{from_slice, to_vec}; -use crate::{Api, Env, StdResult, Storage}; - -/// Uuid Provides a Uuid that can be used deterministically. -/// Use internally Uuidv5 and NAMESPACE_OID. -/// The name is combined with cahin id, contract address, block height, and increased sequential. -#[derive( - Serialize, Deserialize, Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, JsonSchema, -)] -pub struct Uuid(#[schemars(with = "String")] raw_uuid::Uuid); -impl Uuid { - pub fn as_slice(&self) -> &[u8] { - &self.as_bytes()[0..16] - } - - // Port the new_v5 implementation of uuid to use deps.api - // https://github.com/uuid-rs/uuid/blob/2d6c147bdfca9612263dd7e82e26155f7ef8bf32/src/v5.rs#L33 - fn new_v5(api: &dyn Api, namespace: &Uuid, name: &[u8]) -> StdResult { - let inputs = [namespace.as_bytes(), name]; - let buffer = api.sha1_calculate(&inputs)?; - - let mut bytes = raw_uuid::Bytes::default(); - bytes.copy_from_slice(&buffer[..16]); - let mut builder = raw_uuid::Builder::from_bytes(bytes); - builder - .set_variant(raw_uuid::Variant::RFC4122) - .set_version(raw_uuid::Version::Sha1); - - Ok(Uuid(builder.into_uuid())) - } -} - -const CONTRACT_UUID_SEQ_NUM_KEY: &[u8] = b"contract_uuid_seq_num"; - -pub fn new_uuid(env: &Env, storage: &mut dyn Storage, api: &dyn Api) -> StdResult { - let raw_seq_num = storage.get(CONTRACT_UUID_SEQ_NUM_KEY); - let seq_num: u16 = match raw_seq_num { - Some(data) => from_slice(&data).unwrap(), - None => 0, - }; - let next_seq_num: u16 = seq_num.wrapping_add(1); - - let uuid_name = format!("{} {} {}", env.contract.address, env.block.height, seq_num); - storage.set(CONTRACT_UUID_SEQ_NUM_KEY, &(to_vec(&next_seq_num).unwrap())); - - Uuid::new_v5( - api, - &Uuid(raw_uuid::Uuid::NAMESPACE_OID), - uuid_name.as_bytes(), - ) -} - -impl Deref for Uuid { - type Target = raw_uuid::Uuid; - fn deref(&self) -> &raw_uuid::Uuid { - &self.0 - } -} - -impl FromStr for Uuid { - type Err = uuid::Error; - fn from_str(s: &str) -> Result { - let parsed = raw_uuid::Uuid::parse_str(s); - match parsed { - Ok(data) => Ok(Uuid(data)), - Err(err) => Err(err), - } - } -} - -#[cfg(test)] -mod tests { - use crate::testing::{mock_env, MockApi, MockStorage}; - use crate::{new_uuid, Uuid}; - use crate::{to_vec, Addr, Storage}; - use std::str::FromStr; - use uuid as raw_uuid; - - const CONTRACT_UUID_SEQ_NUM_KEY: &[u8] = b"contract_uuid_seq_num"; - - #[test] - fn generate_uuid_v5() { - let env = mock_env(); - let api = MockApi::default(); - let mut storage = MockStorage::new(); - - let uuid = new_uuid(&env, &mut storage, &api).unwrap(); - let uuid2 = new_uuid(&env, &mut storage, &api).unwrap(); - - assert_eq!(uuid.to_string(), "417d3461-5f6c-584b-8035-482a70997aee"); - assert_eq!(uuid.get_variant(), uuid::Variant::RFC4122); - assert_eq!(uuid.get_version(), Some(uuid::Version::Sha1)); - let parsed_uuid = Uuid::from_str("417d3461-5f6c-584b-8035-482a70997aee"); - assert_eq!(uuid, parsed_uuid.unwrap()); - - assert_eq!(uuid2.to_string(), "61b5574c-d3e4-5d06-8a87-ab28a7353dfd"); - assert_ne!(uuid, uuid2); - } - - #[test] - fn same_output_as_raw_uuid() { - let env = mock_env(); - let api = MockApi::default(); - let mut storage = MockStorage::new(); - let our_uuid = new_uuid(&env, &mut storage, &api).unwrap(); - - let uuid_name = format!("{} {} {}", env.contract.address, env.block.height, 0); - let raw = raw_uuid::Uuid::new_v5(&raw_uuid::Uuid::NAMESPACE_OID, uuid_name.as_bytes()); - - assert_eq!(our_uuid.to_string(), raw.to_string()); - } - - #[test] - fn work_fine_as_longest_name() { - let mut env = mock_env(); - let api = MockApi::default(); - let mut storage = MockStorage::new(); - - //enforce the max value - env.contract.address = Addr::unchecked("link1qyqszqgpqyqszqgpqyqszqgpqyqszqgp8apuk5"); - env.block.height = u64::MAX; - let stor: &mut dyn Storage = &mut storage; - stor.set(CONTRACT_UUID_SEQ_NUM_KEY, &(to_vec(&u16::MAX).unwrap())); - - let uuid = new_uuid(&env, &mut storage, &api); - assert!(uuid.is_ok()); - } -} diff --git a/packages/vm/src/environment.rs b/packages/vm/src/environment.rs index aa2cae848..d9e0b8000 100644 --- a/packages/vm/src/environment.rs +++ b/packages/vm/src/environment.rs @@ -29,15 +29,12 @@ pub struct GasConfig { pub ed25519_batch_verify_cost: u64, /// ed25519 batch signature verification cost (single public key) pub ed25519_batch_verify_one_pubkey_cost: u64, - /// sha1 hash calculation cost (single input) - pub sha1_calculate_cost: u64, } impl Default for GasConfig { fn default() -> Self { // Target is 10^12 per millisecond (see GAS.md), i.e. 10^9 gas per ยต second. const GAS_PER_US: u64 = 1_000_000_000; - const GAS_PER_NS: u64 = 1_000_000; Self { // ~154 us in crypto benchmarks secp256k1_verify_cost: 154 * GAS_PER_US, @@ -49,7 +46,6 @@ impl Default for GasConfig { // From https://docs.rs/ed25519-zebra/2.2.0/ed25519_zebra/batch/index.html ed25519_batch_verify_cost: 63 * GAS_PER_US / 2, ed25519_batch_verify_one_pubkey_cost: 63 * GAS_PER_US / 4, - sha1_calculate_cost: 269 * GAS_PER_NS, } } } diff --git a/packages/vm/src/imports.rs b/packages/vm/src/imports.rs index a0d60f145..60b4c5737 100644 --- a/packages/vm/src/imports.rs +++ b/packages/vm/src/imports.rs @@ -3,8 +3,7 @@ use std::cmp::max; use cosmwasm_crypto::{ - ed25519_batch_verify, ed25519_verify, secp256k1_recover_pubkey, secp256k1_verify, - sha1_calculate, CryptoError, + ed25519_batch_verify, ed25519_verify, secp256k1_recover_pubkey, secp256k1_verify, CryptoError, }; use cosmwasm_crypto::{ ECDSA_PUBKEY_MAX_LEN, ECDSA_SIGNATURE_LEN, EDDSA_PUBKEY_LEN, MESSAGE_HASH_MAX_LEN, @@ -51,15 +50,6 @@ const MAX_LENGTH_ED25519_MESSAGE: usize = 128 * 1024; /// This is an arbitrary value, for performance / memory contraints. If you need to batch-verify a /// larger number of signatures, let us know. const MAX_COUNT_ED25519_BATCH: usize = 256; -/// Max count of a inputs for sha1. -/// A limit is set to prevent malicious excessive input. -/// Now, we limit ourselves to only small sizes for use cases in Uuid. -pub const MAX_COUNT_SHA1_INPUT: usize = 4; -/// Max length of a input for sha1 -/// After executing the crypto bench according to this, -/// the gas factor is determined based on the result. -/// If you modify this value, you need to adjust the gas factor. -pub const MAX_LENGTH_SHA1_MESSAGE: usize = 80; /// Max length for a debug message const MAX_LENGTH_DEBUG: usize = 2 * MI; @@ -362,43 +352,11 @@ pub fn do_ed25519_batch_verify( } pub fn do_sha1_calculate( - env: &Environment, - hash_inputs_ptr: u32, + _env: &Environment, + _hash_inputs_ptr: u32, ) -> VmResult { - let hash_inputs = read_region( - &env.memory(), - hash_inputs_ptr, - (MAX_LENGTH_SHA1_MESSAGE + 4) * MAX_COUNT_SHA1_INPUT, - )?; - - let hash_inputs = decode_sections(&hash_inputs); - let result = sha1_calculate(&hash_inputs); - let mut gas_cost = env.gas_config.sha1_calculate_cost; - //For sha1, the execution time does not increase linearly by the number of updates(count of inputs). - if hash_inputs.len() > 1 { - gas_cost += (env.gas_config.sha1_calculate_cost * (hash_inputs.len() - 1) as u64) / 2; - } - let gas_info = GasInfo::with_cost(gas_cost); - process_gas_info::(env, gas_info)?; - match result { - Ok(hash) => { - let hash_ptr = write_to_contract::(env, &hash)?; - Ok(to_low_half(hash_ptr)) - } - Err(err) => match err { - CryptoError::InputsTooLarger { .. } | CryptoError::InputTooLong { .. } => { - Ok(to_high_half(err.code())) - } - CryptoError::BatchErr { .. } - | CryptoError::InvalidPubkeyFormat { .. } - | CryptoError::InvalidSignatureFormat { .. } - | CryptoError::GenericErr { .. } - | CryptoError::InvalidHashFormat { .. } - | CryptoError::InvalidRecoveryParam { .. } => { - panic!("Error must not happen for this call") - } - }, - } + // error code for generic error + Ok(to_high_half(10)) } /// Prints a debug message to console. diff --git a/packages/vm/src/instance.rs b/packages/vm/src/instance.rs index 7656cf02d..093d2d2e9 100644 --- a/packages/vm/src/instance.rs +++ b/packages/vm/src/instance.rs @@ -172,10 +172,8 @@ where Function::new_native_with_env(store, env.clone(), do_ed25519_batch_verify), ); - // Calculates the inputs using the sha1 - // Returns 0 if inputs are some invalid and pointer to result region otherwise. - // Ownership of the inputs pointer is not transferred to the host. - // Ownership of the hash pointer is transferred to the contract. + // No longer supported + // This function only returns an error to wasm. env_imports.insert( "sha1_calculate", Function::new_native_with_env(store, env.clone(), do_sha1_calculate),