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

feat(blockifier): replace the aliases in the state diff #2766

Merged
merged 2 commits into from
Dec 23, 2024

Conversation

yoavGrs
Copy link
Contributor

@yoavGrs yoavGrs commented Dec 18, 2024

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

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 r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @nimrod-starkware and @yoavGrs)


crates/blockifier/src/state/stateful_compression_test.rs line 0 at r1 (raw file):
can you implement a decompress test util and use it to compare original and compressed+decompressed diff?


crates/blockifier/src/state/stateful_compression_test.rs line 271 at r1 (raw file):

            .into_iter()
            .collect(),
        declared_contracts: vec![(ClassHash(Felt::THREE), true)].into_iter().collect(),

put large values here? to make sure these are not compressed, but for the correct reason

Code quote:

        compiled_class_hashes: vec![(ClassHash(Felt::ONE), CompiledClassHash(Felt::ZERO))]
            .into_iter()
            .collect(),
        declared_contracts: vec![(ClassHash(Felt::THREE), true)].into_iter().collect(),

crates/blockifier/src/state/stateful_compression.rs line 161 at r1 (raw file):

            .class_hashes
            .insert(alias_compressor.compress_address(address)?, *class_hash);
    }

we always compress class hashes? @Yoni-Starkware @nimrod-starkware

Code quote:

    for (address, class_hash) in state_diff.class_hashes.iter() {
        compressed_state_diff
            .class_hashes
            .insert(alias_compressor.compress_address(address)?, *class_hash);
    }

crates/blockifier/src/state/stateful_compression.rs line 174 at r1 (raw file):

    compressed_state_diff.declared_contracts.extend(state_diff.declared_contracts.iter());

    Ok(compressed_state_diff)

for forward-compatibility (if fields are added to the state diff) better to use .. notation and explicitly replace specific compressed fields. WDYT?

Suggestion:

    let alias_compressor = AliasCompressor { state, alias_contract_address };

    let nonces: ... = state_diff.nonces.iter().map(|(address, nonce)| {
        (alias_compressor.compress_address(address)?, *nonce)
    }).collect();
    let class_hashes: ... = state_diff.class_hashes.iter().map(|(address, class_hash)| {
        (alias_compressor.compress_address(address)?, *class_hash)
    }).collect();
    let storage: ... = state_diff.storage.iter().map(|((address, key), value)| {
        (
            (
                alias_compressor.compress_address(address)?,
                alias_compressor.compress_storage_key(key, address)?,
            ),
            *value,
        )
    }).collect();

    Ok(StateMaps {
        nonces,
        class_hashes,
        storage,
        ..state_diff
    })

@yoavGrs yoavGrs force-pushed the yoav/compression/alias_compressor branch from ff8e757 to 3bf82ca Compare December 19, 2024 14:37
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from af1d7cb to 86efe96 Compare December 19, 2024 14:38
Copy link
Contributor Author

@yoavGrs yoavGrs 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 2 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @nimrod-starkware)


crates/blockifier/src/state/stateful_compression.rs line 174 at r1 (raw file):

Previously, dorimedini-starkware wrote…

for forward-compatibility (if fields are added to the state diff) better to use .. notation and explicitly replace specific compressed fields. WDYT?

Done.
(Without ? in closures)


crates/blockifier/src/state/stateful_compression_test.rs line 271 at r1 (raw file):

Previously, dorimedini-starkware wrote…

put large values here? to make sure these are not compressed, but for the correct reason

Done.


crates/blockifier/src/state/stateful_compression_test.rs line at r1 (raw file):

Previously, dorimedini-starkware wrote…

can you implement a decompress test util and use it to compare original and compressed+decompressed diff?

Done.

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 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nimrod-starkware and @yoavGrs)

Copy link
Contributor Author

@yoavGrs yoavGrs 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, 1 unresolved discussion (waiting on @nimrod-starkware and @Yoni-Starkware)


crates/blockifier/src/state/stateful_compression.rs line 161 at r1 (raw file):

Previously, dorimedini-starkware wrote…

we always compress class hashes? @Yoni-Starkware @nimrod-starkware

In this code, we compress only the contract address.

@yoavGrs yoavGrs force-pushed the yoav/compression/alias_compressor branch from 3bf82ca to ff60390 Compare December 19, 2024 15:12
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from 86efe96 to 3a1c429 Compare December 19, 2024 15:12
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 2 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nimrod-starkware and @Yoni-Starkware)


crates/blockifier/src/state/stateful_compression.rs line 161 at r1 (raw file):

Previously, yoavGrs wrote…

In this code, we compress only the contract address.

what I meant to ask: if only class hash changed, do we compress the contract address?

