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 REDUCE+ & VERIFY_ZERO+ hints #307

Merged
merged 120 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 119 commits
Commits
Show all changes
120 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
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
53e547f
Restore gitignore
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
e24ff99
Merge branch 'main' into secp-hints
fmoletta Oct 3, 2023
e109087
Implement `GET_POINT_FROM_X` hint (#298)
fmoletta Oct 5, 2023
e17ea84
Merge branch 'main' into secp-hints
pefontana Oct 5, 2023
4c1b132
Merge branch 'main' into secp-hints
pefontana Oct 23, 2023
02464df
Merge branch 'main' of github.com:lambdaclass/cairo-vm.go into HEAD
toni-calvin Oct 25, 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
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 ();
}
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 ();
}
39 changes: 39 additions & 0 deletions pkg/hints/hint_codes/secp_hint_codes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package hint_codes

const IMPORT_SECP256R1_ALPHA = "from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_ALPHA as ALPHA"

const IMPORT_SECP256R1_N = "from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_N as N"

const IMPORT_SECP256R1_P = "from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_P as SECP_P"

const VERIFY_ZERO_EXTERNAL_SECP = "from starkware.cairo.common.cairo_secp.secp_utils import pack\n\nq, r = divmod(pack(ids.val, PRIME), SECP_P)\nassert r == 0, f\"verify_zero: Invalid input {ids.val.d0, ids.val.d1, ids.val.d2}.\"\nids.q = q % PRIME"

const REDUCE_V1 = `from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack

value = pack(ids.x, PRIME) % SECP_P`

const REDUCE_V2 = `from starkware.cairo.common.cairo_secp.secp_utils import pack
value = pack(ids.x, PRIME) % SECP_P`

const REDUCE_ED25519 = `from starkware.cairo.common.cairo_secp.secp_utils import pack
SECP_P=2**255-19

value = pack(ids.x, PRIME) % SECP_P`

const VERIFY_ZERO_V1 = `from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack

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`

const VERIFY_ZERO_V2 = `from starkware.cairo.common.cairo_secp.secp_utils import SECP_P
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`

const VERIFY_ZERO_V3 = `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`
6 changes: 0 additions & 6 deletions pkg/hints/hint_codes/secp_p_hint.go

This file was deleted.

12 changes: 12 additions & 0 deletions pkg/hints/hint_codes/signature_hint_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ const DIV_MOD_N_SAFE_DIV = "value = k = safe_div(res * b - a, N)"
const DIV_MOD_N_SAFE_DIV_PLUS_ONE = "value = k_plus_one = safe_div(res * b - a, N) + 1"

const XS_SAFE_DIV = "value = k = safe_div(res * s - x, N)"

const GET_POINT_FROM_X = `from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack

x_cube_int = pack(ids.x_cube, PRIME) % SECP_P
y_square_int = (x_cube_int + ids.BETA) % SECP_P
y = pow(y_square_int, (SECP_P + 1) // 4, SECP_P)

# We need to decide whether to take y or SECP_P - y.
if ids.v % 2 == y % 2:
value = y
else:
value = (-y) % SECP_P`
13 changes: 13 additions & 0 deletions pkg/hints/hint_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

