Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement remaining secp hints #309

Open
wants to merge 133 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
977ba29
Add ec hints
mmsc2 Sep 14, 2023
70a9db2
Implement hints
mmsc2 Sep 15, 2023
864b7b8
Add the hints to the processor
mmsc2 Sep 15, 2023
7df4192
Test pack86 function
mmsc2 Sep 15, 2023
1a66309
Test hint
mmsc2 Sep 15, 2023
91ffa57
Delete debug info, Test ec negative op
mmsc2 Sep 18, 2023
7bf1909
Second hint test
mmsc2 Sep 18, 2023
5d2d256
Merge main
mmsc2 Sep 18, 2023
a08c642
Test embedded hint
mmsc2 Sep 18, 2023
029fe50
Merge branch 'main' into EcHint
mmsc2 Sep 18, 2023
762a566
Merge branch 'main' into EcHint
mmsc2 Sep 18, 2023
6c6eed9
Change to Camel case
mmsc2 Sep 19, 2023
ec9345c
Implement slope hints
mmsc2 Sep 19, 2023
9d14678
Fix merge conflict
mmsc2 Sep 19, 2023
ff7fb50
Fix format
mmsc2 Sep 19, 2023
4e9afc5
Delete github conflict string
mmsc2 Sep 19, 2023
cc53b65
Tests hints
mmsc2 Sep 19, 2023
a0d269b
Tests hints slopes
mmsc2 Sep 19, 2023
c25e25c
Fix merge conflict
mmsc2 Sep 19, 2023
a27b814
Rename misleading name function
mmsc2 Sep 19, 2023
51fedf0
Merge branch 'main' into EcSlopeHint
mmsc2 Sep 19, 2023
9e39502
Fix function name
mmsc2 Sep 19, 2023
327299b
Fix format
mmsc2 Sep 19, 2023
0fdad83
Fix error in function call
mmsc2 Sep 19, 2023
ba81ca8
Merge branch 'main' into EcSlopeHint
entropidelic Sep 19, 2023
78dd5d0
Delete debug info
mmsc2 Sep 19, 2023
c023bea
Merge branch 'EcSlopeHint' of github.com:lambdaclass/cairo-vm.go into…
mmsc2 Sep 19, 2023
facfb8a
Delete unused import
mmsc2 Sep 19, 2023
f195395
Merge main
mmsc2 Sep 20, 2023
76c8b8b
Secp hints
mmsc2 Sep 20, 2023
2e1b1f9
Merge main
mmsc2 Sep 20, 2023
41c5e00
Secpr21
mmsc2 Sep 20, 2023
ed75168
Add it to the hint processor
mmsc2 Sep 20, 2023
e868fa0
Hints secp
mmsc2 Sep 20, 2023
b88e485
Merge main
mmsc2 Sep 20, 2023
efad459
bigint3 nondet
mmsc2 Sep 20, 2023
113bb9b
bigint bug fixed
mmsc2 Sep 20, 2023
c09d921
Zero verify
mmsc2 Sep 20, 2023
50994ad
Merge main
mmsc2 Sep 21, 2023
2216d94
Merge branch 'main' into SecpPHints
mmsc2 Sep 21, 2023
2d44427
Add hint to hint processor
mmsc2 Sep 21, 2023
d50207a
Mege main
mmsc2 Sep 21, 2023
c9f1709
Merge branch 'main' into SecpPHints
mmsc2 Sep 21, 2023
46e8bd6
Merge branch 'SecpPHints' of github.com:lambdaclass/cairo-vm.go into …
mmsc2 Sep 21, 2023
7720f42
Debug info
mmsc2 Sep 22, 2023
5775336
Merge main
mmsc2 Sep 22, 2023
5ce7e74
Prints
mmsc2 Sep 22, 2023
3cd665a
Merge branch 'SecpPHints' of github.com:lambdaclass/cairo-vm.go into …
mmsc2 Sep 22, 2023
c7faf9a
Merge branch 'SecpPHints' of github.com:lambdaclass/cairo-vm.go into …
mmsc2 Sep 22, 2023
3969b1b
Test verify with unit test
mmsc2 Sep 25, 2023
942c204
Debug unit test
mmsc2 Sep 25, 2023
ee521d0
Test verify zero with debug
mmsc2 Sep 25, 2023
621a616
Non det big 3 test
mmsc2 Sep 25, 2023
6d2cc54
Modify test to use ids manager
mmsc2 Sep 25, 2023
cef26c0
Add hint codes
fmoletta Sep 25, 2023
ca18c74
Implement base hint
fmoletta Sep 25, 2023
ea13432
Add hints
fmoletta Sep 25, 2023
dd910fa
Add hints to ExecuteHint
fmoletta Sep 25, 2023
552715d
debug info
mmsc2 Sep 26, 2023
af1afcb
Fix broken test
mmsc2 Sep 26, 2023
69d015e
Move integration test to cairo_run_test.go
mmsc2 Sep 26, 2023
b5f44e2
Move file from hints_utils and rename
mmsc2 Sep 26, 2023
6cfabdf
Delete debug
mmsc2 Sep 26, 2023
6527b72
Return error of IdsData.Insert
mmsc2 Sep 26, 2023
2bcf015
Change to camel case
mmsc2 Sep 26, 2023
b542a09
Add unit test
fmoletta Sep 26, 2023
8cd64b6
Add unit test
fmoletta Sep 26, 2023
f3d9dbe
Add hint codes
fmoletta Sep 26, 2023
91f8188
Implement hint
fmoletta Sep 26, 2023
29efa2d
Add SafeDivBig
fmoletta Sep 26, 2023
d0cc45e
Add generic way to fetch scope variables
fmoletta Sep 26, 2023
0655cfe
Add generic fetch
fmoletta Sep 26, 2023
ca654b4
Add generic way to fetch scope variables
fmoletta Sep 26, 2023
08ebcd6
Use more specific error
fmoletta Sep 26, 2023
bbd8b8a
Merge branch 'scopes-fetch-generic' into signature-hints-3
fmoletta Sep 26, 2023
a6e4d4a
Add hints to ExecuteHint
fmoletta Sep 26, 2023
c85e650
Add extra hint
fmoletta Sep 26, 2023
2e948d8
Fix logic, add unit test
fmoletta Sep 26, 2023
97c9cc7
Add unit test
fmoletta Sep 26, 2023
66c38a6
use boolean flag instead or arg
fmoletta Sep 26, 2023
68b4387
Merge remote-tracking branch 'origin/SecpPHints' into signature-hints-3
fmoletta Sep 26, 2023
f6c402d
Fix scope var name
fmoletta Sep 26, 2023
97a67f8
Fix scope var name in tests
fmoletta Sep 26, 2023
69993be
Make FetchScopeVar work despite references
fmoletta Sep 26, 2023
2739694
Revert "Make FetchScopeVar work despite references"
fmoletta Sep 26, 2023
bcd34f6
Merge branch 'signature-hints-2' into signature-hints-3
fmoletta Sep 26, 2023
9116e1b
Handle scope variables as big.Int instead of *big.Int
fmoletta Sep 26, 2023
62b9ed2
Fix merge cnflicts
fmoletta Sep 26, 2023
ccd5805
Fix tests
fmoletta Sep 26, 2023
e0573c1
Implement Igcdex + add tests
fmoletta Sep 26, 2023
04df104
Implement DivMod
fmoletta Sep 26, 2023
7bd7edc
Use DivMod instead of Div + Mod
fmoletta Sep 26, 2023
b1c81af
Dont modify the original value in bigint3_split function
fmoletta Sep 26, 2023
e6882ff
Merge branch 'SecpPHints' into signature-hints-3
fmoletta Sep 26, 2023
2fbc48d
Push test file
fmoletta Sep 26, 2023
468e176
Remove redundant check
fmoletta Sep 26, 2023
18cfa39
Merge branch 'main' of github.com:lambdaclass/cairo-vm.go into signat…
fmoletta Sep 27, 2023
8367a38
Add hint code
fmoletta Sep 27, 2023
2479f89
Implement hint
fmoletta Sep 27, 2023
859353f
Add unit test
fmoletta Sep 27, 2023
c28ffdd
Fix test value
fmoletta Sep 27, 2023
35195a2
Fix hint logic
fmoletta Sep 27, 2023
3886843
Add unit test
fmoletta Sep 27, 2023
6d64650
Add integration test
fmoletta Sep 27, 2023
8378ffa
fmt
fmoletta Sep 27, 2023
8f8bda9
Merge branch 'main' into signature-hints-3
fmoletta Sep 29, 2023
90862cd
Merge branch 'main' into signature-hints-3
pefontana Sep 29, 2023
32793cb
Merge branch 'signature-hints-3' into secp-hints
fmoletta Sep 29, 2023
4921ef6
Implement Reduce_V1 hint
fmoletta Sep 29, 2023
ee2b36c
Fix file names
fmoletta Sep 29, 2023
94b046c
Add unit test
fmoletta Sep 29, 2023
e725a57
Add testing util CheckScopeVar`
fmoletta Sep 29, 2023
9f392d8
Refactor test
fmoletta Sep 29, 2023
0b46bc5
Merge branch 'main' of github.com:lambdaclass/cairo-vm.go into signat…
fmoletta Oct 2, 2023
53fcdb5
Merge math_utils/utils & utils/math_utils
fmoletta Oct 2, 2023
16428ec
Merge branch 'signature-hints-3' into signature-hints-4
fmoletta Oct 2, 2023
53e547f
Restore gitignore
fmoletta Oct 2, 2023
2b2dae8
Fix
fmoletta Oct 2, 2023
2fab2d7
Merge branch 'signature-hints-3' into secp-hints
fmoletta Oct 2, 2023
da8fc0a
Add hint + tests
fmoletta Oct 2, 2023
6b91a52
Add test file
fmoletta Oct 2, 2023
307207c
Add REDUCE_V2 hint
fmoletta Oct 2, 2023
37b3302
Implement verify_zero hints
fmoletta Oct 2, 2023
36b75e7
Add verify_zero hints
fmoletta Oct 2, 2023
754d3f1
Fix fmt
fmoletta Oct 2, 2023
e6c88a0
Merge branch 'secp-hints' into signature-hints-4
fmoletta Oct 2, 2023
89e5a3e
Bump cairo-vm version
fmoletta Oct 2, 2023
c51e50e
Implement hint + add test
fmoletta Oct 2, 2023
9493264
Implement is zero nondet hint + test
fmoletta Oct 2, 2023
f418046
Add IS_ZERO_PACK
fmoletta Oct 2, 2023
a1ba3b1
Implement is-zero assign scope variables
fmoletta Oct 2, 2023
088973e
Add integration test
fmoletta Oct 2, 2023
52ab234
fmt
fmoletta Oct 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
CAIRO_VM_CLI:=cairo-vm/target/release/cairo-vm-cli

$(CAIRO_VM_CLI):
git clone --depth 1 -b v0.8.5 https://github.com/lambdaclass/cairo-vm
git clone --depth 1 -b v0.8.7 https://github.com/lambdaclass/cairo-vm
cd cairo-vm; cargo b --release --bin cairo-vm-cli

# Create proof mode programs.
Expand Down
129 changes: 129 additions & 0 deletions cairo_programs/div_mod_n.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
%builtins range_check

from starkware.cairo.common.cairo_secp.bigint import BigInt3, nondet_bigint3, BASE, bigint_mul
from starkware.cairo.common.cairo_secp.constants import BETA, N0, N1, N2

// Source: https://github.com/myBraavos/efficient-secp256r1/blob/73cca4d53730cb8b2dcf34e36c7b8f34b96b3230/src/secp256r1/signature.cairo

// Computes a * b^(-1) modulo the size of the elliptic curve (N).
//
// Prover assumptions:
// * All the limbs of a are in the range (-2 ** 210.99, 2 ** 210.99).
// * All the limbs of b are in the range (-2 ** 124.99, 2 ** 124.99).
// * b is in the range [0, 2 ** 256).
//
// Soundness assumptions:
// * The limbs of a are in the range (-2 ** 249, 2 ** 249).
// * The limbs of b are in the range (-2 ** 159.83, 2 ** 159.83).
func div_mod_n{range_check_ptr}(a: BigInt3, b: BigInt3) -> (res: BigInt3) {
%{
from starkware.cairo.common.cairo_secp.secp_utils import N, pack
from starkware.python.math_utils import div_mod, safe_div

a = pack(ids.a, PRIME)
b = pack(ids.b, PRIME)
value = res = div_mod(a, b, N)
%}
let (res) = nondet_bigint3();

%{ value = k_plus_one = safe_div(res * b - a, N) + 1 %}
let (k_plus_one) = nondet_bigint3();
let k = BigInt3(d0=k_plus_one.d0 - 1, d1=k_plus_one.d1, d2=k_plus_one.d2);

let (res_b) = bigint_mul(res, b);
let n = BigInt3(N0, N1, N2);
let (k_n) = bigint_mul(k, n);

// We should now have res_b = k_n + a. Since the numbers are in unreduced form,
// we should handle the carry.

tempvar carry1 = (res_b.d0 - k_n.d0 - a.d0) / BASE;
assert [range_check_ptr + 0] = carry1 + 2 ** 127;

tempvar carry2 = (res_b.d1 - k_n.d1 - a.d1 + carry1) / BASE;
assert [range_check_ptr + 1] = carry2 + 2 ** 127;

tempvar carry3 = (res_b.d2 - k_n.d2 - a.d2 + carry2) / BASE;
assert [range_check_ptr + 2] = carry3 + 2 ** 127;

tempvar carry4 = (res_b.d3 - k_n.d3 + carry3) / BASE;
assert [range_check_ptr + 3] = carry4 + 2 ** 127;

assert res_b.d4 - k_n.d4 + carry4 = 0;

let range_check_ptr = range_check_ptr + 4;

return (res=res);
}

func div_mod_n_alt{range_check_ptr}(a: BigInt3, b: BigInt3) -> (res: BigInt3) {
// just used to import N
%{
from starkware.cairo.common.cairo_secp.secp_utils import N, pack
from starkware.python.math_utils import div_mod, safe_div

a = pack(ids.a, PRIME)
b = pack(ids.b, PRIME)
value = res = div_mod(a, b, N)
%}

%{
from starkware.cairo.common.cairo_secp.secp_utils import pack
from starkware.python.math_utils import div_mod, safe_div

a = pack(ids.a, PRIME)
b = pack(ids.b, PRIME)
value = res = div_mod(a, b, N)
%}
let (res) = nondet_bigint3();

%{ value = k_plus_one = safe_div(res * b - a, N) + 1 %}
let (k_plus_one) = nondet_bigint3();
let k = BigInt3(d0=k_plus_one.d0 - 1, d1=k_plus_one.d1, d2=k_plus_one.d2);

let (res_b) = bigint_mul(res, b);
let n = BigInt3(N0, N1, N2);
let (k_n) = bigint_mul(k, n);

tempvar carry1 = (res_b.d0 - k_n.d0 - a.d0) / BASE;
assert [range_check_ptr + 0] = carry1 + 2 ** 127;

tempvar carry2 = (res_b.d1 - k_n.d1 - a.d1 + carry1) / BASE;
assert [range_check_ptr + 1] = carry2 + 2 ** 127;

tempvar carry3 = (res_b.d2 - k_n.d2 - a.d2 + carry2) / BASE;
assert [range_check_ptr + 2] = carry3 + 2 ** 127;

tempvar carry4 = (res_b.d3 - k_n.d3 + carry3) / BASE;
assert [range_check_ptr + 3] = carry4 + 2 ** 127;

assert res_b.d4 - k_n.d4 + carry4 = 0;

let range_check_ptr = range_check_ptr + 4;

return (res=res);
}

func test_div_mod_n{range_check_ptr: felt}() {
let a: BigInt3 = BigInt3(100, 99, 98);
let b: BigInt3 = BigInt3(10, 9, 8);

let (res) = div_mod_n(a, b);

assert res = BigInt3(
3413472211745629263979533, 17305268010345238170172332, 11991751872105858217578135
);

// test alternative hint
let (res_alt) = div_mod_n_alt(a, b);

assert res_alt = res;

return ();
}

func main{range_check_ptr: felt}() {
test_div_mod_n();

return ();
}
127 changes: 127 additions & 0 deletions cairo_programs/reduce.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
%builtins range_check

from starkware.cairo.common.cairo_secp.bigint import BigInt3, UnreducedBigInt3, nondet_bigint3

const BASE = 2 ** 86;
const SECP_REM = 19;

func verify_zero{range_check_ptr}(val: UnreducedBigInt3) {
let q = [ap];
%{
from starkware.cairo.common.cairo_secp.secp_utils import pack
SECP_P = 2**255-19
to_assert = pack(ids.val, PRIME)
q, r = divmod(pack(ids.val, PRIME), SECP_P)
assert r == 0, f"verify_zero: Invalid input {ids.val.d0, ids.val.d1, ids.val.d2}."
ids.q = q % PRIME
%}
let q_biased = [ap + 1];
q_biased = q + 2 ** 127, ap++;
[range_check_ptr] = q_biased, ap++;
// This implies that q is in the range [-2**127, 2**127).

tempvar r1 = (val.d0 + q * SECP_REM) / BASE;
assert [range_check_ptr + 1] = r1 + 2 ** 127;
// This implies that r1 is in the range [-2**127, 2**127).
// Therefore, r1 * BASE is in the range [-2**213, 2**213).
// By the soundness assumption, val.d0 is in the range (-2**250, 2**250).
// This implies that r1 * BASE = val.d0 + q * SECP_REM (as integers).

tempvar r2 = (val.d1 + r1) / BASE;
assert [range_check_ptr + 2] = r2 + 2 ** 127;
// Similarly, this implies that r2 * BASE = val.d1 + r1 (as integers).
// Therefore, r2 * BASE**2 = val.d1 * BASE + r1 * BASE.

assert val.d2 = q * (BASE / 8) - r2;
// Similarly, this implies that q * BASE / 4 = val.d2 + r2 (as integers).
// Therefore,
// q * BASE**3 / 4 = val.d2 * BASE**2 + r2 * BASE ** 2 =
// val.d2 * BASE**2 + val.d1 * BASE + r1 * BASE =
// val.d2 * BASE**2 + val.d1 * BASE + val.d0 + q * SECP_REM =
// val + q * SECP_REM.
// Hence, val = q * (BASE**3 / 4 - SECP_REM) = q * (2**256 - SECP_REM) = q * secp256k1_prime.

let range_check_ptr = range_check_ptr + 3;
return ();
}

// Receives an unreduced number, and returns a number that is equal to the original number mod
// Ed25519 prime and in reduced form (meaning every limb is in the range [0, BASE)).
//
// Completeness assumption: x's limbs are in the range (-2**210.99, 2**210.99).
// Soundness assumption: x's limbs are in the range (-2**249.99, 2**249.99).
func reduce_ed25519{range_check_ptr}(x: UnreducedBigInt3) -> (reduced_x: BigInt3) {
%{
from starkware.cairo.common.cairo_secp.secp_utils import pack
SECP_P=2**255-19

value = pack(ids.x, PRIME) % SECP_P
%}
let (reduced_x: BigInt3) = nondet_bigint3();

verify_zero(
UnreducedBigInt3(d0=x.d0 - reduced_x.d0, d1=x.d1 - reduced_x.d1, d2=x.d2 - reduced_x.d2)
);
return (reduced_x=reduced_x);
}

func test_reduce_ed25519{range_check_ptr}() {
let x = UnreducedBigInt3(0, 0, 0);
let (res) = reduce_ed25519(x);
assert res = BigInt3(0, 0, 0);

let x = UnreducedBigInt3(
1113660525233188137217661511617697775365785011829423399545361443,
1243997169368861650657124871657865626433458458266748922940703512,
1484456708474143440067316914074363277495967516029110959982060577,
);
let (res) = reduce_ed25519(x);
assert res = BigInt3(
42193159084937489098474581, 19864776835133205750023223, 916662843592479469328893
);

return ();
}

func reduce_v2{range_check_ptr}(x: UnreducedBigInt3) -> (reduced_x: BigInt3) {
let orig_x = x;
%{ from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_P as SECP_P %}
%{
from starkware.cairo.common.cairo_secp.secp_utils import pack
value = pack(ids.x, PRIME) % SECP_P
%}
let (reduced_x: BigInt3) = nondet_bigint3();

verify_zero(
UnreducedBigInt3(
d0=orig_x.d0 - reduced_x.d0,
d1=orig_x.d1 - reduced_x.d1,
d2=orig_x.d2 - reduced_x.d2
)
);
return (reduced_x=reduced_x);
}

func main{range_check_ptr}() {
test_reduce_ed25519();

// reduce_v2 tests
let x = UnreducedBigInt3(0, 0, 0);
let (reduce_v2_a) = reduce_v2(x);
assert reduce_v2_a = BigInt3(
0, 0, 0
);

let y = UnreducedBigInt3(12354, 745634534, 81298789312879123);
let (reduce_v2_b) = reduce_v2(y);
assert reduce_v2_b = BigInt3(
12354, 745634534, 81298789312879123
);

let z = UnreducedBigInt3(12354812987893128791212331231233, 7453123123123123312634534, 8129224990312325879);
let (reduce_v2_c) = reduce_v2(z);
assert reduce_v2_c = BigInt3(
16653320122975184709085185, 7453123123123123312794216, 8129224990312325879
);
return ();
}
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 ();
}
24 changes: 24 additions & 0 deletions cairo_programs/signature.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%builtins range_check

from starkware.cairo.common.cairo_secp.signature import div_mod_n, get_point_from_x
from starkware.cairo.common.cairo_secp.bigint import BigInt3

func main{range_check_ptr: felt}() {
let a: BigInt3 = BigInt3(100, 99, 98);
let b: BigInt3 = BigInt3(10, 9, 8);
let (res) = div_mod_n(a, b);
assert res.d0 = 3413472211745629263979533;
assert res.d1 = 17305268010345238170172332;
assert res.d2 = 11991751872105858217578135;

let x: BigInt3 = BigInt3(100, 99, 98);
let v: felt = 10;
let (point) = get_point_from_x(x, v);
assert point.x.d0 = 100;
assert point.x.d1 = 99;
assert point.x.d2 = 98;
assert point.y.d0 = 50471654703173585387369794;
assert point.y.d1 = 68898944762041070370364387;
assert point.y.d2 = 16932612780945290933872774;
return ();
}
5 changes: 2 additions & 3 deletions pkg/builtins/ec_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"

"github.com/lambdaclass/cairo-vm.go/pkg/lambdaworks"
"github.com/lambdaclass/cairo-vm.go/pkg/math_utils"
"github.com/lambdaclass/cairo-vm.go/pkg/utils"
"github.com/lambdaclass/cairo-vm.go/pkg/vm/memory"
"github.com/pkg/errors"
Expand Down Expand Up @@ -263,7 +262,7 @@ func LineSlope(point_a PartialSumB, point_b DoublePointB, prime big.Int) (big.In
n := new(big.Int).Sub(&point_a.Y, &point_b.Y)
m := new(big.Int).Sub(&point_a.X, &point_b.X)

z, err := math_utils.DivMod(n, m, &prime)
z, err := utils.DivMod(n, m, &prime)
if err != nil {
return big.Int{}, err
}
Expand Down Expand Up @@ -299,7 +298,7 @@ func EcDoubleSlope(point DoublePointB, alpha big.Int, prime big.Int) (big.Int, e
n.Add(n, &alpha)

m := new(big.Int).Mul(&point.Y, big.NewInt(2))
z, err := math_utils.DivMod(n, m, &prime)
z, err := utils.DivMod(n, m, &prime)

if err != nil {
return big.Int{}, err
Expand Down
Loading