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: fails if a Cairo 1 deploy_syscall and class declare happens in the same block #446

Open
apoorvsadana opened this issue Dec 5, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@apoorvsadana
Copy link
Contributor

SNOS version:

cb2a6d2

Current behavior:

If you

  1. Declare a class in a block
  2. Deploy the same class in the same block using the Cairo 1 deploy_syscall (can't use UDC as that's Cairo 0)

Then, SNOS fails with No CASM error.

Expected behavior:

It should work :)

Steps to reproduce:

Create a contract which can deploy using Cairo 1 syscall

#[starknet::contract]
pub mod DeployTesting {
    use starknet::{
        get_caller_address, get_tx_info, ClassHash, ContractAddress,
        syscalls::{deploy_syscall, replace_class_syscall}, SyscallResultTrait, storage::Map,
    };

    #[starknet::interface]
    pub trait IDeployTesting<TState> {
        fn deploy_stuff(
            ref self: TState, salt: felt252, class_hash: ClassHash,
        );
    }

    #[storage]
    struct Storage {
        last_fill_id: u256,
    }
    
    #[abi(embed_v0)]
    impl DeployTestingImpl of IDeployTesting<ContractState> {
        fn deploy_stuff(
            ref self: ContractState, salt: felt252, class_hash: ClassHash,
        ) {
            self.last_fill_id.write(2);
            let (contract_address, _) = deploy_syscall(class_hash, salt, [].span(), false)
                .unwrap_syscall();
        }
    }
}

After you declare deploy this, use this JS code to declare and deploy

async function customDeclareDeploy() {
    const account = new starknet.Account(
        provider,
        '<address>',
        '<pk>',
        '1'
    );
    const contract = new starknet.Contract(
        require('./<path_to_sierra>').abi,
        '<contract_address_for_deploy_testing_contract>',
        account
    );

    let declare_result = await account.declare({
        contract: require('./<random_sierra_contract>'),
        casm: require('./<casm>'),
    });

    console.log(declare_result);

    // waiting for sometime to avoid nonce issue
    await new Promise((resolve) => setTimeout(resolve, 3000));

    let deploy_result = await contract.deploy_stuff(
        0,
        declare_result.class_hash
    );
    console.log(deploy_result);
}

Now run SNOS on the block that included the above 2 txs.

@apoorvsadana apoorvsadana added the bug Something isn't working label Dec 5, 2024
@whichqua whichqua self-assigned this Dec 6, 2024
@whichqua
Copy link
Collaborator

This should be resolved by #419

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants