Skip to content

Commit

Permalink
Li/feat/compute res (#62)
Browse files Browse the repository at this point in the history
* Auto stash before rebase of "main"

* Auto stash before rebase of "main"

* impl compute_res

* fix typo in compute_dst_addr

* remove redundant print

* function doc

* add tests, change computeRes to function

* add methods to improve readability

* function does an explicit return

* minor fixes

* unnecessary declaration as var

* remove redundant check, import long type

* return OperandsResult as .{}

* import Relocatable to shorten code

* convert directly from U256 to MaybeRelocatable
  • Loading branch information
lana-shanghai authored Oct 27, 2023
1 parent 74cc575 commit 4268e11
Show file tree
Hide file tree
Showing 7 changed files with 592 additions and 80 deletions.
24 changes: 14 additions & 10 deletions src/vm/builtins/bitwise/bitwise.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Memory = @import("../../memory/memory.zig").Memory;
const Relocatable = @import("../../memory/relocatable.zig").Relocatable;
const MaybeRelocatable = @import("../../memory/relocatable.zig").MaybeRelocatable;
const fromFelt = @import("../../memory/relocatable.zig").fromFelt;
const fromU256 = @import("../../memory/relocatable.zig").fromU256;
const newFromRelocatable = @import("../../memory/relocatable.zig").newFromRelocatable;
const Felt252 = @import("../../../math/fields/starknet.zig").Felt252;

Expand Down Expand Up @@ -140,7 +141,10 @@ test "deduce when address points to felt greater than BITWISE_TOTAL_N_BITS" {
// when
var address = Relocatable.new(0, 3);

try mem.set(Relocatable.new(0, 0), fromFelt(Felt252.fromInteger(number)));
try mem.set(Relocatable.new(
0,
0,
), fromU256(number));

// then
try expectError(Error.UnsupportedNumberOfBits, deduce(address, mem));
Expand All @@ -155,9 +159,9 @@ test "valid bitwise and" {
defer mem.deinit();

// when
try mem.set(Relocatable.new(0, 5), fromFelt(Felt252.fromInteger(10)));
try mem.set(Relocatable.new(0, 6), fromFelt(Felt252.fromInteger(12)));
try mem.set(Relocatable.new(0, 7), fromFelt(Felt252.fromInteger(0)));
try mem.set(Relocatable.new(0, 5), fromU256(10));
try mem.set(Relocatable.new(0, 6), fromU256(12));
try mem.set(Relocatable.new(0, 7), fromU256(0));

var address = Relocatable.new(0, 7);
var expected = MaybeRelocatable{ .felt = Felt252.fromInteger(8) };
Expand All @@ -175,9 +179,9 @@ test "valid bitwise xor" {
defer mem.deinit();

// when
try mem.set(Relocatable.new(0, 5), fromFelt(Felt252.fromInteger(10)));
try mem.set(Relocatable.new(0, 6), fromFelt(Felt252.fromInteger(12)));
try mem.set(Relocatable.new(0, 8), fromFelt(Felt252.fromInteger(0)));
try mem.set(Relocatable.new(0, 5), fromU256(10));
try mem.set(Relocatable.new(0, 6), fromU256(12));
try mem.set(Relocatable.new(0, 8), fromU256(0));

var address = Relocatable.new(0, 8);
var expected = MaybeRelocatable{ .felt = Felt252.fromInteger(6) };
Expand All @@ -195,9 +199,9 @@ test "valid bitwise or" {
defer mem.deinit();

// when
try mem.set(Relocatable.new(0, 5), fromFelt(Felt252.fromInteger(10)));
try mem.set(Relocatable.new(0, 6), fromFelt(Felt252.fromInteger(12)));
try mem.set(Relocatable.new(0, 9), fromFelt(Felt252.fromInteger(0)));
try mem.set(Relocatable.new(0, 5), fromU256(10));
try mem.set(Relocatable.new(0, 6), fromU256(12));
try mem.set(Relocatable.new(0, 9), fromU256(0));

var address = Relocatable.new(0, 9);
var expected = MaybeRelocatable{ .felt = Felt252.fromInteger(14) };
Expand Down
Loading

0 comments on commit 4268e11

Please sign in to comment.