keep-starknet-strange / snos

Rust Library for running the Starknet OS via the Cairo VM
MIT License
55 stars 27 forks source link

feat: support `DeployAccount` transaction #356

Closed whichqua closed 1 month ago

whichqua commented 1 month ago

Describe the Feature Request Snos panics on blocks with Deploy account transactions. In order to achieve this, several parts of the code need to handle/implement what is required to process these transactions

Branch WIP: https://github.com/keep-starknet-strange/snos/tree/gm/handle-deploy-tx-trace

Related Code

Additional Context On the comments, the different issues that will be described and link the PR/commit from the fix

whichqua commented 1 month ago

The first fix involved the error ContractNotFound and was resolved by handling missing nonce:

pub async fn get_nonce_at_async(&self, contract_address: ContractAddress) -> StateResult<Nonce> {
        let res = self.provider.get_nonce(self.block_id, *contract_address.key()).await;
        let nonce = match res {
            Ok(value) => Ok(value),
            Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => Ok(Felt::ZERO),
            Err(e) => Err(provider_error_to_state_error(e)),
        }?;
        Ok(Nonce(nonce))
    }
whichqua commented 1 month ago

The next issue encountered is related to the class proofs:

    for (class_hash, previous_class_proof) in previous_class_proofs {
        assert!(previous_class_proof.verify(*class_hash).is_ok());
    }

    for (class_hash, class_proof) in class_proofs {
        assert!(class_proof.verify(*class_hash).is_ok());
    }

This assertion is currently failing. Investigations continue.

whichqua commented 1 month ago

Close analysis of the following blocks 97581, 100687, 101556:

whichqua commented 1 month ago

Proving Problem: A good number of blocks with a couple of txs including atleast one DeployAccount plus other txs are failing during tx execution:

[crates/rpc-client/src/pathfinder/proofs.rs:121:17] index = 256
[crates/rpc-client/src/pathfinder/proofs.rs:121:17] start = 5
[crates/rpc-client/src/pathfinder/proofs.rs:121:17] DEFAULT_STORAGE_TREE_HEIGHT = 251
[crates/rpc-client/src/pathfinder/proofs.rs:121:17] index = 256
[crates/rpc-client/src/pathfinder/proofs.rs:121:17] start = 5
[crates/rpc-client/src/pathfinder/proofs.rs:121:17] DEFAULT_STORAGE_TREE_HEIGHT = 251
[crates/rpc-client/src/pathfinder/proofs.rs:121:17] index = 14
[crates/rpc-client/src/pathfinder/proofs.rs:121:17] start = 5
[crates/rpc-client/src/pathfinder/proofs.rs:121:17] DEFAULT_STORAGE_TREE_HEIGHT = 251
thread 'main' panicked at crates/bin/prove_block/src/lib.rs:71:50:
Could not verify previous_class_proof: KeyNotInProof...

The error is that during verify proof we need all proofs to be 256 - 5, yet the index keeps showing up as 15 or 14.

[crates/rpc-client/src/pathfinder/proofs.rs:121:17] index = 14

Example blocks: 17282, 17462

whichqua commented 1 month ago

For other blocks, the issue seems to be some misscalculated hash:

[ERROR prove_block] died at: /snos/cairo-lang/src/starkware/starknet/core/os/contract_class/deprecated_compiled_class.cairo:214
[ERROR prove_block] inst_location:
    Location { end_line: 224, end_col: 7, input_file: InputFile { filename: "/snos/cairo-lang/src/starkware/starknet/core/os/contract_class/deprecated_compiled_class.cairo" }, parent_location: None, start_line: 214, start_col: 5 }
[ERROR prove_block] 
    inner_exc error: Got an exception while executing a hint: Computed compiled_class_hash is inconsistent with the hash in the os_input. Computed hash = 1581181050526515609570793169649908419257677508622928832260239530842366398689, Expected hash = 3367764409417305403458996859647173713892682651403491887738999477132280501187.

thread 'main' panicked at crates/bin/prove_block/src/main.rs:36:61:
Block could not be proven: SnOsError(Runner(VmException(VmException { pc: Relocatable { segment_index: 0, offset: 2170 }, inst_location: Some(Location { end_line: 224, end_col: 7, input_file: InputFile { filename: "/snos/cairo-lang/src/starkware/starknet/core/os/contract_class/deprecated_compiled_class.cairo" }, parent_location: None, start_line: 214, start_col: 5 }), inner_exc: Hint((0, AssertionFailed("Computed compiled_class_hash is inconsistent with the hash in the os_input. Computed hash = 1581181050526515609570793169649908419257677508622928832260239530842366398689, Expected hash = 3367764409417305403458996859647173713892682651403491887738999477132280501187."))), error_attr_value: None, traceback: Some("Cairo traceback (most recent call last):\ncairo-lang/src/starkware/starknet/core/os/os.cairo:73:42: (pc=0:11611)\n    let (block_context: BlockContext*) = get_block_context(\n                                         ^****************^\n//snos/cairo-lang/src/starkware/starknet/core/os/block_context.cairo:59:9: (pc=0:2210)\n    ) = deprecated_load_compiled_class_facts();\n        ^************************************^\n//snos/cairo-lang/src/starkware/starknet/core/os/contract_class/deprecated_compiled_class.cairo:164:5: (pc=0:2134)\n    deprecated_load_compiled_class_facts_inner(\n    ^*****************************************^\n") })))

Example Blocks: 42883, 37031