. "github.com/lambdaclass/cairo-vm.go/pkg/hints/hint_codes"
"github.com/lambdaclass/cairo-vm.go/pkg/hints/hint_utils"
. "github.com/lambdaclass/cairo-vm.go/pkg/hints/hint_utils"
. "github.com/lambdaclass/cairo-vm.go/pkg/lambdaworks"
"github.com/lambdaclass/cairo-vm.go/pkg/parser"
Expand Down Expand Up @@ -218,6 +219,8 @@ func (p *CairoVmHintProcessor) ExecuteHint(vm *vm.VirtualMachine, hintData *any,
return divModNSafeDiv(data.Ids, execScopes, "a", "b", false)
case DIV_MOD_N_SAFE_DIV_PLUS_ONE:
return divModNSafeDiv(data.Ids, execScopes, "a", "b", true)
case GET_POINT_FROM_X:
return getPointFromX(data.Ids, vm, execScopes, constants)
case VERIFY_ZERO_EXTERNAL_SECP:
return verifyZeroWithExternalConst(*vm, *execScopes, data.Ids)
case FAST_EC_ADD_ASSIGN_NEW_X:
Expand All @@ -228,6 +231,16 @@ func (p *CairoVmHintProcessor) ExecuteHint(vm *vm.VirtualMachine, hintData *any,
return fastEcAddAssignNewX(data.Ids, vm, execScopes, "pt0", "pt1", SECP_P())
case FAST_EC_ADD_ASSIGN_NEW_Y:
return fastEcAddAssignNewY(execScopes)
case REDUCE_V1:
return reduceV1(data.Ids, vm, execScopes)
case REDUCE_V2:
return reduceV2(data.Ids, vm, execScopes)
case REDUCE_ED25519:
return reduceED25519(data.Ids, vm, execScopes)
case VERIFY_ZERO_V1, VERIFY_ZERO_V2:
return verifyZero(data.Ids, vm, execScopes, hint_utils.SECP_P())
case VERIFY_ZERO_V3:
return verifyZero(data.Ids, vm, execScopes, hint_utils.SECP_P_V2())
default:
return errors.Errorf("Unknown Hint: %s", data.Code)
}
Expand Down
64 changes: 64 additions & 0 deletions pkg/hints/secp_hints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package hints

import (
"math/big"

. "github.com/lambdaclass/cairo-vm.go/pkg/hints/hint_utils"
"github.com/lambdaclass/cairo-vm.go/pkg/lambdaworks"
. "github.com/lambdaclass/cairo-vm.go/pkg/types"
. "github.com/lambdaclass/cairo-vm.go/pkg/vm"
"github.com/lambdaclass/cairo-vm.go/pkg/vm/memory"
"github.com/pkg/errors"
)

func reduceV1(ids IdsManager, vm *VirtualMachine, scopes *ExecutionScopes) error {
secpP := SECP_P()
scopes.AssignOrUpdateVariable("SECP_P", secpP)
value, err := Uint384FromVarName("x", ids, vm)
if err != nil {
return err
}
packedValue := value.Pack86()
scopes.AssignOrUpdateVariable("value", *new(big.Int).Mod(&packedValue, &secpP))
return nil
}

func reduceV2(ids IdsManager, vm *VirtualMachine, scopes *ExecutionScopes) error {
secpP, err := FetchScopeVar[big.Int]("SECP_P", scopes)
if err != nil {
return err
}
value, err := Uint384FromVarName("x", ids, vm)
if err != nil {
return err
}
packedValue := value.Pack86()
scopes.AssignOrUpdateVariable("value", *new(big.Int).Mod(&packedValue, &secpP))
return nil
}

func reduceED25519(ids IdsManager, vm *VirtualMachine, scopes *ExecutionScopes) error {
secpP := SECP_P_V2()
scopes.AssignOrUpdateVariable("SECP_P", secpP)
value, err := Uint384FromVarName("x", ids, vm)
if err != nil {
return err
}
packedValue := value.Pack86()
scopes.AssignOrUpdateVariable("value", *new(big.Int).Mod(&packedValue, &secpP))
return nil
}

func verifyZero(ids IdsManager, vm *VirtualMachine, scopes *ExecutionScopes, secpP big.Int) error {
scopes.AssignOrUpdateVariable("SECP_P", secpP)
valUnpacked, err := Uint384FromVarName("val", ids, vm)
if err != nil {
return err
}
val := valUnpacked.Pack86()
q, r := new(big.Int).DivMod(&val, &secpP, new(big.Int))
if r.Cmp(big.NewInt(0)) != 0 {
return errors.Errorf("verify_zero: Invalid input %s", val.Text(10))
}
return ids.Insert("q", memory.NewMaybeRelocatableFelt(lambdaworks.FeltFromBigInt(q)), vm)
}
Loading
Loading