WIP(do not merge): u256 to Felt procedure PR rebase visualization#2435
Closed
partylikeits1983 wants to merge 26 commits intoagglayer-newfrom
Closed
WIP(do not merge): u256 to Felt procedure PR rebase visualization#2435partylikeits1983 wants to merge 26 commits intoagglayer-newfrom
u256 to Felt procedure PR rebase visualization#2435partylikeits1983 wants to merge 26 commits intoagglayer-newfrom
Conversation
Co-authored-by: Marti <marti@miden.team>
Co-authored-by: Marti <marti@miden.team>
Co-authored-by: Marti <marti@miden.team>
Co-authored-by: Marti <marti@miden.team>
Co-authored-by: Marti <marti@miden.team>
7879a6b to
e5974a4
Compare
u256 to Felt procedure PR rebase visualization
mmagician
reviewed
Feb 12, 2026
Comment on lines
+35
to
+45
| /// Convert a U256 value to an array of 8 Felt values (u32 limbs in little-endian order). | ||
| /// | ||
| /// The U256 is stored as 4 u64 words in little-endian order. We split each u64 into two u32 limbs. | ||
| pub fn u256_to_felts(value: U256) -> [Felt; 8] { | ||
| let mut limbs = [Felt::ZERO; 8]; | ||
| for i in 0..4 { | ||
| let word = value.0[i]; | ||
| limbs[i * 2] = Felt::new(word as u32 as u64); // Low 32 bits | ||
| limbs[i * 2 + 1] = Felt::new((word >> 32) as u32 as u64); // High 32 bits | ||
| } | ||
| limbs |
Collaborator
There was a problem hiding this comment.
I would prefer not to introduce another data type (U256), because the conversions are already pretty complex with the BE/LE conventions.
e.g. in:
#[tokio::test]
async fn test_scale_down_wrong_y_clean_case() -> anyhow::Result<()> {
let x = U256::from_dec_str("10000000000000000000").unwrap();
assert_y_plus_minus_one_behavior(x, 18).await
}It would be much better if we stick to raw bytes [u8; 32], though for convenience we can wrap it in a struct like we do for ExitRoot, SmtNode etc. so that instead we have:
pub struct U256([u8; 32]);
impl U256 {
fn from_uint_str(...) -> Self {...};
}
// then for conversion:
let x: = U256::from_uint_str("10000000000000000000)";(the difference between using U256 is that it's a foreign struct which internally does not represent the values as raw bytes)
Collaborator
|
I believe this can be closed since #2331 already contains the git history here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Visualization of #2331 once rebased to
agglayer-new