Skip to content

Conversation

Forostovec
Copy link

  • Read a/b/div via Uint256::from_var_name(...).pack() in uint256_mul_div_mod
  • Use Uint256 in uint256_signed_nn for consistent access to a.high
  • Add Uint256::from_base_addr_with_offsets and use it in uint256_offseted_unsigned_div_rem (standard layout uses from_var_name, expanded layout uses offsets)
  • Form quotient_low/quotient_high via Uint512::split into two Uint256, and write remainder via Uint256

These changes remove duplicated packing logic, standardize error paths, and align uint256 hint implementations with the existing UintNNN helper patterns

Copy link
Contributor

@JulianGCalderon JulianGCalderon left a comment

Choose a reason for hiding this comment

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

Hey @Forostovec, thanks for the contribution! Could you also update the changelog?

Comment on lines +332 to +337
let a = Uint256::from_var_name("a", vm, ids_data, ap_tracking)?;
let a_high = a.high;
//Main logic
//memory[ap] = 1 if 0 <= (ids.a.high % PRIME) < 2 ** 127 else 0
let result: Felt252 =
if *a_high >= Felt252::ZERO && a_high.as_ref() <= &Felt252::from(i128::MAX) {
if *a_high.as_ref() >= Felt252::ZERO && a_high.as_ref() <= &Felt252::from(i128::MAX) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would imply fetching a.low, but not using it, right?

Comment on lines +398 to +406
let div = if div_offset_low == 0 && div_offset_high == 1 {
// Standard Uint256 layout
Uint256::from_var_name("div", vm, ids_data, ap_tracking)?
} else {
let div_addr = get_relocatable_from_var_name("div", vm, ids_data, ap_tracking)?;
Uint256::from_base_addr_with_offsets(div_addr, "div", vm, div_offset_low, div_offset_high)?
};
let div_low = div.low.as_ref();
let div_high = div.high.as_ref();
Copy link
Contributor

Choose a reason for hiding this comment

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

Here could we call from_base_addr_with_offsets directly and avoid the conditional? It would make the function easier to read.

Also, in this function we are packing the U256 into a bigint manually. Could you modify it to call pack? Given that this PR is for unifying U256 usage in general, we can include it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants