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 proof_mode functionalities #682

Merged
merged 50 commits into from
Feb 14, 2025
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d7b74e6
Fixes for the generation of entry code, fixes of hints parsing
MaksymMalicki Nov 15, 2024
dfd9ec8
Add modifications to the runner
MaksymMalicki Nov 21, 2024
a7814a1
Merge branch 'main' into add_code_entry
MaksymMalicki Dec 2, 2024
83872d8
Add fixes for the entrycode generation
MaksymMalicki Dec 3, 2024
cd04099
Refactor main CLI, offset the hints indexes by entry code size, load …
MaksymMalicki Dec 10, 2024
5eb27ab
Add available gas and user args (#677)
MaksymMalicki Dec 25, 2024
8812042
Fix the integration tests
MaksymMalicki Dec 26, 2024
78cf788
Fixes in the runner
MaksymMalicki Dec 27, 2024
af47a3d
Fixes in the runner
MaksymMalicki Dec 28, 2024
73f6dd5
Fix the unit tests, uncomment pythonVm execution in integration tests…
MaksymMalicki Dec 28, 2024
17b17df
Add writing tokens gas cost to memory
MaksymMalicki Jan 7, 2025
688b3d2
Proper builtins initialization for cairo mode
MaksymMalicki Jan 8, 2025
f105506
Address comments in the PR
MaksymMalicki Jan 9, 2025
cc82938
Fix bugs regarding dicts
MaksymMalicki Jan 10, 2025
a32add7
Remove prints
MaksymMalicki Jan 10, 2025
07f4016
Merge branch 'main' into missing_dict_functionalities
MaksymMalicki Jan 10, 2025
53d4190
Fixes of the last tests for the dicts
MaksymMalicki Jan 11, 2025
31aeeed
Add dict_non_squashed dir to the integration tests
MaksymMalicki Jan 11, 2025
086011a
Add checks for the matching args size, rename files, modify the integ…
MaksymMalicki Jan 11, 2025
fc09b66
Almost all pass
MaksymMalicki Jan 13, 2025
72b3c14
Fix lint and unit tests
MaksymMalicki Jan 13, 2025
ce93d4f
Fix loading gas to the memory as an argument
MaksymMalicki Jan 15, 2025
734d1e7
Fix run for tensor__small.cairo
MaksymMalicki Jan 16, 2025
b54e9bb
Merge branch 'main' into inputs
MaksymMalicki Jan 16, 2025
c511329
check for input and output types for proofmode
MaksymMalicki Jan 17, 2025
74c2110
Implementation for entry code
MaksymMalicki Jan 23, 2025
6883060
Implement inline casm for segment arena
MaksymMalicki Jan 23, 2025
b757a2e
Merge branch 'main' into proof_mode
MaksymMalicki Jan 23, 2025
8d50465
Lint the project
MaksymMalicki Jan 23, 2025
78d3bbc
remove system type
MaksymMalicki Jan 23, 2025
eeef9a2
Modifications for the runner
MaksymMalicki Jan 25, 2025
b1a2881
Add relocate all dictionaries hint
MaksymMalicki Jan 29, 2025
4fc752b
allocate empty segment
MaksymMalicki Jan 29, 2025
6a71d5d
Implement dict relocation
MaksymMalicki Jan 29, 2025
71d2c33
Lint project, add hint to the entry code
MaksymMalicki Jan 29, 2025
6504516
Merge branch 'main' into proof_mode
MaksymMalicki Jan 31, 2025
bd040d8
Fixes in the runner for the proofmode
MaksymMalicki Feb 10, 2025
8793737
enable tests
MaksymMalicki Feb 10, 2025
b5eff91
adjust the builtins offsets by ret types
MaksymMalicki Feb 11, 2025
bcc6003
Merge branch 'main' into proof_mode
MaksymMalicki Feb 11, 2025
86d12d5
Modify integration tests structure, so it uses new fork
MaksymMalicki Feb 11, 2025
2205014
Merge branch 'proof_mode' of https://github.com/NethermindEth/cairo-v…
MaksymMalicki Feb 11, 2025
de1de03
Fixes for the integration tests, implement IsZero for memory value, a…
MaksymMalicki Feb 12, 2025
fda45ef
Add layouts to the integration tests, modify the args of integration …
MaksymMalicki Feb 13, 2025
2ca49b0
Address PR comments
MaksymMalicki Feb 13, 2025
396cb37
Refactor cairo1 integration tests, to do the directory tree lookup
MaksymMalicki Feb 13, 2025
1e2d928
Merge branch 'main' into proof_mode
MaksymMalicki Feb 13, 2025
f40cf39
Fix linter issues
MaksymMalicki Feb 14, 2025
750beca
CI fix
MaksymMalicki Feb 14, 2025
ed1bfd7
Fix makefile
MaksymMalicki Feb 14, 2025
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
Fix bugs regarding dicts
MaksymMalicki committed Jan 10, 2025
commit cc8293808176da41aca1447a374f5df07c8d7a76
22 changes: 16 additions & 6 deletions pkg/hintrunner/core/hint.go
Original file line number Diff line number Diff line change
@@ -1153,7 +1153,8 @@ func (hint *Felt252DictEntryInit) Execute(vm *VM.VirtualMachine, ctx *hinter.Hin

prevValue, err := ctx.DictionaryManager.At(dictPtr, key)
if err != nil {
return fmt.Errorf("get dictionary entry: %w", err)
mv := mem.MemoryValueFromFieldElement(&utils.FeltZero)
prevValue = &mv
}
if prevValue == nil {
mv := mem.EmptyMemoryValueAsFelt()
@@ -1245,6 +1246,7 @@ func (hint *InitSquashData) String() string {

func (hint *InitSquashData) Execute(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error {
// todo(rodro): Don't know if it could be called multiple times, or
fmt.Println(ctx.SquashedDictionaryManager.Keys, ctx.SquashedDictionaryManager.KeyToIndices)
err := hinter.InitializeSquashedDictionaryManager(ctx)
if err != nil {
return err
@@ -1282,7 +1284,7 @@ func (hint *InitSquashData) Execute(vm *VM.VirtualMachine, ctx *hinter.HintRunne

// sort the keys in descending order
sort.Slice(ctx.SquashedDictionaryManager.Keys, func(i, j int) bool {
return ctx.SquashedDictionaryManager.Keys[i].Cmp(&ctx.SquashedDictionaryManager.Keys[j]) < 0
return ctx.SquashedDictionaryManager.Keys[i].Cmp(&ctx.SquashedDictionaryManager.Keys[j]) > 0
})

// if the first key is bigger than 2^128, signal it
@@ -1411,11 +1413,15 @@ func (hint *ShouldContinueSquashLoop) Execute(vm *VM.VirtualMachine, ctx *hinter
}

var shouldContinueLoop f.Element
if lastIndices, err := ctx.SquashedDictionaryManager.LastIndices(); err == nil && len(lastIndices) <= 1 {
shouldContinueLoop.SetOne()
} else if err != nil {
lastIndices, err := ctx.SquashedDictionaryManager.LastIndices()
if err != nil {
return fmt.Errorf("get last indices: %w", err)
}
if len(lastIndices) > 1 {
shouldContinueLoop.SetOne()
} else {
shouldContinueLoop.SetZero()
}

mv := mem.MemoryValueFromFieldElement(&shouldContinueLoop)
return vm.Memory.WriteToAddress(&shouldContinuePtr, &mv)
@@ -1435,11 +1441,15 @@ func (hint *GetNextDictKey) Execute(vm *VM.VirtualMachine, ctx *hinter.HintRunne
return fmt.Errorf("get next key address: %w", err)
}

nextKey, err := ctx.SquashedDictionaryManager.PopKey()
_, err = ctx.SquashedDictionaryManager.PopKey()
if err != nil {
return fmt.Errorf("pop key: %w", err)
}

nextKey, err := ctx.SquashedDictionaryManager.LastKey()
if err != nil {
return fmt.Errorf("get last key: %w", err)
}
mv := mem.MemoryValueFromFieldElement(&nextKey)
return vm.Memory.WriteToAddress(&nextKeyAddr, &mv)
}
44 changes: 39 additions & 5 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
@@ -316,6 +316,9 @@ func (runner *Runner) initializeVm(
// run until the program counter equals the `pc` parameter
func (runner *Runner) RunUntilPc(pc *mem.MemoryAddress) error {
for !runner.vm.Context.Pc.Equal(pc) {
if runner.vm.Context.Pc.Offset == 166 {
runner.vm.PrintMemory()
}
if runner.steps() >= runner.maxsteps {
return fmt.Errorf(
"pc %s step %d: max step limit exceeded (%d)",
@@ -541,13 +544,46 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, finalizeFo
}

ctx := &InlineCasmContext{}

gotSegmentArena := false
for _, builtin := range function.Builtins {
if builtin == builtins.SegmentArenaType {
gotSegmentArena = true
}
}

hints := make(map[uint64][]hinter.Hinter)

if gotSegmentArena {
hints[uint64(ctx.currentCodeOffset)] = []hinter.Hinter{
&core.AllocSegment{
Dst: hinter.ApCellRef(0),
},
&core.AllocSegment{
Dst: hinter.ApCellRef(1),
},
}
ctx.AddInlineCASM(
"[ap+2] = 0, ap++;",
)
ctx.AddInlineCASM(
"[ap] = [[ap-1]], ap++;",
)
ctx.AddInlineCASM(
`
[ap] = [[ap-2]+1], ap++;
[ap-1] = [[ap-3]+2];
`,
)
apOffset += 3
}

paramsSize := 0
for _, param := range paramTypes {
paramsSize += param.Size
}
apOffset += paramsSize
usedArgs := 0
var hints map[uint64][]hinter.Hinter
for _, builtin := range function.Builtins {
if offset, isBuiltin := builtinsOffsetsMap[builtin]; isBuiltin {
ctx.AddInlineCASM(
@@ -561,10 +597,8 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, finalizeFo
)
apOffset += 1
} else if builtin == builtins.GasBuiltinType {
hints = map[uint64][]hinter.Hinter{
uint64(ctx.currentCodeOffset): {
&core.ExternalWriteArgsToMemory{},
},
hints[uint64(ctx.currentCodeOffset)] = []hinter.Hinter{
&core.ExternalWriteArgsToMemory{},
}
ctx.AddInlineCASM("ap += 1;")
apOffset += 1