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

Implemented EvalCircuit, Fixed bugs and wrote tests for Modbuiltin #669

Merged
merged 12 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
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 .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ jobs:
python-version: "3.9"

- name: Install cairo-lang
run: pip install cairo-lang==0.13.1
run: pip install cairo-lang==0.13.2

- name: Install sympy
run: pip install sympy==1.11.1
8 changes: 8 additions & 0 deletions pkg/hintrunner/core/cairo_hintparser.go
Original file line number Diff line number Diff line change
@@ -95,6 +95,14 @@ func GetHintByName(hint starknet.Hint) (hinter.Hinter, error) {
return &AllocSegment{
Dst: parseCellRefer(args.Dst),
}, nil
case starknet.EvalCircuitName:
args := hint.Args.(*starknet.EvalCircuit)
return &EvalCircuit{
AddModN: parseResOperand(args.NAddMods),
AddModPtr: parseResOperand(args.AddModPtr),
MulModN: parseResOperand(args.NMulMods),
MulModPtr: parseResOperand(args.MulModPtr),
}, nil
case starknet.TestLessThanName:
args := hint.Args.(*starknet.TestLessThan)
return &TestLessThan{
41 changes: 41 additions & 0 deletions pkg/hintrunner/core/hint.go
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import (
"github.com/NethermindEth/cairo-vm-go/pkg/parsers/starknet"
"github.com/NethermindEth/cairo-vm-go/pkg/utils"
VM "github.com/NethermindEth/cairo-vm-go/pkg/vm"
"github.com/NethermindEth/cairo-vm-go/pkg/vm/builtins"
mem "github.com/NethermindEth/cairo-vm-go/pkg/vm/memory"
f "github.com/consensys/gnark-crypto/ecc/stark-curve/fp"
)
@@ -56,6 +57,46 @@ func (hint *AllocSegment) Execute(vm *VM.VirtualMachine, _ *hinter.HintRunnerCon
return nil
}

type EvalCircuit struct {
AddModN hinter.Reference
AddModPtr hinter.Reference
MulModN hinter.Reference
MulModPtr hinter.Reference
}

func (hint *EvalCircuit) String() string {
return "EvalCircuit"
}

func (hint *EvalCircuit) Execute(vm *VM.VirtualMachine, _ *hinter.HintRunnerContext) error {
addModInputAddress, err := hinter.ResolveAsAddress(vm, hint.AddModPtr)
if err != nil {
return fmt.Errorf("resolve addModBuiltin pointer: %w", err)
}
nAddMods, err := hint.AddModN.Resolve(vm)
if err != nil {
return fmt.Errorf("resolve nAddMods operand %s: %v", hint.AddModN, err)
}
nAddModsFelt, err := nAddMods.Uint64()
if err != nil {
return err
}
mulModInputAddress, err := hinter.ResolveAsAddress(vm, hint.MulModPtr)
if err != nil {
return fmt.Errorf("resolve mulModBuiltin pointer: %w", err)
}
nMulMods, err := hint.MulModN.Resolve(vm)
if err != nil {
return fmt.Errorf("resolve nMulMods operand %s: %v", hint.MulModN, err)
}
nMulModsFelt, err := nMulMods.Uint64()
if err != nil {
return err
}

return builtins.FillMemory(vm.Memory, *addModInputAddress, nAddModsFelt, *mulModInputAddress, nMulModsFelt)
}

type TestLessThan struct {
dst hinter.Reference
lhs hinter.Reference
Loading