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: incorrect nonce value #499

Closed
greged93 opened this issue Mar 25, 2024 · 5 comments · Fixed by #502 or #503
Closed

BUG: incorrect nonce value #499

greged93 opened this issue Mar 25, 2024 · 5 comments · Fixed by #502 or #503
Assignees
Labels
bug Something isn't working integration

Comments

@greged93
Copy link
Collaborator

I am sending a transaction to a contract which tries to get the nonce of the sender via the transaction info syscall. The below is the cairo 1 snippet I am running (with the link to the full code here):

assert(get_caller_address().is_zero(), 'Caller not 0');

let tx_info = get_tx_info().unbox();

let call_len = calls.len();
assert(call_len == 1, 'call len is not 1');

let call = calls.at(0);
assert(*call.to == self.kakarot_core_address(), 'to is not kakarot core');
assert!(
    *call.selector == selector!("eth_send_transaction"),
    "Validate: selector must be eth_send_transaction"
);

let signature = tx_info.signature;
let chain_id = self.chain_id();

let tx_metadata = TransactionMetadata {
     address: self.evm_address(),
     chain_id,
     account_nonce: tx_info.nonce.try_into().unwrap(),
     signature: signature
            .try_into_eth_signature(chain_id)
            .expect('signature extraction failed')
};

However, printing the tx_info.nonce value gets me a 0x1139045e000000000000000000000000000000000 instead of 0x0. I tried tracing the nonce value all the way to the wrap_get_execution_info_v2 and it seems the value was still correct. Couldn't figure out at what point the nonce gets set to this incorrect value.

@rodrigo-pino
Copy link
Contributor

rodrigo-pino commented Mar 25, 2024

I am having a similar issue. Not located on the nonce but on tx_info.account_contract_address. This is the test I am running:

    #[external(v0)]
    fn test_get_execution_info(
        self: @ContractState,
        expected_block_info: BlockInfo,
        expected_tx_info: TxInfo,
        // Expected call info.
        expected_caller_address: felt252,
        expected_contract_address: felt252,
        expected_entry_point_selector: felt252,
    ) {
        let execution_info = starknet::get_execution_info().unbox();
        let block_info = execution_info.block_info.unbox();
        assert(block_info == expected_block_info, 'BLOCK_INFO_MISMATCH');

        let tx_info = execution_info.tx_info.unbox();
        assert(tx_info.version == expected_tx_info.version, 'VERSION_MISMATCH');
        // This one is failing
        assert(tx_info.account_contract_address == expected_tx_info.account_contract_address, 'ACC_CTRCT_ADRR_MISMATCH');
        // Every other field after this is correct
...

The account_contract_address member is 0, but it shouldn't be. The syscall is implemented in the blockfier and it returns the right value when debugged.

Please find the full test code here

@igaray igaray added bug Something isn't working integration labels Mar 26, 2024
@azteca1998 azteca1998 self-assigned this Mar 26, 2024
@azteca1998
Copy link
Collaborator

azteca1998 commented Mar 26, 2024

It seems the issue is related to the array rewrite. Basically the Starknet glue code is still using the old arrays and therefore the offsets are all wrong after an array is found in the struct. I'm working on it.

@azteca1998 azteca1998 linked a pull request Mar 26, 2024 that will close this issue
5 tasks
@azteca1998
Copy link
Collaborator

That PR is mostly ready: there's only a test that is failing and I'm not sure why but I'll probably fix it in a different PR.
The bug should be fixed, could you test if it fixes the bug? cc @greged93 @rodrigo-pino

@greged93
Copy link
Collaborator Author

@azteca1998 just tried but it seems like I am not getting an error with the signature. Still taking the first example, running

let signature = tx_info.signature;
(*signature.at(0)).print();

Seems to make the VM error out. Maybe it's important to note that my signature's length is 5. By the way I made a PR here to add Kakarot to SiR so that might help you with the debugging.

@azteca1998
Copy link
Collaborator

Well, this is embarassing. I accidentally made it so that when converting arrays to the internal representation, the start offset is always len, therefore it always has zero size... Fixed in #503.

@azteca1998 azteca1998 reopened this Mar 27, 2024
@azteca1998 azteca1998 linked a pull request Mar 27, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working integration
Projects
Status: Done
4 participants