From 8f7a8b58c30603ba6c9754f2639a4006e8081cf7 Mon Sep 17 00:00:00 2001 From: shaorongqiang Date: Tue, 11 Apr 2023 13:23:58 +0800 Subject: [PATCH] fix AssetTypePrefix (#922) Co-authored-by: shaorongqiang --- src/ledger/src/data_model/mod.rs | 48 +++++++++++++++++++------------- src/ledger/src/store/mod.rs | 2 +- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/ledger/src/data_model/mod.rs b/src/ledger/src/data_model/mod.rs index 3b0098a1b..d3b2a54e7 100644 --- a/src/ledger/src/data_model/mod.rs +++ b/src/ledger/src/data_model/mod.rs @@ -13,8 +13,6 @@ pub use effects::{BlockEffect, TxnEffect}; use noah_algebra::bls12_381::BLSScalar; use noah_algebra::prelude::Scalar; use noah_crypto::basic::anemoi_jive::{AnemoiJive, AnemoiJive381}; -use num_bigint::BigUint; -use std::str::FromStr; use { crate::converter::ConvertAccount, @@ -1050,33 +1048,43 @@ pub struct UpdateMemoBody { pub enum AssetTypePrefix { UserDefined, ERC20, - NFT, + ERC721, + ERC1155, } impl AssetTypePrefix { #[allow(missing_docs)] pub fn bytes(&self) -> Vec { - let code = match self { - AssetTypePrefix::UserDefined => "56", - AssetTypePrefix::ERC20 => "77", - AssetTypePrefix::NFT => "02", - }; - - hex::decode(format!("{code:0>64}",)).unwrap() + match self { + // println!("{:?}",Keccak256::digest(b"Findora User-defined Asset Type",).as_slice()); + AssetTypePrefix::UserDefined => vec![ + 21, 32, 222, 134, 151, 157, 34, 235, 197, 37, 167, 187, 177, 22, 151, + 207, 188, 106, 180, 176, 48, 199, 185, 128, 200, 9, 142, 225, 131, 159, + 227, 159, + ], + // println!("{:?}",Keccak256::digest(b"Findora ERC20 Asset Type",).as_slice()); + AssetTypePrefix::ERC20 => vec![ + 65, 125, 161, 85, 119, 221, 149, 146, 115, 34, 149, 216, 194, 125, 118, + 193, 48, 66, 123, 79, 108, 204, 246, 48, 201, 158, 89, 51, 76, 223, 150, + 61, + ], + // println!("{:?}",Keccak256::digest(b"Findora ERC721 Asset Type",).as_slice()); + AssetTypePrefix::ERC721 => vec![ + 170, 49, 235, 37, 197, 120, 157, 2, 29, 201, 171, 189, 37, 86, 83, 193, + 122, 235, 202, 55, 40, 170, 141, 141, 78, 235, 98, 142, 128, 114, 97, + 59, + ], + // println!("{:?}",Keccak256::digest(b"Findora ERC1155 Asset Type",).as_slice()); + AssetTypePrefix::ERC1155 => vec![ + 150, 43, 52, 224, 244, 30, 0, 120, 126, 90, 220, 123, 15, 96, 104, 17, + 211, 55, 68, 229, 107, 134, 178, 207, 138, 35, 88, 150, 3, 48, 36, 154, + ], + } } #[allow(missing_docs)] pub fn to_field_element(&self) -> BLSScalar { - // TODO: change to some random numbers in mainnet launch - // The current number comes from the Anemoi parameters - match self { - AssetTypePrefix::UserDefined => - BLSScalar::from(&BigUint::from_str("6406215194479240286762731634835344236141886914605144794931128113894074089386").unwrap()), - AssetTypePrefix::ERC20 => - BLSScalar::from(&BigUint::from_str("25560080366671527635336967422834298208909930660967190727048965370381122828324").unwrap()), - AssetTypePrefix::NFT => - BLSScalar::from(&BigUint::from_str("50658439267116975037933099803088424427085069111100904739841927317887955508403").unwrap()), - } + BLSScalar::from_bytes(&self.bytes()).unwrap() } } diff --git a/src/ledger/src/store/mod.rs b/src/ledger/src/store/mod.rs index 420f6eed4..1975d7d59 100644 --- a/src/ledger/src/store/mod.rs +++ b/src/ledger/src/store/mod.rs @@ -1345,7 +1345,7 @@ impl LedgerStatus { no_replay_token.get_seq_id() as usize, ); if let Err(e) = self.sliding_set.insert(rand, seq_id) { - pd!(format!("Error inserting into window: {e}")); + tracing::warn!(" Error inserting into window: {e}"); } } block.no_replay_tokens.clear();