Skip to content

WIP(do not merge): u256 to Felt procedure PR rebase visualization#2435

Closed
partylikeits1983 wants to merge 26 commits intoagglayer-newfrom
ajl-u256-felt-downscale-procedure-rebased
Closed

WIP(do not merge): u256 to Felt procedure PR rebase visualization#2435
partylikeits1983 wants to merge 26 commits intoagglayer-newfrom
ajl-u256-felt-downscale-procedure-rebased

Conversation

@partylikeits1983
Copy link
Contributor

@partylikeits1983 partylikeits1983 commented Feb 12, 2026

Visualization of #2331 once rebased to agglayer-new

partylikeits1983 and others added 24 commits February 12, 2026 13:38
@partylikeits1983 partylikeits1983 force-pushed the ajl-u256-felt-downscale-procedure-rebased branch from 7879a6b to e5974a4 Compare February 12, 2026 10:54
@partylikeits1983 partylikeits1983 changed the title WIP: rebase visualization WIP(do not merge): rebase visualization Feb 12, 2026
@partylikeits1983 partylikeits1983 changed the title WIP(do not merge): rebase visualization WIP(do not merge): u256 to Felt procedure PR rebase visualization 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@igamigo igamigo added the pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority label Feb 12, 2026
@mmagician
Copy link
Collaborator

I believe this can be closed since #2331 already contains the git history here

@mmagician mmagician closed this Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants