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

Cairo1 runner fixes #675

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Cairo1 runner fixes #675

wants to merge 13 commits into from

Conversation

MaksymMalicki
Copy link
Contributor

No description provided.

@MaksymMalicki MaksymMalicki changed the title Fixes for the generation of entry code, fixes of hints parsing Entry code generation fix Nov 21, 2024
@MaksymMalicki MaksymMalicki changed the title Entry code generation fix Cairo1 runner fixes Dec 10, 2024
@MaksymMalicki
Copy link
Contributor Author

MaksymMalicki commented Dec 10, 2024

Current changes in the existing code feature:

General:

  1. Bump of version of go from 1.20 -> 1.21
  2. Updates of the Makefile make integration command, so that it builds the nesseccary binaries for integration tests

cmd/cli/main.go:

  1. Reading and parsing entrypoint arguments and gas
  2. Loading gas and entrypoint arguments to the execution segment after builtins pointer
  3. Shifting the keys in the hintmap by the size of entry code instructions

integration_tests/cairo_vm_test.go:

  1. Fixes in the names of few of integration tests, so that they point to the correct layout
  2. Writing the missing integration tests to the file
  3. Restructuring of the file, so that the python VM is being run only for zero integration tests

pkg/hintrunner/core/cairo_hintparser.go, pkg/hintrunner/core/hint.go, pkg/hintrunner/core/hint_test.go, pkg/parsers/starknet/hint.go:

  1. Corrections in parsing of Uint256InvModN
  2. Introduction of ExternalWriteArgsToMemoryHint, which allows to easily write the input params to memory at given step, without if statements

pkg/hintrunner/hintrunner.go:

  1. Writing userArgs to the scope of the ExternalWriteArgsToMemoryHint, so that they can be retrieved by the hint in the future

pkg/parsers/starknet/args.go, pkg/parsers/starknet/args_test.go:

  1. Parsing of user input args and tests (only single values and arrays, does not support nesting)

pkg/runner/gas.go:

  1. Introduces the additional initialization steps to the VM, including adding a pointer to the gas costs segment to the end of the program segment and writing gas costs of listed tokens to that segment (necessary for proper working of gas)

pkg/runner/runner.go:

  1. Various cairo runner modes: Execution and Proof for cairo0 and cairo1
  2. AssembleProgram - prepend entry code instructions and append footer instructions to the bytecode, shift hints ids accordingly
  3. Add proper entry point initialization for Execution and Proof mode for Cairo1
  4. Add proper initialization of builtins for Cairo1 (creating a builtin segment only when builtin is present both in layout and program builtins list
  5. Generation of entry code for cairo1 - code refactoring for paramTypes handling, fixes in calculation of offset for call method in the entry code, proper handling of gas builtin

pkg/vm/vm.go:

  1. Add helper, debug PrintMemory() method

MaksymMalicki and others added 7 commits December 25, 2024 21:55
* Add parsing logic for input user args

* Add flags for available gas, input user args, writing args to memory

* Fix unit tests for user arguments parsing

* Lint the PR

* Add user args to hint context

* Refactor the code

* Fix unconditional append of ExternalWriteArgsToMemory, bug fixes in integration tests

* Add fixes of the call size calculation and include ExternalWriteArgsToMemory hint when gas present

* Add layouts for integration tests

* Add error handling

* Fixes in entry code generation

* Address changes mentioned in a discussion

* Add comment regarding writing to memory in a hint for the future reference in the integration tests with args

* Changes in calculations of the initial PC offset, CALL opcode offset incremented by mainFuncOffset, writing user args to the AP in the hint

* Turn back VM config to private field

* Add error handling on assign of `userArgs` to the initial scope

* Lint project

* Bump go version from 1.20 -> 1.21 (#678)

* Bump go version from 1.20 -> 1.21

* Update golangci-lint

* Simplify the Makefile

* Correction in the makefile
@@ -182,7 +179,7 @@ func TestCairoFiles(t *testing.T) {
{"./cairo_zero_hint_tests/", true},
{"./cairo_zero_file_tests/", true},
{"./builtin_tests/", true},
// {"./cairo_1_programs/", false},
{"./cairo_1_programs/", false},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you'll need to leave the comment here, as the tests are not passing yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

if userArgs != nil {
err := context.ScopeManager.AssignVariable("userArgs", userArgs)
if err != nil {
panic(fmt.Errorf("assign userArgs: %v", err))
Copy link
Contributor

@cicr99 cicr99 Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave a comment here that this line should not be reachable since the context was just initialized above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 7 to 8
"github.com/NethermindEth/cairo-vm-go/pkg/vm/memory"
mem "github.com/NethermindEth/cairo-vm-go/pkg/vm/memory"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why both? I would use the one without the alias only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


const (
ConstToken TokenGasCost = iota + 1
HoleToken
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using this one? The rest I understand refer to builtins but I think for this one if you are going to leave it here then you should add a comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for ConstToken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is not necessary for now, removed the unused tokens

MulModToken
)

func getTokenGasCost(token TokenGasCost) (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I know these values come from the rust vm, could you pls add a comment with a link to the source?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@@ -25,6 +25,7 @@ const (
AddModeType
MulModType
GasBuiltinType
SystemType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this one refer to? I see you only use it in emulatedBuiltins?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, this is something I thought might be useful in the future, but it turned out not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants