Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Oct 2, 2023
1 parent a1ba3b1 commit 088973e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
60 changes: 60 additions & 0 deletions cairo_programs/secp.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
%builtins range_check
from starkware.cairo.common.cairo_secp.bigint import nondet_bigint3, BigInt3, bigint_to_uint256

from starkware.cairo.common.cairo_secp.field import verify_zero, UnreducedBigInt3, reduce, is_zero

func main{range_check_ptr: felt}() {
// Bigint to uint
let big_int = BigInt3(d0=9, d1=9, d2=9);

let (uint256) = bigint_to_uint256(big_int);

assert uint256.low = 696341272098026404630757385;
assert uint256.high = 158329674399744;

// verify_zero
let zero: UnreducedBigInt3 = UnreducedBigInt3(0, 0, 0);
verify_zero(zero);

let x: UnreducedBigInt3 = UnreducedBigInt3(132181232131231239112312312313213083892150, 10, 10);

// reduce
let (y: BigInt3) = reduce(x);
assert y = BigInt3(48537904510172037887998390, 1708402383786350, 10);

let m: BigInt3 = nondet_bigint3();
// Since the scope variable 'value' remains the same, m == y
assert m = y;

let n: BigInt3 = reduce(UnreducedBigInt3(1321812083892150, 11230, 103321));
assert n = BigInt3(1321812083892150, 11230, 103321);

let p: BigInt3 = reduce(UnreducedBigInt3(0, 0, 0));
assert p = BigInt3(0, 0, 0);

let q: BigInt3 = reduce(UnreducedBigInt3(-10, 0, 0));
assert q = BigInt3(
77371252455336262886226981, 77371252455336267181195263, 19342813113834066795298815
);

let r: BigInt3 = reduce(UnreducedBigInt3(-10, -56, -111));
assert r = BigInt3(
77371252455336262886226981, 77371252455336267181195207, 19342813113834066795298704
);

// is_zero
let (u) = is_zero(BigInt3(0, 0, 0));
assert u = 1;
let (v) = is_zero(
BigInt3(232113757366008801543585, 232113757366008801543585, 232113757366008801543585)
);
assert v = 0;

let (w) = is_zero(BigInt3(-10, -10, -10));
assert w = 0;

let (z) = is_zero(BigInt3(1833312543, 67523423, 8790312));
assert z = 0;

return ();
}
4 changes: 4 additions & 0 deletions pkg/vm/cairo_run/cairo_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,7 @@ func TestKeccakAddUint256(t *testing.T) {
func TestReduce(t *testing.T) {
testProgram("reduce", t)
}

func TestSecp(t *testing.T) {
testProgram("secp", t)
}

0 comments on commit 088973e

Please sign in to comment.