From b5c28bd65e6a00f3673fdf2956f704beb705196c Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Mon, 18 Sep 2023 14:29:11 -0400 Subject: [PATCH] Rename utility methods for U256 conversion Co-authored-by: Nicholas Ward --- evm/src/get_challenges.rs | 24 ++++++++++++------------ evm/src/recursive_verifier.rs | 16 ++++++++-------- evm/src/util.rs | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/evm/src/get_challenges.rs b/evm/src/get_challenges.rs index 8cd6fd810f..ab25a28d57 100644 --- a/evm/src/get_challenges.rs +++ b/evm/src/get_challenges.rs @@ -13,7 +13,7 @@ use crate::permutation::{ get_n_grand_product_challenge_sets_target, }; use crate::proof::*; -use crate::util::{h256_limbs, u256_limbs, u256_lowest_limb, u256_lowest_word}; +use crate::util::{h256_limbs, u256_limbs, u256_to_u32, u256_to_u64}; use crate::witness::errors::ProgramError; fn observe_root, C: GenericConfig, const D: usize>( @@ -61,15 +61,15 @@ fn observe_block_metadata< challenger.observe_elements( &u256_limbs::(U256::from_big_endian(&block_metadata.block_beneficiary.0))[..5], ); - challenger.observe_element(u256_lowest_limb(block_metadata.block_timestamp)?); - challenger.observe_element(u256_lowest_limb(block_metadata.block_number)?); - challenger.observe_element(u256_lowest_limb(block_metadata.block_difficulty)?); - challenger.observe_element(u256_lowest_limb(block_metadata.block_gaslimit)?); - challenger.observe_element(u256_lowest_limb(block_metadata.block_chain_id)?); - let basefee = u256_lowest_word(block_metadata.block_base_fee)?; + challenger.observe_element(u256_to_u32(block_metadata.block_timestamp)?); + challenger.observe_element(u256_to_u32(block_metadata.block_number)?); + challenger.observe_element(u256_to_u32(block_metadata.block_difficulty)?); + challenger.observe_element(u256_to_u32(block_metadata.block_gaslimit)?); + challenger.observe_element(u256_to_u32(block_metadata.block_chain_id)?); + let basefee = u256_to_u64(block_metadata.block_base_fee)?; challenger.observe_element(basefee.0); challenger.observe_element(basefee.1); - challenger.observe_element(u256_lowest_limb(block_metadata.block_gas_used)?); + challenger.observe_element(u256_to_u32(block_metadata.block_gas_used)?); for i in 0..8 { challenger.observe_elements(&u256_limbs(block_metadata.block_bloom[i])); } @@ -106,10 +106,10 @@ fn observe_extra_block_data< challenger: &mut Challenger, extra_data: &ExtraBlockData, ) -> Result<(), ProgramError> { - challenger.observe_element(u256_lowest_limb(extra_data.txn_number_before)?); - challenger.observe_element(u256_lowest_limb(extra_data.txn_number_after)?); - challenger.observe_element(u256_lowest_limb(extra_data.gas_used_before)?); - challenger.observe_element(u256_lowest_limb(extra_data.gas_used_after)?); + challenger.observe_element(u256_to_u32(extra_data.txn_number_before)?); + challenger.observe_element(u256_to_u32(extra_data.txn_number_after)?); + challenger.observe_element(u256_to_u32(extra_data.gas_used_before)?); + challenger.observe_element(u256_to_u32(extra_data.gas_used_after)?); for i in 0..8 { challenger.observe_elements(&u256_limbs(extra_data.block_bloom_before[i])); } diff --git a/evm/src/recursive_verifier.rs b/evm/src/recursive_verifier.rs index d58344bbf7..76a923385c 100644 --- a/evm/src/recursive_verifier.rs +++ b/evm/src/recursive_verifier.rs @@ -43,7 +43,7 @@ use crate::proof::{ TrieRootsTarget, }; use crate::stark::Stark; -use crate::util::{h256_limbs, u256_limbs, u256_lowest_limb, u256_lowest_word}; +use crate::util::{h256_limbs, u256_limbs, u256_to_u32, u256_to_u64}; use crate::vanishing_poly::eval_vanishing_poly_circuit; use crate::vars::StarkEvaluationTargets; use crate::witness::errors::ProgramError; @@ -1009,31 +1009,31 @@ where witness.set_target_arr(&block_metadata_target.block_beneficiary, &beneficiary_limbs); witness.set_target( block_metadata_target.block_timestamp, - u256_lowest_limb(block_metadata.block_timestamp)?, + u256_to_u32(block_metadata.block_timestamp)?, ); witness.set_target( block_metadata_target.block_number, - u256_lowest_limb(block_metadata.block_number)?, + u256_to_u32(block_metadata.block_number)?, ); witness.set_target( block_metadata_target.block_difficulty, - u256_lowest_limb(block_metadata.block_difficulty)?, + u256_to_u32(block_metadata.block_difficulty)?, ); witness.set_target( block_metadata_target.block_gaslimit, - u256_lowest_limb(block_metadata.block_gaslimit)?, + u256_to_u32(block_metadata.block_gaslimit)?, ); witness.set_target( block_metadata_target.block_chain_id, - u256_lowest_limb(block_metadata.block_chain_id)?, + u256_to_u32(block_metadata.block_chain_id)?, ); // Basefee fits in 2 limbs - let basefee = u256_lowest_word(block_metadata.block_base_fee)?; + let basefee = u256_to_u64(block_metadata.block_base_fee)?; witness.set_target(block_metadata_target.block_base_fee[0], basefee.0); witness.set_target(block_metadata_target.block_base_fee[1], basefee.1); witness.set_target( block_metadata_target.block_gas_used, - u256_lowest_limb(block_metadata.block_gas_used)?, + u256_to_u32(block_metadata.block_gas_used)?, ); let mut block_bloom_limbs = [F::ZERO; 64]; for (i, limbs) in block_bloom_limbs.chunks_exact_mut(8).enumerate() { diff --git a/evm/src/util.rs b/evm/src/util.rs index ee285e2574..a3f6d0507a 100644 --- a/evm/src/util.rs +++ b/evm/src/util.rs @@ -49,7 +49,7 @@ pub fn trace_rows_to_poly_values( /// Returns the lowest LE 32-bit limb of a `U256` as a field element, /// and errors if the integer is actually greater. -pub(crate) fn u256_lowest_limb(u256: U256) -> Result { +pub(crate) fn u256_to_u32(u256: U256) -> Result { if TryInto::::try_into(u256).is_err() { return Err(ProgramError::IntegerTooLarge); } @@ -59,7 +59,7 @@ pub(crate) fn u256_lowest_limb(u256: U256) -> Result /// Returns the lowest LE 64-bit word of a `U256` as two field elements /// each storing a 32-bit limb, and errors if the integer is actually greater. -pub(crate) fn u256_lowest_word(u256: U256) -> Result<(F, F), ProgramError> { +pub(crate) fn u256_to_u64(u256: U256) -> Result<(F, F), ProgramError> { if TryInto::::try_into(u256).is_err() { return Err(ProgramError::IntegerTooLarge); }