Skip to content

Commit

Permalink
Program initialization methods with some utils and tests (keep-star…
Browse files Browse the repository at this point in the history
…knet-strange#353)

* add Program init implementation and two unit tests

* add unit test with builtins

* getIdentifier implementation

* dataLen implementation

* add iteratorIdentifier implementation

* add builtinsLen implementation

* invalid identifiers

---------

Co-authored-by: lanaivina <[email protected]>
  • Loading branch information
tcoratger and lana-shanghai authored Feb 7, 2024
1 parent b0ae64e commit 0f686c1
Show file tree
Hide file tree
Showing 4 changed files with 632 additions and 75 deletions.
26 changes: 0 additions & 26 deletions src/math/fields/fields.zig
Original file line number Diff line number Diff line change
Expand Up @@ -146,32 +146,6 @@ pub fn Field(comptime F: type, comptime mod: u256) type {
return .{ .fe = mont };
}

/// Create a field element from a signed integer in Montgomery representation.
///
/// This function converts a signed integer to a field element in Montgomery form.
pub fn fromSignedInteger(num: i256) Self {
var lbe: [BytesSize]u8 = [_]u8{0} ** BytesSize;
std.mem.writeInt(
i256,
lbe[0..],
@mod(num, Modulo),
.little,
);

var nonMont: F.NonMontgomeryDomainFieldElement = undefined;
F.fromBytes(
&nonMont,
lbe,
);
var mont: F.MontgomeryDomainFieldElement = undefined;
F.toMontgomery(
&mont,
nonMont,
);

return .{ .fe = mont };
}

/// Get the field element representing zero.
///
/// Returns a field element with a value of zero.
Expand Down
13 changes: 0 additions & 13 deletions src/math/fields/starknet.zig
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,6 @@ test "Felt252 fromInteger" {
);
}

test "Felt252 fromSignedInteger" {
try expectEqual(
Felt252{ .fe = .{
0xffffffeb9bf00041, 0x9987fff, 0xfffffffffffb7c00, 0x7fffea55af00670,
} },
Felt252.fromSignedInteger(-106710729501573572985208420194530329073740042555888586719234),
);
try expectEqual(
Felt252.fromInt(u8, 10),
Felt252.fromSignedInteger(10),
);
}

test "Felt252 toInteger" {
try expectEqual(
@as(
Expand Down
Loading

0 comments on commit 0f686c1

Please sign in to comment.