From 461c1532cdd5c05b2a881fb97021a1e96ae5b369 Mon Sep 17 00:00:00 2001 From: shaorongqiang Date: Thu, 15 Dec 2022 10:12:10 +0800 Subject: [PATCH 1/3] update EVM_FIRST_BLOCK_HEIGHT to checkpoint (#743) --- src/components/contracts/rpc/src/eth.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/contracts/rpc/src/eth.rs b/src/components/contracts/rpc/src/eth.rs index 7ae9688f46..5f572cb1b3 100644 --- a/src/components/contracts/rpc/src/eth.rs +++ b/src/components/contracts/rpc/src/eth.rs @@ -5,6 +5,7 @@ use crate::utils::{ }; use crate::{error_on_execution_failure, internal_err}; use baseapp::{extensions::SignedExtra, BaseApp}; +use config::abci::global_cfg::CFG; use ethereum::{ BlockV0 as EthereumBlock, LegacyTransactionMessage as EthereumTransactionMessage, TransactionV0 as EthereumTransaction, @@ -572,7 +573,7 @@ impl EthApi for EthApiImpl { let task = spawn_blocking(move || -> Result> { if let Some(h) = height { - if 0 < h && h < *EVM_FIRST_BLOCK_HEIGHT { + if 0 < h && h < CFG.checkpoint.evm_first_block_height as u64 { return Ok(Some(dummy_block(h, full))); } } From 5b140212112206caae3ba467daa0b5741e6c3bb2 Mon Sep 17 00:00:00 2001 From: kevinssgh <79858682+kevinssgh@users.noreply.github.com> Date: Wed, 14 Dec 2022 22:48:55 -0500 Subject: [PATCH 2/3] Gas calculation of EIP-1962 (#759) * added gas calculation and updated unit test * Empty-Commit * Apply suggestions from code review Co-authored-by: onewayfunc Co-authored-by: Weikeng Chen --- .../evm/precompile/eth-pairings/src/lib.rs | 23 +++++++++++++++---- .../evm/precompile/eth-pairings/src/tests.rs | 13 +++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/components/contracts/modules/evm/precompile/eth-pairings/src/lib.rs b/src/components/contracts/modules/evm/precompile/eth-pairings/src/lib.rs index b81f1428ea..470fec3c31 100644 --- a/src/components/contracts/modules/evm/precompile/eth-pairings/src/lib.rs +++ b/src/components/contracts/modules/evm/precompile/eth-pairings/src/lib.rs @@ -8,8 +8,6 @@ use evm_precompile_utils::{EvmDataReader, EvmDataWriter, EvmResult, Gasometer}; use module_evm::precompile::{FinState, Precompile, PrecompileId, PrecompileResult}; use tracing::debug; -const GAS_EXECUTION: u64 = 3437; - /// The Verifier precompile. pub struct EthPairing; @@ -50,20 +48,35 @@ impl Precompile for EthPairing { } impl EthPairing { - fn call_public_api_on_vector(data: &[u8]) -> Result, ApiError> { + fn get_operation(data: &[u8]) -> Result<(OperationType, &[u8]), ApiError> { if data.is_empty() { return Err(ApiError::InputError("input is zero length".to_owned())); } let op = OperationType::from_u8(data[0]).ok_or(ApiError::MissingValue)?; - perform_operation(op, &data[0..]) + Ok((op, &data[1..])) + } + + fn call_public_api_on_vector(data: &[u8]) -> Result, ApiError> { + let (op, input) = Self::get_operation(data)?; + perform_operation(op, input) + } + + fn calculate_gas_for_operation(data: &[u8]) -> Result { + let (op, input) = Self::get_operation(data)?; + eth_pairings::gas_meter::meter_operation(op, input) } fn execute_operation( mut input: EvmDataReader, target_gas: Option, ) -> EvmResult { + // Calculate and record required gas for operation let mut gasometer = Gasometer::new(target_gas); - gasometer.record_cost(GAS_EXECUTION)?; + let gas = match Self::calculate_gas_for_operation(input.get_slice()) { + Ok(res) => res, + Err(api_err) => return Err(ExitError::Other(api_err.to_string().into())), + }; + gasometer.record_cost(gas)?; debug!(target: "evm", "EthPairing#executingOp"); let result = match Self::call_public_api_on_vector(input.get_slice()) { diff --git a/src/components/contracts/modules/evm/precompile/eth-pairings/src/tests.rs b/src/components/contracts/modules/evm/precompile/eth-pairings/src/tests.rs index 5f358e327d..2ff06a41d6 100644 --- a/src/components/contracts/modules/evm/precompile/eth-pairings/src/tests.rs +++ b/src/components/contracts/modules/evm/precompile/eth-pairings/src/tests.rs @@ -4,12 +4,12 @@ use fp_mocks::*; // Test from eth-pairings (eip1962) repository https://github.com/FindoraNetwork/eip1962 #[test] -fn test_g1_mul() { +fn test_bls12_pairing() { use hex; - let hex_string = "02820d8080001026e1318f230000000000000080be6dc885e544bee65620747e191023316695af6989f85b230000000000044eccc6886286fbaee7561d483d50d89e9e9e95af2989f85b230000000000044eccc688628631"; + let hex_string = "07202912811758d871b77a9c3635c28570dc020576f9fc2719d8d0494439162b2b89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011603e65409b693c8a08aeb3478d10aa3732a6672ba06d12912811758d871b77a9c3635c28570dc020576f9fc2719d8d0494439162b2b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010206059efde42f3701020127ccb2831f0011c1d547c491b9dffbd4cfdb87598a4b370f5873ea62094a2f201faa6cb7f6fcca66de3f308a25776dac3f61edb792948fbe53e4d18a3d8aefbe011a7e9f75f3fdc77b83a97f7acd58326a0545f8aa37b69bfb32c52dc195763e8c17176e0ad4ee94d9c720e922d42688127c4b812cd7c2f8cf6126acd4c3d7568121e48b3fefe66c279f2ec71f0d6f8156a3343d1cfa54b808d747cd02419278290ad2d7d03f5de1e7b3c97732f53dbe1dfd42e51f9571f7fee3d9c1785d5a1ed6010b4f7f211a0a5f4425728e2df580196d3e3b85ef148ed769acd23e9be6e8440726cb40655787f48eaf46154cb740e2a58db5b96fa02d83fb9d0f94320da1471e0104ece4c46ac4f05a7c28ecda84292f15999747bb77c530c65448f1f837a47dd70e972c4065d0b39d40b5d550a55901516afa7f02b395963d1535fcba1705e31a117cb4beab1dc582198c4ab0c02e96a22f7bd10dde3bbbdbc9182a9596cb0ed32121616b692e8036437efb4c3816f018f11e643c6e0a049da431986a3a722b06"; let data = hex::decode(hex_string).unwrap(); - assert!(EthPairing::execute( + let output = EthPairing::execute( &EvmDataWriter::new() .write_selector(Call::ExecuteOperation) .write_raw_bytes(&data) @@ -21,6 +21,9 @@ fn test_g1_mul() { apparent_value: From::from(0), }, &BASE_APP.lock().unwrap().deliver_state, - ) - .is_ok()); + ); + + assert!(output.is_ok()); + assert_eq!(output.as_ref().unwrap().cost, 164986); + assert_eq!(output.unwrap().output, vec![0x1]); } From 9c727a6294c6cb60069a126e8995e4c5f799fe77 Mon Sep 17 00:00:00 2001 From: kevinssgh <79858682+kevinssgh@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:45:45 -0500 Subject: [PATCH 3/3] Fix errors after clippy updatd (#766) --- .../abciapp/src/abci/staking/test.rs | 2 +- .../api/query_server/query_api/ledger_api.rs | 2 +- .../contracts/baseapp/src/tm_events.rs | 2 +- .../modules/evm/tests/utils/solidity.rs | 6 ++--- .../contracts/primitives/mocks/src/lib.rs | 2 +- .../contracts/primitives/types/src/crypto.rs | 11 ++++---- .../contracts/primitives/utils/src/ecdsa.rs | 4 +-- .../contracts/primitives/utils/src/lib.rs | 2 +- .../contracts/primitives/wasm/src/wasm.rs | 8 +++--- .../contracts/rpc/src/eth_pubsub.rs | 6 ++--- src/components/contracts/rpc/src/web3.rs | 2 +- .../finutils/src/bins/stt/init/i_testing.rs | 2 +- src/components/finutils/src/common/utils.rs | 26 +++++++++---------- .../finutils/src/txn_builder/mod.rs | 2 +- .../wallet_mobile/src/rust/account.rs | 2 +- src/ledger/src/data_model/test.rs | 2 +- src/ledger/src/staking/cosig.rs | 4 +-- src/ledger/src/staking/mod.rs | 2 +- src/ledger/src/store/api_cache.rs | 4 +-- src/ledger/src/store/mod.rs | 2 +- src/libs/bitmap/src/lib.rs | 4 +-- src/libs/globutils/src/wallet.rs | 12 ++++----- src/libs/merkle_tree/src/lib.rs | 4 +-- src/libs/sliding_set/src/lib.rs | 2 +- 24 files changed, 56 insertions(+), 59 deletions(-) diff --git a/src/components/abciapp/src/abci/staking/test.rs b/src/components/abciapp/src/abci/staking/test.rs index 41c414aba8..922707e4d7 100644 --- a/src/components/abciapp/src/abci/staking/test.rs +++ b/src/components/abciapp/src/abci/staking/test.rs @@ -65,7 +65,7 @@ fn check_block_rewards_rate() -> Result<()> { { let rate = ledger.staking_get_block_rewards_rate(); - let rate = [rate[0] as u128, rate[1] as u128]; + let rate = [rate[0], rate[1]]; // max value: 105% assert!(rate[0] * 100 <= rate[1] * 105); // min value: 2% diff --git a/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs b/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs index 0c41ca00bf..399bb577ae 100644 --- a/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs +++ b/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs @@ -254,7 +254,7 @@ pub async fn query_validators( }) .collect(); return Ok(web::Json(ValidatorList::new( - staking.cur_height() as u64, + staking.cur_height(), validators_list, ))); }; diff --git a/src/components/contracts/baseapp/src/tm_events.rs b/src/components/contracts/baseapp/src/tm_events.rs index 3790ee084b..d32a344402 100644 --- a/src/components/contracts/baseapp/src/tm_events.rs +++ b/src/components/contracts/baseapp/src/tm_events.rs @@ -50,7 +50,7 @@ fn get_pending_hash() -> Result, attohttpc::Error> { }) .map(|json_resp| { for tx in json_resp.result.txs { - base64::decode(&tx) + base64::decode(tx) .map(|bytes| { let hasher = sha2_256(&bytes); pending_hash.push(H256::from_slice(&hasher)) diff --git a/src/components/contracts/modules/evm/tests/utils/solidity.rs b/src/components/contracts/modules/evm/tests/utils/solidity.rs index 17ea27a179..6fda0f06f1 100644 --- a/src/components/contracts/modules/evm/tests/utils/solidity.rs +++ b/src/components/contracts/modules/evm/tests/utils/solidity.rs @@ -30,7 +30,7 @@ impl ContractConstructor { { let bin_file = format!("{}.bin", contract_name); let abi_file = format!("{}.abi", contract_name); - let hex_path = artifacts_base_path.as_ref().join(&bin_file); + let hex_path = artifacts_base_path.as_ref().join(bin_file); let hex_rep = match std::fs::read_to_string(&hex_path) { Ok(hex) => hex, Err(_) => { @@ -40,8 +40,8 @@ impl ContractConstructor { std::fs::read_to_string(hex_path).unwrap() } }; - let code = hex::decode(&hex_rep).unwrap(); - let abi_path = artifacts_base_path.as_ref().join(&abi_file); + let code = hex::decode(hex_rep).unwrap(); + let abi_path = artifacts_base_path.as_ref().join(abi_file); let reader = std::fs::File::open(abi_path).unwrap(); let abi = ethabi::Contract::load(reader).unwrap(); diff --git a/src/components/contracts/primitives/mocks/src/lib.rs b/src/components/contracts/primitives/mocks/src/lib.rs index a190a41928..f88cac0081 100644 --- a/src/components/contracts/primitives/mocks/src/lib.rs +++ b/src/components/contracts/primitives/mocks/src/lib.rs @@ -90,7 +90,7 @@ pub struct KeyPair { } pub fn generate_address(seed: u8) -> KeyPair { - let private_key = H256::from_slice(&[(seed + 1) as u8; 32]); + let private_key = H256::from_slice(&[(seed + 1); 32]); let secret_key = libsecp256k1::SecretKey::parse_slice(&private_key[..]).unwrap(); let public_key = &libsecp256k1::PublicKey::from_secret_key(&secret_key).serialize()[1..65]; diff --git a/src/components/contracts/primitives/types/src/crypto.rs b/src/components/contracts/primitives/types/src/crypto.rs index 65e919df6e..996c734de2 100644 --- a/src/components/contracts/primitives/types/src/crypto.rs +++ b/src/components/contracts/primitives/types/src/crypto.rs @@ -450,11 +450,12 @@ impl Verify for XfrSignature { pub fn secp256k1_ecdsa_recover(sig: &[u8; 65], msg: &[u8; 32]) -> ruc::Result<[u8; 64]> { let rs = libsecp256k1::Signature::parse_standard_slice(&sig[0..64]) .map_err(|_| eg!("Ecdsa signature verify error: bad RS"))?; - let v = - libsecp256k1::RecoveryId::parse( - if sig[64] > 26 { sig[64] - 27 } else { sig[64] } as u8, - ) - .map_err(|_| eg!("Ecdsa signature verify error: bad V"))?; + let v = libsecp256k1::RecoveryId::parse(if sig[64] > 26 { + sig[64] - 27 + } else { + sig[64] + }) + .map_err(|_| eg!("Ecdsa signature verify error: bad V"))?; let pubkey = libsecp256k1::recover(&libsecp256k1::Message::parse(msg), &rs, &v) .map_err(|_| eg!("Ecdsa signature verify error: bad signature"))?; let mut res = [0u8; 64]; diff --git a/src/components/contracts/primitives/utils/src/ecdsa.rs b/src/components/contracts/primitives/utils/src/ecdsa.rs index 09904c1c84..4e71af6244 100644 --- a/src/components/contracts/primitives/utils/src/ecdsa.rs +++ b/src/components/contracts/primitives/utils/src/ecdsa.rs @@ -72,7 +72,7 @@ impl<'de> Deserialize<'de> for Public { D: Deserializer<'de>, { let pk = - base64::decode_config(&String::deserialize(deserializer)?, base64::URL_SAFE) + base64::decode_config(String::deserialize(deserializer)?, base64::URL_SAFE) .map_err(|e| de::Error::custom(format!("{:?}", e)))?; Public::try_from(pk.as_slice()) .map_err(|e| de::Error::custom(format!("{:?}", e))) @@ -173,7 +173,7 @@ impl<'de> Deserialize<'de> for Signature { where D: Deserializer<'de>, { - let signature_hex = hex::decode(&String::deserialize(deserializer)?) + let signature_hex = hex::decode(String::deserialize(deserializer)?) .map_err(|e| de::Error::custom(format!("{:?}", e)))?; Signature::try_from(signature_hex.as_ref()) .map_err(|e| de::Error::custom(format!("{:?}", e))) diff --git a/src/components/contracts/primitives/utils/src/lib.rs b/src/components/contracts/primitives/utils/src/lib.rs index 5b3a129831..cd8b159932 100644 --- a/src/components/contracts/primitives/utils/src/lib.rs +++ b/src/components/contracts/primitives/utils/src/lib.rs @@ -10,7 +10,7 @@ use primitive_types::H160; pub fn timestamp_converter(timestamp: protobuf::well_known_types::Timestamp) -> u64 { let unix_time = core::time::Duration::new(timestamp.seconds as u64, timestamp.nanos as u32); - unix_time.as_secs() as u64 + unix_time.as_secs() } pub fn proposer_converter(address: Vec) -> Option { diff --git a/src/components/contracts/primitives/wasm/src/wasm.rs b/src/components/contracts/primitives/wasm/src/wasm.rs index f58ce5eec2..f587e244c4 100644 --- a/src/components/contracts/primitives/wasm/src/wasm.rs +++ b/src/components/contracts/primitives/wasm/src/wasm.rs @@ -35,7 +35,7 @@ pub fn recover_signer(transaction: &Transaction) -> Option { #[wasm_bindgen] pub fn recover_tx_signer(raw_tx: String) -> Result { - let tx_bytes = base64::decode_config(&raw_tx, base64::URL_SAFE) + let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE) .c(d!()) .map_err(error_to_jsvalue)?; let raw_tx = EvmRawTxWrapper::unwrap(&tx_bytes) @@ -55,7 +55,7 @@ pub fn recover_tx_signer(raw_tx: String) -> Result { #[wasm_bindgen] pub fn evm_tx_hash(raw_tx: String) -> Result { - let tx_bytes = base64::decode_config(&raw_tx, base64::URL_SAFE) + let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE) .c(d!()) .map_err(error_to_jsvalue)?; let raw_tx = EvmRawTxWrapper::unwrap(&tx_bytes) @@ -82,7 +82,7 @@ mod test { #[test] fn recover_signer_works() { let raw_tx = String::from("ZXZtOnsic2lnbmF0dXJlIjpudWxsLCJmdW5jdGlvbiI6eyJFdGhlcmV1bSI6eyJUcmFuc2FjdCI6eyJub25jZSI6IjB4MSIsImdhc19wcmljZSI6IjB4MTc0ODc2ZTgwMCIsImdhc19saW1pdCI6IjB4NTIwOCIsImFjdGlvbiI6eyJDYWxsIjoiMHgyYWQzMjg0NmM2ZGQyZmZkM2VkYWRiZTUxY2Q1YWUwNGFhNWU1NzVlIn0sInZhbHVlIjoiMHg1NmJjNzVlMmQ2MzEwMDAwMCIsImlucHV0IjpbXSwic2lnbmF0dXJlIjp7InYiOjEwODIsInIiOiIweGY4YWVmN2Y4MDUzZDg5ZmVlMzk1MGM0ZDcwMjA4MGJmM2E4MDcyYmVkNWQ4NGEzYWYxOWEzNjAwODFiNjM2YTIiLCJzIjoiMHgyOTYyOTlhOGYyNDMwYjg2ZmQzZWI5NzZlYWJjNzMwYWMxY2ZiYmJlMzZlYjY5ZWFlMzM4Y2ZmMzNjNGE5OGMxIn19fX19"); - let tx_bytes = base64::decode_config(&raw_tx, base64::URL_SAFE).unwrap(); + let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE).unwrap(); let evm_tx = EvmRawTxWrapper::unwrap(&tx_bytes).unwrap(); let unchecked_tx: UncheckedTransaction<()> = serde_json::from_slice(evm_tx).unwrap(); @@ -100,7 +100,7 @@ mod test { #[test] fn evm_tx_hash_works() { let raw_tx = String::from("eyJzaWduYXR1cmUiOm51bGwsImZ1bmN0aW9uIjp7IkV0aGVyZXVtIjp7IlRyYW5zYWN0Ijp7Im5vbmNlIjoiMHg5IiwiZ2FzX3ByaWNlIjoiMHhlOGQ0YTUxMDAwIiwiZ2FzX2xpbWl0IjoiMHg1MjA4IiwiYWN0aW9uIjp7IkNhbGwiOiIweGE1MjI1Y2JlZTUwNTIxMDBlYzJkMmQ5NGFhNmQyNTg1NTgwNzM3NTcifSwidmFsdWUiOiIweDk4YTdkOWI4MzE0YzAwMDAiLCJpbnB1dCI6W10sInNpZ25hdHVyZSI6eyJ2IjoxMDgyLCJyIjoiMHg4MDBjZjQ5ZTAzMmJhYzY4MjY3MzdhZGJhZDEzN2Y0MTk5OTRjNjgxZWE1ZDUyYjliMGJhZDJmNDAyYjMwMTI0IiwicyI6IjB4Mjk1Mjc3ZWY2NTYzNDAwY2VkNjFiODhkM2ZiNGM3YjMyY2NkNTcwYThiOWJiOGNiYmUyNTkyMTRhYjdkZTI1YSJ9fX19fQ=="); - let tx_bytes = base64::decode_config(&raw_tx, base64::URL_SAFE).unwrap(); + let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE).unwrap(); let unchecked_tx: UncheckedTransaction<()> = serde_json::from_slice(tx_bytes.as_slice()).unwrap(); if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { diff --git a/src/components/contracts/rpc/src/eth_pubsub.rs b/src/components/contracts/rpc/src/eth_pubsub.rs index 7587a1031e..21efe31663 100644 --- a/src/components/contracts/rpc/src/eth_pubsub.rs +++ b/src/components/contracts/rpc/src/eth_pubsub.rs @@ -255,10 +255,8 @@ impl SubscriptionResult { for (receipt_index, receipt) in receipts.into_iter().enumerate() { let transaction_hash: Option = if !receipt.logs.is_empty() { Some(H256::from_slice( - Keccak256::digest(&rlp::encode( - &block.transactions[receipt_index as usize], - )) - .as_slice(), + Keccak256::digest(&rlp::encode(&block.transactions[receipt_index])) + .as_slice(), )) } else { None diff --git a/src/components/contracts/rpc/src/web3.rs b/src/components/contracts/rpc/src/web3.rs index 40237395d8..3cba4b8ff8 100644 --- a/src/components/contracts/rpc/src/web3.rs +++ b/src/components/contracts/rpc/src/web3.rs @@ -31,7 +31,7 @@ impl Web3Api for Web3ApiImpl { fn sha3(&self, input: Bytes) -> Result { Ok(H256::from_slice( - Keccak256::digest(&input.into_vec()).as_slice(), + Keccak256::digest(input.into_vec()).as_slice(), )) } } diff --git a/src/components/finutils/src/bins/stt/init/i_testing.rs b/src/components/finutils/src/bins/stt/init/i_testing.rs index 0adf1a9338..909fdc10af 100644 --- a/src/components/finutils/src/bins/stt/init/i_testing.rs +++ b/src/components/finutils/src/bins/stt/init/i_testing.rs @@ -395,7 +395,7 @@ struct TmValidator { fn get_26657_validators(sa: &str) -> Result { let url = format!("{}:26657/validators", sa); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() diff --git a/src/components/finutils/src/common/utils.rs b/src/components/finutils/src/common/utils.rs index 50d54ddd35..ef89aae623 100644 --- a/src/components/finutils/src/common/utils.rs +++ b/src/components/finutils/src/common/utils.rs @@ -52,7 +52,7 @@ pub fn send_tx(tx: &Transaction) -> Result<()> { let tx_bytes = serde_json::to_vec(tx).c(d!())?; - let _ = attohttpc::post(&url) + let _ = attohttpc::post(url) .header(attohttpc::header::CONTENT_TYPE, "application/json") .bytes(&tx_bytes) .send() @@ -484,7 +484,7 @@ struct TmStatus { fn get_network_status(addr: &str) -> Result { let url = format!("{}:26657/status", addr); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -515,7 +515,7 @@ pub fn get_local_block_height() -> u64 { pub fn get_asset_type(code: &str) -> Result { let url = format!("{}:8668/asset_token/{}", get_serv_addr().c(d!())?, code); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -533,7 +533,7 @@ pub fn get_created_assets(addr: &XfrPublicKey) -> Result> { wallet::public_key_to_base64(addr) ); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -587,7 +587,7 @@ fn get_owned_utxos_x( wallet::public_key_to_base64(addr) ); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -608,7 +608,7 @@ pub fn get_owned_abar(com: &Commitment) -> Result<(ATxoSID, AnonAssetRecord)> { wallet::commitment_to_base58(com) ); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -637,7 +637,7 @@ fn get_seq_id() -> Result { let url = format!("{}:8668/global_state", get_serv_addr().c(d!())?); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -662,7 +662,7 @@ pub fn get_owner_memo_batch(ids: &[TxoSID]) -> Result>> { ids ); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -678,7 +678,7 @@ pub fn get_abar_memo(id: &ATxoSID) -> Result> { let id = id.0.to_string(); let url = format!("{}:8667/get_abar_memo/{}", get_serv_addr().c(d!())?, id); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -698,7 +698,7 @@ pub fn get_abar_proof(atxo_sid: &ATxoSID) -> Result> { atxo_sid ); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -717,7 +717,7 @@ pub fn check_nullifier_hash(null_hash: &str) -> Result> { null_hash ); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -735,7 +735,7 @@ pub fn get_delegation_info(pk: &XfrPublicKey) -> Result { wallet::public_key_to_base64(pk) ); - attohttpc::get(&url) + attohttpc::get(url) .send() .c(d!())? .error_for_status() @@ -753,7 +753,7 @@ pub fn get_validator_detail(td_addr: TendermintAddrRef) -> Result 0 { let oabar_money_back = OpenAnonAssetRecordBuilder::new() .amount(remainder) diff --git a/src/components/wallet_mobile/src/rust/account.rs b/src/components/wallet_mobile/src/rust/account.rs index 44a2ac9986..e6ecdb1b96 100644 --- a/src/components/wallet_mobile/src/rust/account.rs +++ b/src/components/wallet_mobile/src/rust/account.rs @@ -112,7 +112,7 @@ impl EVMTransactionBuilder { }; let txn_with_tag = EvmRawTxWrapper::wrap(&txn); - base64::encode(&txn_with_tag) + base64::encode(txn_with_tag) } pub fn into_ptr(self) -> *mut Self { diff --git a/src/ledger/src/data_model/test.rs b/src/ledger/src/data_model/test.rs index 633d113d66..145fdadd1d 100755 --- a/src/ledger/src/data_model/test.rs +++ b/src/ledger/src/data_model/test.rs @@ -218,7 +218,7 @@ fn gen_sample_tx() -> Transaction { let issuance_operation = Operation::IssueAsset(asset_issuance.clone()); // Instantiate an DefineAsset operation - let mut asset = Box::new(Asset::default()); + let mut asset = Box::::default(); asset.code = AssetTypeCode::gen_random(); let asset_creation = DefineAsset::new( diff --git a/src/ledger/src/staking/cosig.rs b/src/ledger/src/staking/cosig.rs index fc3ec62b0b..e883333070 100644 --- a/src/ledger/src/staking/cosig.rs +++ b/src/ledger/src/staking/cosig.rs @@ -170,7 +170,7 @@ pub struct CoSigRule { impl CoSigRule { #[allow(missing_docs)] pub fn new(threshold: [u64; 2]) -> Result { - if threshold[0] > threshold[1] || threshold[1] > MAX_TOTAL_POWER as u64 { + if threshold[0] > threshold[1] || threshold[1] > MAX_TOTAL_POWER { return Err(eg!("invalid threshold")); } @@ -263,7 +263,7 @@ mod test { vd.cosig_rule = pnk!(CoSigRule::new([75, 100])); assert!(CoSigRule::new([200, 100]).is_err()); - assert!(CoSigRule::new([200, 1 + MAX_TOTAL_POWER as u64]).is_err()); + assert!(CoSigRule::new([200, 1 + MAX_TOTAL_POWER]).is_err()); let mut data = CoSigOp::create(Data::default(), no_replay_token()); pnk!(data.batch_sign(&kps.iter().skip(10).collect::>())); diff --git a/src/ledger/src/staking/mod.rs b/src/ledger/src/staking/mod.rs index 3ea34e5c2c..6d05458351 100644 --- a/src/ledger/src/staking/mod.rs +++ b/src/ledger/src/staking/mod.rs @@ -378,7 +378,7 @@ impl Staking { ) -> Result> { self.validator_info .remove(&h) - .map(|v| v.body.into_iter().map(|(_, v)| v).collect()) + .map(|v| v.body.into_values().collect()) .c(d!("not exists")) } diff --git a/src/ledger/src/store/api_cache.rs b/src/ledger/src/store/api_cache.rs index 9f3d123a0c..a08f3c2776 100644 --- a/src/ledger/src/store/api_cache.rs +++ b/src/ledger/src/store/api_cache.rs @@ -462,9 +462,7 @@ pub fn check_lost_data(ledger: &mut LedgerState) -> Result<()> { } // update the last txo sid - api_cache - .last_sid - .insert("last_txo_sid".to_string(), index as u64); + api_cache.last_sid.insert("last_txo_sid".to_string(), index); } } diff --git a/src/ledger/src/store/mod.rs b/src/ledger/src/store/mod.rs index a5b5689057..6c2d42e204 100644 --- a/src/ledger/src/store/mod.rs +++ b/src/ledger/src/store/mod.rs @@ -1474,7 +1474,7 @@ impl LedgerStatus { ); if seq_id > self.block_commit_count { return Err(eg!(("Transaction seq_id ahead of block_count"))); - } else if seq_id + (TRANSACTION_WINDOW_WIDTH as u64) < self.block_commit_count { + } else if seq_id + TRANSACTION_WINDOW_WIDTH < self.block_commit_count { return Err(eg!(("Transaction seq_id too far behind block_count"))); } else { // Check to see that this nrpt has not been seen before diff --git a/src/libs/bitmap/src/lib.rs b/src/libs/bitmap/src/lib.rs index eb325dec1b..fbf2bed15c 100644 --- a/src/libs/bitmap/src/lib.rs +++ b/src/libs/bitmap/src/lib.rs @@ -566,7 +566,7 @@ fn count_byte(mask: usize) -> u8 { let mut result = 0; for i in 0..8 { - result += if mask & (1 << i) == 0 { 0 } else { 1 }; + result += (mask & (1 << i) != 0) as u8; } result @@ -1097,7 +1097,7 @@ impl BitMap { // Append a list of the set bits to the serialization // results. fn append_set(&self, index: usize, result: &mut Vec) { - let set_bits = self.set_bits[index] as u32; + let set_bits = self.set_bits[index]; // Append the header to the serialization. self.append_header(index, BIT_DESC_SET, set_bits, result); diff --git a/src/libs/globutils/src/wallet.rs b/src/libs/globutils/src/wallet.rs index cddc6207de..249670e33b 100644 --- a/src/libs/globutils/src/wallet.rs +++ b/src/libs/globutils/src/wallet.rs @@ -208,13 +208,13 @@ fn check_lang(lang: &str) -> Result { /// Convert a XfrPublicKey to base64 human-readable address #[inline(always)] pub fn public_key_to_base64(key: &XfrPublicKey) -> String { - base64::encode_config(&NoahFromToBytes::noah_to_bytes(key), base64::URL_SAFE) + base64::encode_config(NoahFromToBytes::noah_to_bytes(key), base64::URL_SAFE) } /// Convert publickey to hex. #[inline(always)] pub fn public_key_to_hex(key: &XfrPublicKey) -> String { - let s = hex::encode(&NoahFromToBytes::noah_to_bytes(key)); + let s = hex::encode(NoahFromToBytes::noah_to_bytes(key)); String::from("0x") + &s } @@ -238,7 +238,7 @@ pub fn anon_public_key_from_base64(pk: &str) -> Result { #[inline(always)] /// Convert an anon public key to base64 pub fn anon_public_key_to_base64(key: &AXfrPubKey) -> String { - base64::encode_config(&AXfrPubKey::noah_to_bytes(key), base64::URL_SAFE) + base64::encode_config(AXfrPubKey::noah_to_bytes(key), base64::URL_SAFE) } #[inline(always)] @@ -252,7 +252,7 @@ pub fn x_public_key_from_base64(pk: &str) -> Result { #[inline(always)] /// Convert a x public key to base64 pub fn x_public_key_to_base64(key: &XPublicKey) -> String { - base64::encode_config(&XPublicKey::noah_to_bytes(key), base64::URL_SAFE) + base64::encode_config(XPublicKey::noah_to_bytes(key), base64::URL_SAFE) } #[inline(always)] @@ -266,7 +266,7 @@ pub fn anon_secret_key_from_base64(sk: &str) -> Result { #[inline(always)] /// Convert an anon secret key to base64 pub fn anon_secret_key_to_base64(key: &AXfrKeyPair) -> String { - base64::encode_config(&AXfrKeyPair::noah_to_bytes(key), base64::URL_SAFE) + base64::encode_config(AXfrKeyPair::noah_to_bytes(key), base64::URL_SAFE) } #[inline(always)] @@ -280,7 +280,7 @@ pub fn x_secret_key_from_base64(sk: &str) -> Result { #[inline(always)] /// Convert an anon public key to base64 pub fn x_secret_key_to_base64(key: &XSecretKey) -> String { - base64::encode_config(&XSecretKey::noah_to_bytes(key), base64::URL_SAFE) + base64::encode_config(XSecretKey::noah_to_bytes(key), base64::URL_SAFE) } #[inline(always)] diff --git a/src/libs/merkle_tree/src/lib.rs b/src/libs/merkle_tree/src/lib.rs index 637232fc4c..4db52c3e1c 100644 --- a/src/libs/merkle_tree/src/lib.rs +++ b/src/libs/merkle_tree/src/lib.rs @@ -1952,7 +1952,7 @@ impl AppendOnlyMerkle { self.check_lower(block, lower_list, lower_index).c(d!())?; } - leaf_count += block.valid_leaves() as u64; + leaf_count += block.valid_leaves(); } if leaf_count != leaves_at_this_level { @@ -2875,7 +2875,7 @@ mod tests { }; for i in 0..transactions { - test_append(&mut tree, i as u64, false); + test_append(&mut tree, i, false); if i == 1 || i == 2 diff --git a/src/libs/sliding_set/src/lib.rs b/src/libs/sliding_set/src/lib.rs index da25b2829e..9fd715a6cc 100644 --- a/src/libs/sliding_set/src/lib.rs +++ b/src/libs/sliding_set/src/lib.rs @@ -25,7 +25,7 @@ impl SlidingSet { /// Create a new sliding window start with 0 #[inline(always)] pub fn new(width: usize) -> Self { - let mut map = Vec::with_capacity(width as usize); + let mut map = Vec::with_capacity(width); for _ in 0..width { map.push(Vec::new()); }