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: deploy syscall address registry #4489

Merged
merged 4 commits into from
Nov 28, 2023

Conversation

enitrat
Copy link
Contributor

@enitrat enitrat commented Nov 27, 2023

Fixes #4488


This change is Reviewable

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @enitrat)

a discussion (no related file):
Add a tests in cairo-lang-starknet/cairo-level-tests.



crates/cairo-lang-runner/src/casm_run/mod.rs line 984 at r1 (raw file):

                Ok(value) => value,
                Err(mut revert_reason) => {
                    fail_syscall!(revert_reason, b"CONSTRUCTOR_FAILED");

I would assume this failure should revert the deployment as well.

Copy link
Contributor Author

@enitrat enitrat left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 2 unresolved discussions (waiting on @orizi)

a discussion (no related file):

Previously, orizi wrote…

Add a tests in cairo-lang-starknet/cairo-level-tests.

Done. Also tested that before the changes, the test failed with

failures:
   cairo_level_tests::deployment::test_deploy_in_construct - Panicked with 0x666163746f7279206465706c6f796d656e74206661696c6564 ('factory deployment failed').

Error: test result: FAILED. 47 passed; 1 failed; 0 ignored

Now, it passes.



crates/cairo-lang-runner/src/casm_run/mod.rs line 984 at r1 (raw file):

Previously, orizi wrote…

I would assume this failure should revert the deployment as well.

Done.

@ilyalesokhin-starkware
Copy link
Contributor

crates/cairo-lang-starknet/cairo_level_tests/deployment.cairo line 30 at r2 (raw file):

        let (address, _) = deploy_syscall(child_hash.try_into().unwrap(), 0, calldata.span(), false)
            .expect('child deployment failed');
        // The child contract is deployed, but the following line fails without propagating an error.

Is this fixed following this PR?

Code quote:

 // The child contract is deployed, but the following line fails without propagating an error.

Copy link
Contributor Author

@enitrat enitrat left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi)


crates/cairo-lang-starknet/cairo_level_tests/deployment.cairo line 30 at r2 (raw file):

Previously, ilyalesokhin-starkware wrote…

Is this fixed following this PR?

oops - sorry, I missed this comment. Yes, it's fixed following this PR and the test passes correctly.

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 3 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @orizi)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @enitrat)


crates/cairo-lang-starknet/cairo_level_tests/deployment.cairo line 74 at r3 (raw file):

    let res = IFactoryDispatcher { contract_address: starknet_address }.get_value();
    assert(res == 1, 'factory value is not 1')
}

Suggestion:

use core::result::ResultTrait;
use starknet::deploy_syscall;

#[starknet::interface]
trait IValue<TContractState> {
    fn get_value(self: @TContractState) -> felt252;
    fn set_value(ref self: TContractState, value: felt252);
}

#[starknet::contract]
mod self_caller {
    use core::traits::TryInto;
    use starknet::{ClassHash, deploy_syscall};
    use super::{IValueDispatcher, IValueDispatcherTrait};
    #[storage]
    struct Storage {
        value: felt252,
    }

    #[constructor]
    fn constructor(ref self: ContractState) {
        IValueDispatcher { contract_address: starknet::get_contract_address() }.set_value(1);
    }

    #[abi(embed_v0)]
    impl ValueImpl of super::IValue<ContractState> {
        fn get_value(self: @ContractState) -> felt252 {
            self.value.read()
        }

        fn set_value(ref self: ContractState, value: felt252) {
            self.value.write(value);
        }
    }
}

#[test]
fn test_deploy_in_construct() {
    let (contract_address, _) = deploy_syscall(
        self_caller::TEST_CLASS_HASH.try_into().unwrap(), 0, array![].span(), false
    )
        .expect('deployment failed');
    assert!(IValueDispatcher { contract_address }.get_value() == 1);
}

Copy link
Contributor Author

@enitrat enitrat left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware and @orizi)


crates/cairo-lang-starknet/cairo_level_tests/deployment.cairo line 74 at r3 (raw file):

    let res = IFactoryDispatcher { contract_address: starknet_address }.get_value();
    assert(res == 1, 'factory value is not 1')
}

Done.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @enitrat)

@orizi orizi added this pull request to the merge queue Nov 28, 2023
Merged via the queue into starkware-libs:main with commit 9d9a218 Nov 28, 2023
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.

bug: CASM runner deploy_syscall doesn't support external call to deployer in constructor
3 participants