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

fix: Identifier retdata is not relocatable #393

Merged
merged 29 commits into from
Oct 18, 2024

Conversation

whichqua
Copy link
Collaborator

@whichqua whichqua commented Oct 2, 2024

Problem:
This issue occurs with the following conditions

  1. deploy_contract is called inside an invoke tx.
  2. The contract being deployed has empty calldata array.

Solution:

Rc::new(os_input)

Note that this PR also wraps the os_input in a Rc. This was necessary(-ish) so that the deploy syscall could inspect the class info, but it should also have a big improvement to performance. See 3ddd5ef (and 8562944).

Issue Number: #392

Type

  • feature
  • bugfix
  • dev (no functional changes, no API changes)
  • fmt (formatting, renaming)
  • build
  • docs
  • testing

Description

Breaking changes?

  • yes
  • no

ftheirs and others added 18 commits October 9, 2024 09:47
* point to snos_requirements branch

* fix inconsistent hash

* add blocks to CI
The reference PIE was created with `full_output` enabled, so `output.rs` was updated to support that. The code was refactored to better mirror the Cairo serialization code.

Co-authored-by: Herman Obst Demaestri <hodemaestri@gmail.com>
…ion (#391)

* debug : prints added for blob

* debug : prints added for blob

* debug : prints added for blob

* debug : prints added for blob

* fix: fixed split commitment function

* fix: fixed split commitment function

* fix: fixed split commitment function

* feat : removed logs

* fix : lint and clippy

* test : added a test for split commitment function

* feat : requested changes done

* chore : added constants for hardcoded values

---------

Co-authored-by: Herman Obst Demaestri <70286869+HermanObst@users.noreply.github.com>
Copy link
Collaborator Author

@whichqua whichqua left a comment

Choose a reason for hiding this comment

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

I have left a small fix to help avoid a specific clone.
Regarding the Rc I gave it a try to remove it and I keep experiencing a borrow checker issue, so I am ok with it now. We can discuss that later.

crates/starknet-os/src/execution/syscall_handler.rs Outdated Show resolved Hide resolved
@@ -28,6 +29,7 @@ where
PCS: PerContractStorage,
{
pub _prev_block_context: Option<BlockContext>,
pub os_input: Option<Rc<StarknetOsInput>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@notlesh why do you need this to be a Rc?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That avoids cloning it, which is the part of this PR that improves performance

Copy link
Collaborator

Choose a reason for hiding this comment

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

To elaborate: the OsInput is now used in both ExecutionHelper and in run_os() so this avoids having to have two copies of it in those cases

Comment on lines +338 to +344
if response.need_retdata_hack {
log::warn!("Writing Felt::ZERO instead of pointer since retdata size is 0");
write_felt(vm, ptr, Felt252::ZERO)?; // casted pointer
write_felt(vm, ptr, Felt252::ZERO)?; // size
} else {
write_segment(vm, ptr, response.constructor_retdata)?;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@notlesh could this be handled in cairo-vm?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Which part? The syscall is specific to the OS.

If you mean the underlying problem (which is that cast(0, felt*) is represented by cairo-vm as an Int(0) then yes, I think that could be an upstream bug, but I'm not sure. It's worth asking about...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, exactly that

crates/starknet-os/src/hints/execution.rs Outdated Show resolved Hide resolved
crates/starknet-os/src/hints/execution.rs Outdated Show resolved Hide resolved
@@ -1119,6 +1121,21 @@ pub fn check_new_deploy_response(
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
let response_ptr = get_ptr_from_var_name(vars::ids::RESPONSE, vm, ids_data, ap_tracking)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@notlesh cant we use the "need_retdata_hack" here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think so. The need_retdata_hack is part of the syscall struct, which has disappeared by this point. It's possible that we could write something to the vm to use later, but I think that's a bad idea.

@HermanObst HermanObst merged commit 662d170 into main Oct 18, 2024
6 checks passed
@HermanObst HermanObst deleted the gm/retdata-is-not-relocatable branch October 18, 2024 21:27
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.

6 participants