Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: swap out the internal U512 inside nibbles #132

Merged
merged 9 commits into from
Apr 8, 2024
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/tests/account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn prepare_interpreter<F: Field>(
.push(value_ptr.into())
.expect("The stack should not overflow"); // value_ptr
interpreter
.push(k.try_into_u256().unwrap())
.push(k.try_into().unwrap())
.expect("The stack should not overflow"); // key

interpreter.run()?;
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/tests/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn prepare_interpreter<F: Field>(
.push(value_ptr.into())
.expect("The stack should not overflow"); // value_ptr
interpreter
.push(k.try_into_u256().unwrap())
.push(k.try_into().unwrap())
.expect("The stack should not overflow"); // key

interpreter.run()?;
Expand Down
8 changes: 4 additions & 4 deletions evm_arithmetization/src/cpu/kernel/tests/mpt/delete.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use ethereum_types::{BigEndianHash, H256, U512};
use mpt_trie::nibbles::Nibbles;
use mpt_trie::nibbles::{Nibbles, NibblesIntern};
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField as F;
use rand::random;
Expand Down Expand Up @@ -70,7 +70,7 @@ fn test_after_mpt_delete_extension_branch() -> Result<()> {
}
.into();
let key = nibbles.merge_nibbles(&Nibbles {
packed: U512::zero(),
packed: NibblesIntern::zero(),
count: 64 - nibbles.count,
});
test_state_trie(state_trie, key, test_account_2())
Expand Down Expand Up @@ -130,7 +130,7 @@ fn test_state_trie(
.push(value_ptr.into())
.expect("The stack should not overflow"); // value_ptr
interpreter
.push(k.try_into_u256().unwrap())
.push(k.try_into().unwrap())
.expect("The stack should not overflow"); // key
interpreter.run()?;
assert_eq!(
Expand All @@ -147,7 +147,7 @@ fn test_state_trie(
.push(0xDEADBEEFu32.into())
.expect("The stack should not overflow");
interpreter
.push(k.try_into_u256().unwrap())
.push(k.try_into().unwrap())
.expect("The stack should not overflow");
interpreter
.push(64.into())
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/tests/mpt/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fn test_state_trie(
.push(value_ptr.into())
.expect("The stack should not overflow"); // value_ptr
interpreter
.push(k.try_into_u256().unwrap())
.push(k.try_into().unwrap())
.expect("The stack should not overflow"); // key

interpreter.run()?;
Expand Down
12 changes: 6 additions & 6 deletions evm_arithmetization/src/generation/mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;
use bytes::Bytes;
use ethereum_types::{Address, BigEndianHash, H256, U256, U512};
use keccak_hash::keccak;
use mpt_trie::nibbles::Nibbles;
use mpt_trie::nibbles::{Nibbles, NibblesIntern};
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use rlp::{Decodable, DecoderError, Encodable, PayloadInfo, Rlp, RlpStream};
use rlp_derive::{RlpDecodable, RlpEncodable};
Expand Down Expand Up @@ -120,7 +120,7 @@ fn parse_storage_value(value_rlp: &[u8]) -> Result<Vec<U256>, ProgramError> {
const fn empty_nibbles() -> Nibbles {
Nibbles {
count: 0,
packed: U512::zero(),
packed: NibblesIntern::zero(),
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ where
trie_data.push(nibbles.count.into());
trie_data.push(
nibbles
.try_into_u256()
.try_into()
.map_err(|_| ProgramError::IntegerTooLarge)?,
);
trie_data.push((trie_data.len() + 1).into());
Expand All @@ -187,7 +187,7 @@ where
trie_data.push(nibbles.count.into());
trie_data.push(
nibbles
.try_into_u256()
.try_into()
.map_err(|_| ProgramError::IntegerTooLarge)?,
);

Expand Down Expand Up @@ -250,7 +250,7 @@ fn load_state_trie(
trie_data.push(nibbles.count.into());
trie_data.push(
nibbles
.try_into_u256()
.try_into()
.map_err(|_| ProgramError::IntegerTooLarge)?,
);
// Set `value_ptr_ptr`.
Expand Down Expand Up @@ -286,7 +286,7 @@ fn load_state_trie(
trie_data.push(nibbles.count.into());
trie_data.push(
nibbles
.try_into_u256()
.try_into()
.map_err(|_| ProgramError::IntegerTooLarge)?,
);
// Set `value_ptr_ptr`.
Expand Down
6 changes: 3 additions & 3 deletions evm_arithmetization/src/generation/trie_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::collections::HashMap;

use ethereum_types::{BigEndianHash, H256, U256, U512};
use mpt_trie::nibbles::Nibbles;
use mpt_trie::nibbles::{Nibbles, NibblesIntern};
use mpt_trie::partial_trie::{HashedPartialTrie, Node, PartialTrie, WrappedNode};

use super::mpt::{AccountRlp, LegacyReceiptRlp, LogRlp};
Expand Down Expand Up @@ -47,7 +47,7 @@ pub(crate) fn read_trie<V>(
let mut res = HashMap::new();
let empty_nibbles = Nibbles {
count: 0,
packed: U512::zero(),
packed: NibblesIntern::zero(),
};
read_trie_helper::<V>(memory, ptr, read_value, empty_nibbles, &mut res)?;
Ok(res)
Expand Down Expand Up @@ -259,7 +259,7 @@ pub(crate) fn get_trie<N: PartialTrie>(
) -> Result<N, ProgramError> {
let empty_nibbles = Nibbles {
count: 0,
packed: U512::zero(),
packed: NibblesIntern::zero(),
};
Ok(N::new(get_trie_helper(
memory,
Expand Down
Loading