From 8fa830edd4cfaa362dc38ada973111eeac10dcb2 Mon Sep 17 00:00:00 2001 From: Steven Gu Date: Fri, 13 Dec 2024 23:17:44 +0800 Subject: [PATCH] Comment out `test_pidgy_pinguin_mapping_slot` test case, and fix clippy. --- mp2-common/src/eth.rs | 66 ++++++++++++++++++++-------------------- mp2-common/src/utils.rs | 67 +---------------------------------------- 2 files changed, 35 insertions(+), 98 deletions(-) diff --git a/mp2-common/src/eth.rs b/mp2-common/src/eth.rs index dacbb634..47268614 100644 --- a/mp2-common/src/eth.rs +++ b/mp2-common/src/eth.rs @@ -532,38 +532,40 @@ mod test { Ok(()) } - #[tokio::test] - async fn test_pidgy_pinguin_mapping_slot() -> Result<()> { - // first pinguin holder https://dune.com/queries/2450476/4027653 - // holder: 0x188b264aa1456b869c3a92eeed32117ebb835f47 - // NFT id https://opensea.io/assets/ethereum/0xbd3531da5cf5857e7cfaa92426877b022e612cf8/1116 - let mapping_value = - Address::from_str("0x188B264AA1456B869C3a92eeeD32117EbB835f47").unwrap(); - let nft_id: u32 = 1116; - let mapping_key = left_pad32(&nft_id.to_be_bytes()); - let url = get_mainnet_url(); - let provider = ProviderBuilder::new().on_http(url.parse().unwrap()); - - // extracting from - // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol - // assuming it's using ERC731Enumerable that inherits ERC721 - let mapping_slot = 2; - // pudgy pinguins - let pudgy_address = Address::from_str("0xBd3531dA5CF5857e7CfAA92426877b022e612cf8")?; - let query = ProofQuery::new_mapping_slot(pudgy_address, mapping_slot, mapping_key.to_vec()); - let res = query - .query_mpt_proof(&provider, BlockNumberOrTag::Latest) - .await?; - let raw_address = ProofQuery::verify_storage_proof(&res)?; - // the value is actually RLP encoded ! - let decoded_address: Vec = rlp::decode(&raw_address).unwrap(); - let leaf_node: Vec> = rlp::decode_list(res.storage_proof[0].proof.last().unwrap()); - println!("leaf_node[1].len() = {}", leaf_node[1].len()); - // this is read in the same order - let found_address = Address::from_slice(&decoded_address.into_iter().collect::>()); - assert_eq!(found_address, mapping_value); - Ok(()) - } + /* TODO: Need to update, since the mapping slot value is updated. + #[tokio::test] + async fn test_pidgy_pinguin_mapping_slot() -> Result<()> { + // first pinguin holder https://dune.com/queries/2450476/4027653 + // holder: 0x188b264aa1456b869c3a92eeed32117ebb835f47 + // NFT id https://opensea.io/assets/ethereum/0xbd3531da5cf5857e7cfaa92426877b022e612cf8/1116 + let mapping_value = + Address::from_str("0x188B264AA1456B869C3a92eeeD32117EbB835f47").unwrap(); + let nft_id: u32 = 1116; + let mapping_key = left_pad32(&nft_id.to_be_bytes()); + let url = get_mainnet_url(); + let provider = ProviderBuilder::new().on_http(url.parse().unwrap()); + + // extracting from + // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol + // assuming it's using ERC731Enumerable that inherits ERC721 + let mapping_slot = 2; + // pudgy pinguins + let pudgy_address = Address::from_str("0xBd3531dA5CF5857e7CfAA92426877b022e612cf8")?; + let query = ProofQuery::new_mapping_slot(pudgy_address, mapping_slot, mapping_key.to_vec()); + let res = query + .query_mpt_proof(&provider, BlockNumberOrTag::Latest) + .await?; + let raw_address = ProofQuery::verify_storage_proof(&res)?; + // the value is actually RLP encoded ! + let decoded_address: Vec = rlp::decode(&raw_address).unwrap(); + let leaf_node: Vec> = rlp::decode_list(res.storage_proof[0].proof.last().unwrap()); + println!("leaf_node[1].len() = {}", leaf_node[1].len()); + // this is read in the same order + let found_address = Address::from_slice(&decoded_address.into_iter().collect::>()); + assert_eq!(found_address, mapping_value); + Ok(()) + } + */ #[tokio::test] async fn test_kashish_contract_proof_query() -> Result<()> { diff --git a/mp2-common/src/utils.rs b/mp2-common/src/utils.rs index db30d2ba..6926d25c 100644 --- a/mp2-common/src/utils.rs +++ b/mp2-common/src/utils.rs @@ -773,33 +773,9 @@ impl, const D: usize> SliceConnector for CircuitBui } } -/// Convert an Uint32 target to Uint8 targets. -pub(crate) fn unpack_u32_to_u8_targets, const D: usize>( - b: &mut CircuitBuilder, - u: Target, - endianness: Endianness, -) -> Vec { - let zero = b.zero(); - let mut bits = b.split_le(u, u32::BITS as usize); - match endianness { - Endianness::Big => bits.reverse(), - Endianness::Little => (), - }; - bits.chunks(8) - .map(|chunk| { - // let bits: Box> = match endianness { - let bits: Box> = match endianness { - Endianness::Big => Box::new(chunk.iter()), - Endianness::Little => Box::new(chunk.iter().rev()), - }; - bits.fold(zero, |acc, bit| b.mul_const_add(F::TWO, acc, bit.target)) - }) - .collect() -} - #[cfg(test)] mod test { - use super::{bits_to_num, unpack_u32_to_u8_targets, Packer, TargetsConnector, ToFields}; + use super::{bits_to_num, Packer, TargetsConnector, ToFields}; use crate::types::CBuilder; use crate::utils::{ greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, num_to_bits, @@ -1033,45 +1009,4 @@ mod test { let proof = data.prove(pw)?; data.verify(proof) } - - #[test] - fn test_unpack_u32_to_u8_targets() -> Result<()> { - let rng = &mut thread_rng(); - let u32_value: u32 = rng.gen(); - let big_endian_u8_values = u32_value.to_be_bytes().to_fields(); - let little_endian_u8_values = u32_value.to_le_bytes().to_fields(); - - let config = default_config(); - let mut builder = CBuilder::new(config); - let b = &mut builder; - - let [exp_big_endian_u8_targets, exp_little_endian_u8_targets] = - array::from_fn(|_| b.add_virtual_target_arr::<4>()); - - let u32_target = b.constant(F::from_canonical_u32(u32_value)); - let real_big_endian_u8_targets = unpack_u32_to_u8_targets(b, u32_target, Endianness::Big); - let real_little_endian_u8_targets = - unpack_u32_to_u8_targets(b, u32_target, Endianness::Little); - - b.connect_targets( - real_big_endian_u8_targets, - exp_big_endian_u8_targets.to_vec(), - ); - b.connect_targets( - real_little_endian_u8_targets, - exp_little_endian_u8_targets.to_vec(), - ); - - let data = builder.build::(); - let mut pw = PartialWitness::new(); - [ - (big_endian_u8_values, exp_big_endian_u8_targets), - (little_endian_u8_values, exp_little_endian_u8_targets), - ] - .into_iter() - .for_each(|(values, targets)| pw.set_target_arr(&targets, &values)); - - let proof = data.prove(pw)?; - data.verify(proof) - } }