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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Implement is-zero assign scope variables
  • Loading branch information
fmoletta committed Oct 2, 2023
commit a1ba3b120e13b90bfda7cd845aba697b379bb704
5 changes: 5 additions & 0 deletions pkg/hints/hint_codes/secp_hint_codes.go
Original file line number Diff line number Diff line change
@@ -50,3 +50,8 @@ x = pack(ids.x, PRIME) % SECP_P`

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

const IS_ZERO_ASSIGN_SCOPE_VARS = `from starkware.cairo.common.cairo_secp.secp_utils import SECP_P
from starkware.python.math_utils import div_mod

value = x_inv = div_mod(1, x, SECP_P)`
2 changes: 2 additions & 0 deletions pkg/hints/hint_processor.go
Original file line number Diff line number Diff line change
@@ -227,6 +227,8 @@ func (p *CairoVmHintProcessor) ExecuteHint(vm *vm.VirtualMachine, hintData *any,
return isZeroNondet(data.Ids, vm)
case IS_ZERO_PACK_V1, IS_ZERO_PACK_V2:
return isZeroPack(data.Ids, vm, execScopes)
case IS_ZERO_ASSIGN_SCOPE_VARS:
return isZeroAssignScopeVars(execScopes)
default:
return errors.Errorf("Unknown Hint: %s", data.Code)
}
17 changes: 17 additions & 0 deletions pkg/hints/secp_hints.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
. "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/utils"
. "github.com/lambdaclass/cairo-vm.go/pkg/vm"
"github.com/lambdaclass/cairo-vm.go/pkg/vm/memory"
"github.com/pkg/errors"
@@ -106,3 +107,19 @@ func isZeroPack(ids IdsManager, vm *VirtualMachine, scopes *ExecutionScopes) err
scopes.AssignOrUpdateVariable("x", *xModP)
return nil
}

func isZeroAssignScopeVars(scopes *ExecutionScopes) error {
secpP := SECP_P()
scopes.AssignOrUpdateVariable("SECP_P", secpP)
x, err := FetchScopeVar[big.Int]("x", scopes)
if err != nil {
return err
}
value, err := utils.DivMod(big.NewInt(1), &x, &secpP)
if err != nil {
return err
}
scopes.AssignOrUpdateVariable("value", *value)
scopes.AssignOrUpdateVariable("x_inv", *value)
return nil
}
26 changes: 26 additions & 0 deletions pkg/hints/secp_hints_test.go
Original file line number Diff line number Diff line change
@@ -344,3 +344,29 @@ func TestIsZeroPack(t *testing.T) {
xUnpacked := Uint384{Limbs: []Felt{FeltFromUint(6), FeltFromUint(6), FeltFromUint(6)}}
CheckScopeVar[big.Int]("x", xUnpacked.Pack86(), scopes, t)
}

func TestIsZeroAssignScopeVars(t *testing.T) {
vm := NewVirtualMachine()
vm.Segments.AddSegment()
idsManager := SetupIdsForTest(map[string][]*MaybeRelocatable{}, vm)

hintProcessor := CairoVmHintProcessor{}
hintData := any(HintData{
Ids: idsManager,
Code: IS_ZERO_ASSIGN_SCOPE_VARS,
})
scopes := NewExecutionScopes()
x, _ := new(big.Int).SetString("52621538839140286024584685587354966255185961783273479086367", 10)
scopes.AssignOrUpdateVariable("x", *x)

err := hintProcessor.ExecuteHint(vm, &hintData, nil, scopes)
if err != nil {
t.Errorf("IS_ZERO_ASSIGN_SCOPE_VARS hint failed with error %s", err)
}
// Check scope vars
CheckScopeVar[big.Int]("SECP_P", SECP_P(), scopes, t)

value, _ := new(big.Int).SetString("19429627790501903254364315669614485084365347064625983303617500144471999752609", 10)
CheckScopeVar[big.Int]("value", *value, scopes, t)
CheckScopeVar[big.Int]("x_inv", *value, scopes, t)
}