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

bug: RustVM initiates builtins on a specific order that might not match the program's #502

Closed
enitrat opened this issue Jan 21, 2025 · 0 comments · Fixed by #525
Closed
Assignees

Comments

@enitrat
Copy link
Collaborator

enitrat commented Jan 21, 2025

In runner.py, we have two different cases depenending on the VM used:

  • PyVM:
        for builtin_runner in runner.builtin_runners.values():
            builtin_runner.initialize_segments(runner)


        # Handle builtins
        for builtin_arg in _builtins:
            builtin_runner = runner.builtin_runners.get(
                builtin_arg.replace("_ptr", "_builtin")
            )
            if builtin_runner is None:
                raise ValueError(f"Builtin runner {builtin_arg} not found")
            stack.extend(builtin_runner.initial_stack())
            add_output = "output" in builtin_arg
            if add_output:
                output_ptr = stack[-1]

  • RustVM:
        # Must be done right after runner creation to make sure the execution base is 1
        # See https://github.com/lambdaclass/cairo-vm/issues/1908
        runner.initialize_segments()

This will cause an issue regarding the way we manage our builtins:

  1. The PythonVM will initialize the builtins in the same order as the program's builtins, because we collect them in the same way
  2. The RustVM has a specific preset of builtin orders:
        let builtin_ordered_list = vec![
            BuiltinName::output,
            BuiltinName::pedersen,
            BuiltinName::range_check,
            BuiltinName::ecdsa,
            BuiltinName::bitwise,
            BuiltinName::ec_op,
            BuiltinName::keccak,
            BuiltinName::poseidon,
            BuiltinName::range_check96,
            BuiltinName::add_mod,
            BuiltinName::mul_mod,
        ];

Thus, if a program has e.g. {bitwise_ptr, range_check_ptr}, then the RustVM will assign them segments 3 and 2, but the program will expect them to be in segments 2 and 3.

@github-project-automation github-project-automation bot moved this to Backlog in Keth Jan 21, 2025
@enitrat enitrat self-assigned this Jan 23, 2025
enitrat added a commit that referenced this issue Jan 23, 2025
Closes #502

---------

Co-authored-by: Oba <[email protected]>
Co-authored-by: Clément Walter <[email protected]>
@github-project-automation github-project-automation bot moved this from Backlog to Done in Keth Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant