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

Mpt trie panic refactor #118

Merged
merged 14 commits into from
Mar 25, 2024
Merged

Mpt trie panic refactor #118

merged 14 commits into from
Mar 25, 2024

Conversation

vladimir-trifonov
Copy link
Contributor

Use ThisError instead of panicking on various places in mtr_trie.

@github-actions github-actions bot added crate: trace_decoder Anything related to the trace_decoder crate. crate: mpt_trie Anything related to the mpt_trie crate. labels Mar 22, 2024
@muursh muursh requested a review from BGluth March 22, 2024 11:02
@muursh muursh force-pushed the mpt_trie_panic_refactor branch from 57ea909 to 4e3df65 Compare March 22, 2024 11:54
Copy link
Contributor

@muursh muursh left a comment

Choose a reason for hiding this comment

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

All in all a good start. We're going in the right direction

trace_decoder/src/decoding.rs Outdated Show resolved Hide resolved
mpt_trie/examples/simple.rs Outdated Show resolved Hide resolved
mpt_trie/src/debug_tools/stats.rs Show resolved Hide resolved
mpt_trie/src/partial_trie.rs Outdated Show resolved Hide resolved
mpt_trie/src/trie_hashing.rs Outdated Show resolved Hide resolved
mpt_trie/src/trie_ops.rs Outdated Show resolved Hide resolved
mpt_trie/src/trie_ops.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot added the crate: evm_arithmetization Anything related to the evm_arithmetization crate. label Mar 22, 2024
@vgnom vgnom added this to the Type 1 - Q1 2024 milestone Mar 22, 2024
Copy link
Contributor

@BGluth BGluth left a comment

Choose a reason for hiding this comment

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

So this looks good (and you got this done pretty quick as well!), and I just have a few thoughts.

I guess this is probably too big to put into a single PR, but a lot of the methods/functions in nibbles.rs can also panic, and I guess we should probably change those to Results as well.

I mentioned this in a few of my comments, but I think we should avoid duplicating expects that are identical throughout the codebase (@muursh want your thoughts on this). This is also a nit, but I think it's a bit cleaner to avoid using map_or(Ok(None)) and instead wrap the block in an Ok() since the duplication is a bit better this way. This is a bit subjective, so I'm good either way here.