@yoavGrs yoavGrs force-pushed the yoav/compression/alias_compressor branch from ff60390 to ae7f69c Compare December 19, 2024 16:00
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from 3a1c429 to 1644fd5 Compare December 19, 2024 16:00
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 2 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nimrod-starkware and @Yoni-Starkware)

Copy link
Contributor Author

@yoavGrs yoavGrs 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, 1 unresolved discussion (waiting on @nimrod-starkware and @Yoni-Starkware)


crates/blockifier/src/state/stateful_compression.rs line 161 at r1 (raw file):

Previously, dorimedini-starkware wrote…

what I meant to ask: if only class hash changed, do we compress the contract address?

This is what Nimrod wrote to me:

for address in address_to_class_hash.keys() | address_to_nonce.keys() | storage_updates.keys():
    if address in storage_updates:
         // allocate aliases for storage keys.
    // allocate alias for address

Copy link
Collaborator

@Yoni-Starkware Yoni-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 @nimrod-starkware and @yoavGrs)


crates/blockifier/src/state/stateful_compression.rs line 174 at r1 (raw file):

Previously, yoavGrs wrote…

Done.
(Without ? in closures)

@yoavGrs can you please follow Dori's suggestion re collect instead of new + for? (convention)


crates/blockifier/src/state/stateful_compression.rs line 183 at r7 (raw file):

    ) -> CompressionResult<ContractAddress> {
        if contract_address.0 >= MIN_VALUE_FOR_ALIAS_ALLOC {
            Ok(self.get_alias(StorageKey(contract_address.0))?.try_into()?)

StorageKey -> AliasKey

@yoavGrs yoavGrs force-pushed the yoav/compression/alias_compressor branch from ae7f69c to e41ec4a Compare December 22, 2024 09:04
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from 1644fd5 to f7862bb Compare December 22, 2024 09:04
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 r9, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nimrod-starkware and @yoavGrs)


crates/blockifier/src/state/stateful_compression.rs line 174 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

@yoavGrs can you please follow Dori's suggestion re collect instead of new + for? (convention)

@Yoni-Starkware issue is ? within the iterator closures.
@yoavGrs you can collect::<Result<_, _>>()? to solve this though (collect is smart enough to collect an Iterator<Result<_, _>> into a Result<_, _>)

@yoavGrs yoavGrs force-pushed the yoav/compression/alias_compressor branch from e41ec4a to cf2d3f0 Compare December 23, 2024 08:23
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from f7862bb to edbf88b Compare December 23, 2024 08:23
@yoavGrs yoavGrs force-pushed the yoav/compression/alias_compressor branch from cf2d3f0 to 01d697a Compare December 23, 2024 09:07
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from edbf88b to 814abff Compare December 23, 2024 09:07
@yoavGrs yoavGrs force-pushed the yoav/compression/alias_compressor branch from 01d697a to 7b96768 Compare December 23, 2024 09:30
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from 814abff to f46dab6 Compare December 23, 2024 09:30
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 r11, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nimrod-starkware and @yoavGrs)

@yoavGrs yoavGrs force-pushed the yoav/compression/alias_compressor branch 2 times, most recently from c781a55 to 44a7c63 Compare December 23, 2024 12:57
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from f46dab6 to e25383e Compare December 23, 2024 12:57
@yoavGrs yoavGrs changed the base branch from yoav/compression/alias_compressor to graphite-base/2766 December 23, 2024 13:28
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from e25383e to 5433ec4 Compare December 23, 2024 13:28
@yoavGrs yoavGrs changed the base branch from graphite-base/2766 to main December 23, 2024 13:29
@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch 2 times, most recently from 4f92b53 to e6f35c8 Compare December 23, 2024 13:33
Copy link
Contributor Author

@yoavGrs yoavGrs 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 2 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware, @nimrod-starkware, and @Yoni-Starkware)


crates/blockifier/src/state/stateful_compression.rs line 174 at r1 (raw file):

Previously, dorimedini-starkware wrote…

@Yoni-Starkware issue is ? within the iterator closures.
@yoavGrs you can collect::<Result<_, _>>()? to solve this though (collect is smart enough to collect an Iterator<Result<_, _>> into a Result<_, _>)

Done!
I should return Result from the closures, to allow using ? within them.


crates/blockifier/src/state/stateful_compression.rs line 183 at r7 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

StorageKey -> AliasKey

Compilation error: can't use a type alias as a constructor

@yoavGrs yoavGrs force-pushed the yoav/compression/compress_state_diff branch from e6f35c8 to 199ab60 Compare December 23, 2024 14:33
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 r13, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nimrod-starkware and @Yoni-Starkware)

Copy link
Collaborator

@Yoni-Starkware Yoni-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 2 files at r13.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @nimrod-starkware)

@yoavGrs yoavGrs merged commit 3000622 into main Dec 23, 2024
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants