Skip to content

Commit

Permalink
fix diffasserterror in uint256 integration test (#495)
Browse files Browse the repository at this point in the history
fix diffasserterror in uint256 integration test
  • Loading branch information
StringNick authored Mar 22, 2024
1 parent 2a1c9f0 commit 954d12c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/hint_processor/uint256_utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,13 @@ pub fn uint256OffsetedUnsignedDivRem(
// TODO: optimize use biguint instead of u512
const a_shifted = (@as(u512, a_high.toInteger()) << 128) + @as(u512, a_low.toInteger());
const div = (@as(u512, div_high.toInteger()) << 128) + @as(u512, div_low.toInteger());

//a and div will always be positive numbers
//Then, Rust div_rem equals Python divmod
const quotient_remainder = try helper.divRem(u512, a_shifted, div);

const quotient = Uint256.fromFelt(Felt252.fromInt(u512, quotient_remainder[0]));
const remainder = Uint256.fromFelt(Felt252.fromInt(u512, quotient_remainder[1]));
const quotient = Uint256.split(u512, quotient_remainder[0]);
const remainder = Uint256.split(u512, quotient_remainder[1]);

try quotient.insertFromVarName(allocator, "quotient", vm, ids_data, ap_tracking);
try remainder.insertFromVarName(allocator, "remainder", vm, ids_data, ap_tracking);
Expand Down
3 changes: 1 addition & 2 deletions src/integration_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ pub fn main() void {
//TODO: hint uint384 not implemented
// .{ .pathname = "cairo_programs/uint256_improvements.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/uint256_integration_tests.json", .layout = "all_cairo" },
// TODO: fix DiffAssertValues
// .{ .pathname = "cairo_programs/uint256.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/uint256.json", .layout = "all_cairo" },

// .{ .pathname = "cairo_programs/uint384_extension_test.json", .layout = "all_cairo" },
// .{ .pathname = "cairo_programs/uint384_extension.json", .layout = "all_cairo" },
Expand Down
4 changes: 4 additions & 0 deletions src/math/fields/fields.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ pub fn Field(comptime F: type, comptime modulo: u256) type {

fe: F.MontgomeryDomainFieldElement,

pub fn format(self: Self, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
return std.fmt.format(writer, "Felt({any})", .{self.toInteger()});
}

/// Mask to apply to the highest limb to get the correct number of bits.
pub fn mask(bits: usize) u64 {
return switch (bits) {
Expand Down

0 comments on commit 954d12c

Please sign in to comment.