mpt_trie/examples/ethereum_trie.rs Outdated Show resolved Hide resolved
mpt_trie/examples/ethereum_trie.rs Show resolved Hide resolved
mpt_trie/src/trie_ops.rs Outdated Show resolved Hide resolved
mpt_trie/src/trie_ops.rs Outdated Show resolved Hide resolved
Comment on lines +508 to 511
delete_intern(&children[nibble as usize], curr_k)?.map_or(Ok(None),
|(updated_child, value_deleted)| {
// If the child we recursively called is deleted, then we may need to reduce
// this branch to an extension/leaf.
Copy link
Contributor

@BGluth BGluth Mar 22, 2024

Choose a reason for hiding this comment

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

Small nit, but wdyt about instead replacing the map_or with map and then wrapping delete_intern with an Ok()? I guess this is a bit subjective, but this means we can ignore the Result type except for the Ok() that wraps everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but we have:

updated_children[nibble as usize] =
                                try_collapse_if_extension(updated_child)?;

inside the map_or

mpt_trie/src/trie_ops.rs Outdated Show resolved Hide resolved
mpt_trie/src/trie_ops.rs Outdated Show resolved Hide resolved
mpt_trie/src/trie_ops.rs Outdated Show resolved Hide resolved
mpt_trie/src/trie_ops.rs Show resolved Hide resolved
Copy link
Contributor

@wborgeaud wborgeaud left a comment

Choose a reason for hiding this comment

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

LGTM otherwise

mpt_trie/examples/simple.rs Outdated Show resolved Hide resolved
mpt_trie/src/debug_tools/diff.rs Outdated Show resolved Hide resolved
mpt_trie/src/debug_tools/stats.rs Outdated Show resolved Hide resolved
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Contributor

@muursh muursh left a comment

Choose a reason for hiding this comment

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

I'm happy with this

Copy link
Contributor

@BGluth BGluth left a comment

Choose a reason for hiding this comment

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

Yeah LGTM! Merge-er!

@muursh muursh merged commit 71cd5b5 into develop Mar 25, 2024
7 checks passed
@muursh muursh deleted the mpt_trie_panic_refactor branch March 25, 2024 19:59
@BGluth BGluth mentioned this pull request Apr 16, 2024
BGluth added a commit that referenced this pull request Apr 19, 2024
* Update plonky2 dependencies (#119)

* Update plonky2 dependencies

* Modify changelog

* Charge gas before SLOAD and refactor `insert_accessed_storage_keys` (#117)

* Charge gas before SLOAD and refactor `insert_accessed_storage_keys`

* fmt

* Only store value for cold access

* PR feedback

---------

Co-authored-by: BGluth <gluthb@gmail.com>

* Increased the public interface for `trie_tools` (#123)

- `trie_tools` needs to access a bit of currently private logic.
  Specifically, it needs to be able to process compact bytecode into
  `mpt_tries` directly.
- I think this change is actually reasonable. I can see realistic use
  cases where we don't need to process an entire block trace but instead
  just want to decode some compact bytecode.
- With the current public interface, the caller can only pass in an
  entire block trace to process.

* Mpt trie panic refactor (#118)

* refactor: refactoring mpt_trie to use more Results

* fix: replace anyhow with this-error for mpt_trie

* style: formatting

* fix: fix results

* fix: pr fixes

* fix: fix error message

* fix: format

* fix: fix unusefull return type

* fix: fix formatting

* fix: pr fixes

* fix: pr fixes

* fix: pr fixes

* tests: refactor some tests

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* refactor: remove some reallocations from decoder (#126)

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Charge cold access cost in *CALL* before accessing state (#124)

* Charge cold access cost in CALL before accessing state

* PR feedback

---------

Co-authored-by: BGluth <gluthb@gmail.com>

* chore: add debug function for better logging in development (#134)

* chore: add debug function for better logging in development

* chore: fix clippy issue

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Make test_receipt_encoding more meaningful. (#131)

* Make test_receipt_encoding more meaningful.

* Apply comment

* Add a getter for the KERNEL codehash (#136)

* Update CHANGELOG

* Version bump for next release (#137)

* Bumped sub-crate versions for a new release

* Added in missing change log entries

- Other PRs missed updating `CHANGELOG.md`

* feat: swap out the internal U512 inside nibbles (#132)

* feat: swap out the internal U512 inside nibbles

* fix: comment fix

* fix: fix clippy pr issues

* fix: fix clippy issue

* fix: fix pr comments

* docs: update changelog

* fix: update impl_to_nibbles

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Some clippy fixes (#149)

* MAX fixes for clippy

* fix transmut without annotations

* please the fmt gods

* Remove interpreter-specific preinialization logic from State trait (#139)

* Remove interpreter specific methods from State trait

* Changelog

* Make some more functions constant (#154)

* Make some more functions constant

* Update changelog

* fix(keccak-sponge): properly constrain padding bytes (#158)

* fix(keccak-sponge): properly constrain padding bytes

* fix: block bytes offset

* fix: constrain zero padding bytes

* fix: use collect_vec

* feat: replace is_final_input_len with is_padding_byte

* fix: remove unnecessary iterators

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* fix: remove redundant constraint

* docs: define padding byte in comment

---------

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Reduce verbosity in logs (#160)

* Reduce verbosity in logs

* CHANGELOG

* Add entry for 158 in CHANGELOG

* Bump with latest starky (#161)

* Bump with latest plonky2

* CHANGELOG

* feat: decouple trace_decoder and proof_gen (#163)

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Simplify withdrawals logic (#168)

* Simplify withdrawals logic

* Update CHANGELOG

* Clippy

* feat: extend trace decoder err info (#148)

* feat: extend trace decoder err info

* fix: fix clippy issue

* feat: swap out the internal U512 inside nibbles (#132)

* feat: swap out the internal U512 inside nibbles

* fix: comment fix

* fix: fix clippy pr issues

* fix: fix clippy issue

* fix: fix pr comments

* docs: update changelog

* fix: update impl_to_nibbles

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Some clippy fixes (#149)

* MAX fixes for clippy

* fix transmut without annotations

* please the fmt gods

* fix: add pr comments fixes

* fix: add pr comments fix

* fix: add pr comment fix

* docs: update changelog

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>
Co-authored-by: Ben <bmarsh94@gmail.com>

* Moved `Unreleased` changes to `0.3.0` (#173)

- Also added two missing PRs

---------

Co-authored-by: Hamy Ratoanina <hamy.ratoanina@toposware.com>
Co-authored-by: wborgeaud <williamborgeaud@gmail.com>
Co-authored-by: Vladimir Trifonov <vladimir-trifonov@users.noreply.github.com>
Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>
Co-authored-by: Linda Guiga <101227802+LindaGuiga@users.noreply.github.com>
Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>
Co-authored-by: Robin Salen <salenrobin@gmail.com>
Co-authored-by: Ben <bmarsh94@gmail.com>
Co-authored-by: Ayush Shukla <shuklaayush247@gmail.com>
BGluth pushed a commit that referenced this pull request Apr 22, 2024
* refactor: refactoring mpt_trie to use more Results

* fix: replace anyhow with this-error for mpt_trie

* style: formatting

* fix: fix results

* fix: pr fixes

* fix: fix error message

* fix: format

* fix: fix unusefull return type

* fix: fix formatting

* fix: pr fixes

* fix: pr fixes

* fix: pr fixes

* tests: refactor some tests

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>
LindaGuiga added a commit that referenced this pull request Apr 26, 2024
* Moved `Unreleased` changes to `0.3.0` (#173)

- Also added two missing PRs

* `main` --> `0.3.0` (#138)

* Update plonky2 dependencies (#119)

* Update plonky2 dependencies

* Modify changelog

* Charge gas before SLOAD and refactor `insert_accessed_storage_keys` (#117)

* Charge gas before SLOAD and refactor `insert_accessed_storage_keys`

* fmt

* Only store value for cold access

* PR feedback

---------

Co-authored-by: BGluth <gluthb@gmail.com>

* Increased the public interface for `trie_tools` (#123)

- `trie_tools` needs to access a bit of currently private logic.
  Specifically, it needs to be able to process compact bytecode into
  `mpt_tries` directly.
- I think this change is actually reasonable. I can see realistic use
  cases where we don't need to process an entire block trace but instead
  just want to decode some compact bytecode.
- With the current public interface, the caller can only pass in an
  entire block trace to process.

* Mpt trie panic refactor (#118)

* refactor: refactoring mpt_trie to use more Results

* fix: replace anyhow with this-error for mpt_trie

* style: formatting

* fix: fix results

* fix: pr fixes

* fix: fix error message

* fix: format

* fix: fix unusefull return type

* fix: fix formatting

* fix: pr fixes

* fix: pr fixes

* fix: pr fixes

* tests: refactor some tests

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* refactor: remove some reallocations from decoder (#126)

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Charge cold access cost in *CALL* before accessing state (#124)

* Charge cold access cost in CALL before accessing state

* PR feedback

---------

Co-authored-by: BGluth <gluthb@gmail.com>

* chore: add debug function for better logging in development (#134)

* chore: add debug function for better logging in development

* chore: fix clippy issue

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Make test_receipt_encoding more meaningful. (#131)

* Make test_receipt_encoding more meaningful.

* Apply comment

* Add a getter for the KERNEL codehash (#136)

* Update CHANGELOG

* Version bump for next release (#137)

* Bumped sub-crate versions for a new release

* Added in missing change log entries

- Other PRs missed updating `CHANGELOG.md`

* feat: swap out the internal U512 inside nibbles (#132)

* feat: swap out the internal U512 inside nibbles

* fix: comment fix

* fix: fix clippy pr issues

* fix: fix clippy issue

* fix: fix pr comments

* docs: update changelog

* fix: update impl_to_nibbles

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Some clippy fixes (#149)

* MAX fixes for clippy

* fix transmut without annotations

* please the fmt gods

* Remove interpreter-specific preinialization logic from State trait (#139)

* Remove interpreter specific methods from State trait

* Changelog

* Make some more functions constant (#154)

* Make some more functions constant

* Update changelog

* fix(keccak-sponge): properly constrain padding bytes (#158)

* fix(keccak-sponge): properly constrain padding bytes

* fix: block bytes offset

* fix: constrain zero padding bytes

* fix: use collect_vec

* feat: replace is_final_input_len with is_padding_byte

* fix: remove unnecessary iterators

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Update evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* fix: remove redundant constraint

* docs: define padding byte in comment

---------

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>

* Reduce verbosity in logs (#160)

* Reduce verbosity in logs

* CHANGELOG

* Add entry for 158 in CHANGELOG

* Bump with latest starky (#161)

* Bump with latest plonky2

* CHANGELOG

* feat: decouple trace_decoder and proof_gen (#163)

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Simplify withdrawals logic (#168)

* Simplify withdrawals logic

* Update CHANGELOG

* Clippy

* feat: extend trace decoder err info (#148)

* feat: extend trace decoder err info

* fix: fix clippy issue

* feat: swap out the internal U512 inside nibbles (#132)

* feat: swap out the internal U512 inside nibbles

* fix: comment fix

* fix: fix clippy pr issues

* fix: fix clippy issue

* fix: fix pr comments

* docs: update changelog

* fix: update impl_to_nibbles

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>

* Some clippy fixes (#149)

* MAX fixes for clippy

* fix transmut without annotations

* please the fmt gods

* fix: add pr comments fixes

* fix: add pr comments fix

* fix: add pr comment fix

* docs: update changelog

---------

Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>
Co-authored-by: Ben <bmarsh94@gmail.com>

* Moved `Unreleased` changes to `0.3.0` (#173)

- Also added two missing PRs

---------

Co-authored-by: Hamy Ratoanina <hamy.ratoanina@toposware.com>
Co-authored-by: wborgeaud <williamborgeaud@gmail.com>
Co-authored-by: Vladimir Trifonov <vladimir-trifonov@users.noreply.github.com>
Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>
Co-authored-by: Linda Guiga <101227802+LindaGuiga@users.noreply.github.com>
Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>
Co-authored-by: Robin Salen <salenrobin@gmail.com>
Co-authored-by: Ben <bmarsh94@gmail.com>
Co-authored-by: Ayush Shukla <shuklaayush247@gmail.com>

* Fix withdrawals accesses in state trie (#176)

* Bumped `trace_decoder` version for new `zk_evm` release (#177)

* Bumped `trace_decoder` version for new `zk_evm` release

* Updated `CHANGELOG.md`

* Revert "`main` --> `0.3.0` (#138)" (#179)

This reverts commit 88d75ed.

* Some cleanup (#190)

* Cleanup perform_op

* Move interpreter test methods to test module

* Some more cleanup and removal

* more cleanup

* More cleanup misc and doc

* Remove outdated arg

* Fix clippy

---------

Co-authored-by: BGluth <gluthb@gmail.com>
Co-authored-by: Hamy Ratoanina <hamy.ratoanina@toposware.com>
Co-authored-by: wborgeaud <williamborgeaud@gmail.com>
Co-authored-by: Vladimir Trifonov <vladimir-trifonov@users.noreply.github.com>
Co-authored-by: Vladimir Trifonov <trifonov.vp@gmail.com>
Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>
Co-authored-by: Robin Salen <salenrobin@gmail.com>
Co-authored-by: Ben <bmarsh94@gmail.com>
Co-authored-by: Ayush Shukla <shuklaayush247@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate: evm_arithmetization Anything related to the evm_arithmetization crate. crate: mpt_trie Anything related to the mpt_trie crate. crate: trace_decoder Anything related to the trace_decoder crate.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants