Skip to content

Commit

Permalink
remove unnecessary builtin name (keep-starknet-strange#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
StringNick authored Feb 19, 2024
1 parent c33c48b commit 07c86f9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/hint_processor/math_hints.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ pub fn verifyEcdsaSignature(

const ecdsa_ptr = try hint_utils.getPtrFromVarName("ecdsa_ptr", vm, ids_data, ap_tracking);

const builtin_runner = try vm.getBuiltinRunner(.Signature);
const builtin_runner = try vm.getSignatureBuiltin();

try builtin_runner.Signature.addSignature(ecdsa_ptr, .{
try builtin_runner.addSignature(ecdsa_ptr, .{
r,
s,
});
Expand Down
23 changes: 1 addition & 22 deletions src/vm/builtins/builtin_runner/builtin_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,8 @@ pub const POSEIDON_BUILTIN_NAME = "poseidon_builtin";
/// The name of the segment arena builtin.
pub const SEGMENT_ARENA_BUILTIN_NAME = "segment_arena_builtin";

pub const BuiltinName = enum {
/// Bitwise built-in runner for bitwise operations.
Bitwise,
/// EC Operation built-in runner for elliptic curve operations.
EcOp,
/// Hash built-in runner for hash operations.
Hash,
/// Output built-in runner for output operations.
Output,
/// Range Check built-in runner for range check operations.
RangeCheck,
/// Keccak built-in runner for Keccak operations.
Keccak,
/// Signature built-in runner for signature operations.
Signature,
/// Poseidon built-in runner for Poseidon operations.
Poseidon,
/// Segment Arena built-in runner for segment arena operations.
SegmentArena,
};

/// Built-in runner
pub const BuiltinRunner = union(BuiltinName) {
pub const BuiltinRunner = union(enum) {
const Self = @This();

/// Bitwise built-in runner for bitwise operations.
Expand Down
16 changes: 7 additions & 9 deletions src/vm/core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,14 @@ pub const CairoVM = struct {
return &self.builtin_runners;
}

/// Gets builtin runner by name
/// if not exist return not found builtin error
pub fn getBuiltinRunner(self: *Self, name: BuiltinName) !*BuiltinRunner {
for (self.builtin_runners.items) |*runner| {
if (@intFromEnum(runner.*) == @intFromEnum(name)) {
return runner;
}
}
pub fn getSignatureBuiltin(self: *const Self) !*builtin_runner.SignatureBuiltinRunner {
for (self.builtin_runners.items) |*runner|
switch (runner.*) {
.Signature => |*signature_builtin| return signature_builtin,
else => {},
};

return CairoVMError.NotFoundBuiltin;
return CairoVMError.NoSignatureBuiltin;
}

pub fn insertInMemory(
Expand Down
2 changes: 2 additions & 0 deletions src/vm/error.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub const CairoVMError = error{
Unexpected,
/// Expected range_check builtin to be present
NoRangeCheckBuiltin,
/// Expected signature builtin to be present
NoSignatureBuiltin,
/// getBuiltin by name, if not exist error
NotFoundBuiltin,
ReferenceNotFound,
Expand Down
5 changes: 1 addition & 4 deletions src/vm/types/layout.zig
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,7 @@ test "CairoLayout: allCairoInstance" {
try expectEqual(
@as(
?PedersenInstanceDef,
.{
.ratio = 256,
.repetitions = 1
},
.{ .ratio = 256, .repetitions = 1 },
),
actual.builtins.pedersen,
);
Expand Down

0 comments on commit 07c86f9

Please sign in to comment.