dojoengine / dojo

Dojo is a toolchain for building provable games and autonomous worlds with Cairo
https://dojoengine.org
Apache License 2.0
407 stars 164 forks source link

Katana: Add state update DA encodings #2474

Closed kariy closed 3 days ago

kariy commented 4 days ago

Summary by CodeRabbit

coderabbitai[bot] commented 4 days ago

Walkthrough

Ohayo, sensei! This pull request introduces several new files and modules in the katana/primitives crate, focusing on data availability and cryptographic operations. Key changes include the addition of functions for encoding and decoding state updates, the implementation of the inverse Fast Fourier Transform (IFFT), and the introduction of constants related to EIP-4844. Additionally, the Cargo.toml file has been updated to manage dependencies more effectively.

Changes

File Path Change Summary
crates/katana/primitives/Cargo.toml - Added num-traits and num-bigint = "0.4.6" dependencies.
- Removed num-traits from [dev-dependencies] section.
- Added rstest to [dev-dependencies].
crates/katana/primitives/src/da/blob.rs - Added pub fn recover(data: Vec<BigUint>) -> Vec<BigUint> for recovering original data from a blob.
- Added pub fn transform(data: Vec<BigUint>) -> Vec<BigUint> for transforming data using FFT.
crates/katana/primitives/src/da/eip4844.rs - Added constants: pub const BLOB_LEN: usize, pub static ref BLS_MODULUS: BigUint, pub static ref GENERATOR: BigUint, and pub static ref TWO: BigUint for EIP-4844 related operations.
crates/katana/primitives/src/da/encoding.rs - Added pub fn encode_state_updates(value: StateUpdates) -> Vec<BigUint> and pub fn decode_state_updates(value: &[BigUint]) -> Result<StateUpdates, EncodingError>.
- Introduced Metadata and ContractUpdate structs.
crates/katana/primitives/src/da/math.rs - Added pub fn ifft(arr: Vec<BigUint>, xs: Vec<BigUint>, p: &BigUint) -> Vec<BigUint> and pub fn div_mod(a: BigUint, b: BigUint, p: &BigUint) -> BigUint for mathematical operations.
- Introduced pub static ref TWO: BigUint.
crates/katana/primitives/src/da/mod.rs - Added new modules: pub mod blob;, pub mod eip4844;, pub mod encoding;, pub mod math;, and pub mod serde;.
crates/katana/primitives/src/da/serde.rs - Added pub fn parse_str_to_blob_data(data: &str) -> Vec<BigUint> for parsing hexadecimal string data.
crates/katana/primitives/src/lib.rs - Added pub mod da; to expose the da module.
crates/katana/primitives/tests/blobs.rs - Introduced test functions: fn parse_blobs_rt(#[case] blob: &str) -> Result<()> and fn read(path: &str) -> Vec<BigUint> for testing blob data parsing and encoding.

Possibly related PRs

Suggested labels

sozo


Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: -- `I pushed a fix in commit , please review it.` -- `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: -- `@coderabbitai generate unit testing code for this file.` -- `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: -- `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` -- `@coderabbitai read src/utils.ts and generate unit testing code.` -- `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` -- `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 4 days ago

Codecov Report

Attention: Patch coverage is 99.17012% with 2 lines in your changes missing coverage. Please review.

Project coverage is 68.61%. Comparing base (731ff47) to head (07ddee3). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/primitives/src/da/encoding.rs 98.80% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2474 +/- ## ========================================== + Coverage 68.45% 68.61% +0.15% ========================================== Files 368 372 +4 Lines 48185 48426 +241 ========================================== + Hits 32987 33226 +239 - Misses 15198 15200 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.