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

build(blockifier): track access to contract 0x1 #3875

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aner-starkware
Copy link
Contributor

No description provided.

@aner-starkware aner-starkware self-assigned this Feb 2, 2025
@reviewable-StarkWare
Copy link

This change is Reviewable

@aner-starkware aner-starkware force-pushed the aner/track_contract_0x1 branch 5 times, most recently from 5a80804 to 5f11877 Compare February 2, 2025 15:23
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @aner-starkware)


crates/blockifier/src/execution/call_info.rs line 152 at r1 (raw file):

    pub read_block_hash_values: Vec<BlockHash>,
    pub accessed_blocks: HashSet<BlockNumber>,
}

Now I would create a struct for this... non-blocking, and maybe @Yoni-Starkware won't like...
WDYT?

Suggestion:

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct StorageAccess<K, V> {
    pub accessed_keys: HashSet<K>,
    pub ordered_values: Vec<V>,
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct StorageAccessTracker {
    pub storage_reads: StorageAccess<StorageKey, Felt>,
    pub class_hash_reads: StorageAccess<ContractAddress, ClassHash>,
    // TODO(Aner): add tests for storage tracking of contract 0x1
    pub block_hash_reads: StorageAccess<BlockNumber, BlockHash>
}

crates/starknet_consensus_orchestrator/src/cende/central_objects_test.rs line 496 at r1 (raw file):

            accessed_contract_addresses: HashSet::from([contract_address!("0x1")]),
            read_block_hash_values: vec![BlockHash(felt!("0xdeafbee"))],
            accessed_blocks: HashSet::from([BlockNumber(100)]),

probably needs eyes - or at least to inform - this team

Code quote:

            read_block_hash_values: vec![BlockHash(felt!("0xdeafbee"))],
            accessed_blocks: HashSet::from([BlockNumber(100)]),

crates/blockifier/src/execution/native/syscall_handler.rs line 237 at r1 (raw file):

impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
    fn get_block_hash(
        // HERE???

this function calls self.base.get_block_hash, so I don't think you need to touch anything here; right @Yoni-Starkware ?

Code quote:

// HERE???

crates/blockifier/src/execution/syscalls/syscall_base.rs line 52 at r1 (raw file):

    pub read_class_hash_values: Vec<ClassHash>,
    // Accessed addresses by the `get_class_hash_at` syscall.
    pub accessed_contract_addresses: HashSet<ContractAddress>,

these four should already be in the StorageAccessTracker struct, no?

  • now you have 6 fields

Code quote:

    pub read_values: Vec<Felt>,
    pub accessed_keys: HashSet<StorageKey>,
    pub read_class_hash_values: Vec<ClassHash>,
    // Accessed addresses by the `get_class_hash_at` syscall.
    pub accessed_contract_addresses: HashSet<ContractAddress>,

crates/blockifier/src/execution/syscalls/syscall_base.rs line 144 at r1 (raw file):

        self.read_block_hash_values.push(BlockHash(block_hash));
        Ok(block_hash)
    }

yes, exactly :)

Code quote:

        self.accessed_blocks.insert(BlockNumber(requested_block_number));
        let key = StorageKey::try_from(Felt::from(requested_block_number))?;
        let block_hash_contract_address = self
            .context
            .tx_context
            .block_context
            .versioned_constants
            .os_constants
            .os_contract_addresses
            .block_hash_contract_address();
        let block_hash = self.state.get_storage_at(block_hash_contract_address, key)?;
        self.read_block_hash_values.push(BlockHash(block_hash));
        Ok(block_hash)
    }

@aner-starkware
Copy link
Contributor Author

crates/blockifier/src/execution/call_info.rs line 152 at r1 (raw file):

Previously, dorimedini-starkware wrote…

Now I would create a struct for this... non-blocking, and maybe @Yoni-Starkware won't like...
WDYT?

I was thinking the same, but I guess there's a reason it was done this way?

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware 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: all files reviewed, 2 unresolved discussions (waiting on @aner-starkware)


crates/blockifier/src/execution/call_info.rs line 152 at r1 (raw file):

Previously, aner-starkware wrote…

I was thinking the same, but I guess there's a reason it was done this way?

don't think so, @Yoni-Starkware ?

@aner-starkware aner-starkware force-pushed the aner/track_contract_0x1 branch from 5f11877 to 7988824 Compare February 2, 2025 15:57
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @aner-starkware)

@aner-starkware aner-starkware force-pushed the aner/track_contract_0x1 branch from 7988824 to 6e533b7 Compare February 2, 2025 16:06
Copy link
Contributor Author

@aner-starkware aner-starkware 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: 5 of 7 files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware)


crates/blockifier/src/execution/syscalls/syscall_base.rs line 52 at r1 (raw file):

Previously, dorimedini-starkware wrote…

these four should already be in the StorageAccessTracker struct, no?

  • now you have 6 fields

Done?


crates/starknet_consensus_orchestrator/src/cende/central_objects_test.rs line 496 at r1 (raw file):

Previously, dorimedini-starkware wrote…

probably needs eyes - or at least to inform - this team

Who would that be?

@aner-starkware aner-starkware changed the title wip build(blockifier): track access to contract 0x1 Feb 2, 2025
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware 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 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @aner-starkware)


crates/starknet_consensus_orchestrator/src/cende/central_objects_test.rs line 496 at r1 (raw file):

Previously, aner-starkware wrote…

Who would that be?

good question. maybe @ShahakShama ?

@aner-starkware
Copy link
Contributor Author

@aner-starkware aner-starkware force-pushed the aner/track_contract_0x1 branch 2 times, most recently from dffcf55 to ffcd860 Compare February 2, 2025 19:10
@aner-starkware aner-starkware force-pushed the aner/track_contract_0x1 branch from ffcd860 to 08a3cf5 Compare February 2, 2025 19:29
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @aner-starkware)

@aner-starkware aner-starkware marked this pull request as ready for review February 3, 2025 10:16
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.

3 participants