-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add is_positive felt method * implement memcpy_continue_copying hint * fix test * fix hint * add failing test * add hint * add test to memcpy_continue_copying hint * improve imports in hints * abstract error * add aux utils methods * change from MaybeRelocatable to Felt when returning n identifier * add tests * add continue loop hint * use utils method for adding segments * fix memcpy_continue_coding hint code Co-authored-by: Juan-M-V <[email protected]> * improve returned value in memset_step_loop method Co-authored-by: fmoletta <[email protected]> * delete GetRef method fromexecScopes * Revert "delete GetRef method fromexecScopes" This reverts commit 9efe91f. * Revert "Revert "delete GetRef method fromexecScopes"" This reverts commit ad0c563. * improve error message * improve tests * add integration tests * Merge branch 'main' of github.com:lambdaclass/cairo-vm.go into memcpy-hints --------- Co-authored-by: Juan-M-V <[email protected]> Co-authored-by: fmoletta <[email protected]>
- Loading branch information
1 parent
6f45961
commit 64dcc86
Showing
17 changed files
with
496 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.memcpy import memcpy | ||
from starkware.cairo.common.registers import get_fp_and_pc | ||
|
||
func main() { | ||
alloc_locals; | ||
let (__fp__, _) = get_fp_and_pc(); | ||
local numbers: (felt, felt, felt) = (1, 2, 3); | ||
let dest: felt* = alloc(); | ||
memcpy(dst=dest, src=&numbers, len=3); | ||
assert numbers[0] = dest[0]; | ||
assert numbers[1] = dest[1]; | ||
assert numbers[2] = dest[2]; | ||
return (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.memset import memset | ||
from starkware.cairo.common.bool import TRUE, FALSE | ||
|
||
func check_array(array: felt*, value: felt, array_length: felt, iterator: felt) -> (r: felt) { | ||
if (iterator == array_length) { | ||
return (TRUE,); | ||
} | ||
if (array[iterator] != value) { | ||
return (FALSE,); | ||
} | ||
return check_array(array, value, array_length, iterator + 1); | ||
} | ||
|
||
func main() { | ||
alloc_locals; | ||
let (local strings: felt*) = alloc(); | ||
memset(strings, 'Lambda', 20); | ||
let check_string: felt = check_array(strings, 'Lambda', 20, 0); | ||
assert check_string = TRUE; | ||
assert strings[20] = 'can insert new value'; | ||
let numbers: felt* = alloc(); | ||
memset(numbers, 10, 100); | ||
let check_string: felt = check_array(numbers, 10, 100, 0); | ||
assert check_string = TRUE; | ||
assert numbers[100] = 11; | ||
return (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package hints | ||
|
||
const MEMSET_ENTER_SCOPE = "vm_enter_scope({'n': ids.n})" | ||
const MEMSET_CONTINUE_LOOP = "n -= 1\nids.continue_loop = 1 if n > 0 else 0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package hints | ||
|
||
import ( | ||
. "github.com/lambdaclass/cairo-vm.go/pkg/hints/hint_utils" | ||
. "github.com/lambdaclass/cairo-vm.go/pkg/types" | ||
. "github.com/lambdaclass/cairo-vm.go/pkg/vm" | ||
) | ||
|
||
// Implements hint: | ||
// %{ vm_enter_scope({'n': ids.n}) %} | ||
func memset_enter_scope(ids IdsManager, vm *VirtualMachine, execScopes *ExecutionScopes) error { | ||
n, err := ids.GetFelt("n", vm) | ||
if err != nil { | ||
return err | ||
} | ||
execScopes.EnterScope(map[string]interface{}{"n": n}) | ||
return nil | ||
} |
Oops, something went wrong.