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

Publish State Diff to Eth #7

Merged
merged 18 commits into from
Jun 17, 2024
Merged

Conversation

Mohiiit
Copy link
Contributor

@Mohiiit Mohiiit commented May 24, 2024

functionality added to send state diff data to eth as blob
added tests

Summary by CodeRabbit

  • New Features

    • Introduced new functions for data conversion, FFT transformation, and blob creation.
    • Added static variables for BLS12-381 modulus and related constants.
  • Bug Fixes

    • Updated functions to handle Ethereum blob size limits per transaction.
  • Improvements

    • Refactored state_update_to_blob_data for better nonce retrieval and data processing.
    • Enhanced publish_state_diff method to support new transaction handling logic.
  • Documentation

    • Updated environment variable requirements for Ethereum RPC URL and private key.
  • Tests

    • Added test cases for new functions and data handling logic.

Copy link

coderabbitai bot commented May 24, 2024

Walkthrough

Recent updates to the Cargo.toml files across multiple crates have introduced new dependencies like num, num-bigint, ethereum-da-client, and others. Significant code modifications involved refactoring parameter types, adding new async functions, and adapting configurations for Ethereum DA client processes. New constants and blob processing functionalities were also incorporated into the orchestrator's job handling logic.

Changes

Files/Paths Change Summary
Cargo.toml (multiple locations) Added/updated dependencies like num, ethereum-da-client, num-bigint, async-trait, lazy_static, dotenv, c-kzg, rstest, tokio, etc.
crates/.../da-client-interface/src/lib.rs Changed parameter types for publish_state_diff, added async methods max_blob_per_txn and max_bytes_per_blob.
crates/.../ethereum/.env_example Introduced new environment variables for private key and Ethereum RPC URL.
crates/.../ethereum/src/lib.rs Major refactorings including changes in method signatures, added sidecar preparation, transaction setup, and introduced new methods for Ethereum client operations.
crates/.../ethereum/src/config.rs Added new public field private_key to EthereumDaConfig, initialized from environment variables.
crates/orchestrator/src/jobs/constants.rs Introduced new constants ETHEREUM_MAX_BYTES_PER_BLOB and ETHEREUM_MAX_BLOB_PER_TXN.
crates/.../da_job/mod.rs Added static variables, new functions for FFT transformation, blob creation, and modified state_update_to_blob_data for better data processing.
crates/.../mod.rs (jobs module) Changed module visibility for constants to public.
crates/.../common/constants.rs (tests module) Added constants ETHEREUM_MAX_BYTES_PER_BLOB and ETHEREUM_MAX_BLOB_PER_TXN.
crates/.../da_job/mod.rs (tests module) Added imports for new constants and updated test cases to include expectations for new Ethereum blob size limit-related functions.

Poem

In the land of code where rabbits thrive,
Dependencies grew, making projects alive. 🌱
With blobs and bytes in transactions' flight,
Ethereum danced through the code in the night. ✨
Constants and configs in orchestration's embrace,
Each function refined, each test in its place.
Hopping through lines, what a wondrous chase! 🐇🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (1)
crates/orchestrator/src/jobs/da_job/mod.rs (1)

Line range hint 198-267: Consider addressing the TODO and hardcoded values in state_update_to_blob_data.

The function contains a TODO comment and hardcoded values for FieldElement::ONE. It's important to clarify these points or resolve them to ensure the robustness and maintainability of the code.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3fe3733 and 29ad37e.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (9)
  • Cargo.toml (2 hunks)
  • crates/da_clients/da-client-interface/src/lib.rs (1 hunks)
  • crates/da_clients/ethereum/.env_example (1 hunks)
  • crates/da_clients/ethereum/Cargo.toml (1 hunks)
  • crates/da_clients/ethereum/src/lib.rs (1 hunks)
  • crates/orchestrator/Cargo.toml (2 hunks)
  • crates/orchestrator/src/jobs/constants.rs (1 hunks)
  • crates/orchestrator/src/jobs/da_job/mod.rs (6 hunks)
  • crates/orchestrator/src/jobs/mod.rs (1 hunks)
Files skipped from review due to trivial changes (2)
  • crates/da_clients/ethereum/.env_example
  • crates/orchestrator/src/jobs/mod.rs
Additional comments not posted (27)
crates/da_clients/ethereum/Cargo.toml (5)

7-15: Updated alloy dependency to include new blockchain-related features and a specific revision. This aligns with the PR's objectives to enhance Ethereum interactions.


20-20: Updated reqwest to version 0.12.3, likely for improved stability or new minor features.


21-21: Added c-kzg dependency, likely for cryptographic operations, supporting the PR's blockchain functionality enhancements.


22-22: Added dotenv for better management of environment variables, enhancing secure configuration practices.


26-28: Added rstest and tokio as workspace dependencies for enhanced testing and asynchronous runtime support.

Also applies to: 30-30

crates/orchestrator/src/jobs/constants.rs (3)

7-7: Added BLOB_LEN constant for blob size, supporting data handling in Ethereum-related functionalities.


8-20: Defined cryptographic constants BLS_MODULUS and GENERATOR using lazy_static, crucial for blockchain operations.


21-21: Added TWO as a constant, likely used in mathematical operations within blockchain functionalities.

crates/da_clients/da-client-interface/src/lib.rs (3)

20-20: Modified publish_state_diff to accept Vec<Vec<u8>>, aligning with the handling of raw byte data for Ethereum transactions.


24-24: Added max_blob_per_txn function to manage the number of blobs per transaction, enhancing blockchain transaction management.


26-26: Added max_bytes_per_blob function to set limits on the byte size per blob, supporting efficient data management in blockchain transactions.

Cargo.toml (5)

18-18: Added num library for enhanced numerical operations, likely supporting blockchain-related data handling.


19-19: Added ethereum-da-client as a direct dependency, central to the PR's focus on enhancing Ethereum interactions.


21-21: Added da-client-interface to standardize interactions across different blockchain platforms, enhancing modularity and interoperability.


39-39: Added num-bigint for handling large integers, crucial for cryptographic operations in blockchain functionalities.


41-42: Added num-traits for numeric traits in generic programming and lazy_static for efficient use of immutable static values, enhancing performance and flexibility.

crates/orchestrator/Cargo.toml (4)

9-9: Repositioned thiserror within workspace dependencies for better organizational clarity and dependency management.


23-25: Added num-bigint, num-traits, and num for enhanced handling of numerical data, crucial for cryptographic calculations in blockchain contexts.


26-26: Added lazy_static for efficient definition of immutable static values, enhancing performance and code clarity.


31-32: Added majin-blob-types and majin-blob-core for handling specific data structures in blockchain functionalities, supporting the new features introduced.

crates/da_clients/ethereum/src/lib.rs (5)

3-9: Extensive imports from alloy covering various aspects of Ethereum transactions such as consensus, eips, and network, aligning with the PR's focus on enhancing Ethereum interactions.


36-72: Significantly enhanced publish_state_diff to handle complex Ethereum transactions with cryptographic proofs, central to the PR's objectives.


79-85: Added max_blob_per_txn and max_bytes_per_blob functions to provide crucial configuration limits for Ethereum transactions, enhancing resource management.


98-121: Added prepare_sidecar function to efficiently handle large and complex data structures for Ethereum transactions, supporting the new functionalities.


123-199: Extensive test cases added to ensure robustness and correctness of the new Ethereum transaction functionalities.

crates/orchestrator/src/jobs/da_job/mod.rs (2)

147-167: Function convert_to_biguint is correctly implemented.

This function efficiently converts a vector of FieldElement to BigUint, handling edge cases appropriately.


360-370: Function test_fft_transformation is correctly implemented.

This function effectively tests the fft_transformation function, ensuring its correctness across different scenarios.

crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
crates/orchestrator/src/jobs/da_job/mod.rs (1)

Line range hint 198-267: Refactor the state_update_to_blob_data function to improve readability and maintainability. Consider breaking down the function into smaller, more manageable functions.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 29ad37e and 6e6d5e7.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (5)
  • Cargo.toml (2 hunks)
  • crates/da_clients/da-client-interface/src/lib.rs (1 hunks)
  • crates/orchestrator/Cargo.toml (2 hunks)
  • crates/orchestrator/src/jobs/da_job/mod.rs (6 hunks)
  • crates/orchestrator/src/jobs/mod.rs (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • Cargo.toml
  • crates/da_clients/da-client-interface/src/lib.rs
  • crates/orchestrator/Cargo.toml
  • crates/orchestrator/src/jobs/mod.rs
Additional comments not posted (6)
crates/orchestrator/src/jobs/da_job/mod.rs (6)

122-145: Move the constants BLS_MODULUS and GENERATOR to a central location as previously suggested.


169-196: Replace the panic with proper error handling in the data_to_blobs function to enhance robustness and user experience.


339-350: Complete the implementation of test_state_update_to_blob_data to ensure the reliability and correctness of the state_update_to_blob_data function.


274-305: Optimize nonce handling in da_word to avoid unnecessary conversions and potential performance issues.


74-100: Ensure proper error handling for potential failures in state_update_to_blob_data and publish_state_diff functions.


Line range hint 313-370: Ensure that the test cases cover all possible scenarios and edge cases to guarantee the robustness of the da_word function.

crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (1)
crates/orchestrator/src/jobs/da_job/mod.rs (1)

[!TIP]
Codebase Verification

The test_state_update_to_blob_data function is present but marked as "not yet done," indicating it is incomplete. This means the function does not currently verify the integrity of the state_update_to_blob_data function as intended.

  • test_state_update_to_blob_data is incomplete and does not fully test the state_update_to_blob_data function.
  • Ensure that the test function is completed and covers all critical paths and edge cases for state_update_to_blob_data.
Analysis chain

Line range hint 199-275: Significant changes in state_update_to_blob_data include handling of various blockchain state components. Ensure that all mappings and transformations are accurate and that the data integrity is maintained throughout the process.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify data integrity in `state_update_to_blob_data`.
# Test: Search for tests related to state update transformations.
rg --type rust 'state_update_to_blob_data'

Length of output: 517



Script:

#!/bin/bash
# Extract the test function `test_state_update_to_blob_data` to review its content and coverage.
ast-grep --lang rust --pattern 'async fn test_state_update_to_blob_data($$_) { $$$ }'

Length of output: 87



Script:

#!/bin/bash
# Locate the `test_state_update_to_blob_data` function and extract its content for review.
rg 'async fn test_state_update_to_blob_data' -A 20 crates/orchestrator/src/jobs/da_job/mod.rs

Length of output: 1063



Script:

#!/bin/bash
# Extract more lines to capture the entire `test_state_update_to_blob_data` function for review.
rg 'async fn test_state_update_to_blob_data' -A 100 crates/orchestrator/src/jobs/da_job/mod.rs

Length of output: 3041

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6e6d5e7 and 1b44e56.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (3)
  • crates/da_clients/ethereum/src/lib.rs (1 hunks)
  • crates/orchestrator/Cargo.toml (2 hunks)
  • crates/orchestrator/src/jobs/da_job/mod.rs (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • crates/orchestrator/Cargo.toml
Additional comments not posted (6)
crates/da_clients/ethereum/src/lib.rs (2)

3-11: Imports have been organized and expanded to include necessary modules for the new functionality.


98-121: The prepare_sidecar function handles the creation of sidecar data for Ethereum transactions. It's crucial to ensure that the KZG commitments and proofs are correctly computed and that the sidecar data aligns with Ethereum's requirements.

crates/orchestrator/src/jobs/da_job/mod.rs (4)

123-146: The fft_transformation function has been updated to use constants directly within the function. Consider refactoring these constants to a central location for better maintainability and to avoid duplication, as previously suggested.


170-197: The data_to_blobs function now includes error handling for blob size validation, replacing the previous panic. This is a significant improvement in robustness and user experience.


74-98: The process_job method has been updated to handle new job types and includes transformations necessary for data submission. Ensure that error messages are clear and that all potential failure points are handled gracefully.

Verification successful

The script output indicates that error handling using eyre and Err is present in crates/orchestrator/src/jobs/da_job/mod.rs. Let's review these instances to ensure they are clear and cover all potential failure points.

Error Handling Instances in crates/orchestrator/src/jobs/da_job/mod.rs:

  1. return Err(eyre!(
        "Cannot process block {} for job id {} as number of blobs allowed are {} but it contains {} blobs",
        block_no,
        job.id,
        max_blob_per_txn,
        current_blob_length
    ));
  2. return Err(eyre!(
        "Failed to get nonce: {}",
        e
    ));

These error messages appear to be clear and provide specific details about the failure conditions. The first error message specifies the block number, job ID, allowed number of blobs, and the actual number of blobs, which is helpful for debugging. The second error message includes the error encountered while getting the nonce.

Given this information, it seems that the error handling in process_job is clear and covers the potential failure points.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that error messages in `process_job` are clear and cover all failure points.
# Test: Search for error handling in `process_job`.
rg --type rust 'eyre|Err'

Length of output: 5815


282-313: The da_word function encodes various blockchain-related parameters into a single field element. Ensure that the encoding is correct and that all edge cases are handled.

Verification successful

To verify the correctness of the da_word function encoding and ensure all edge cases are handled, we need to review the implementation of the da_word function and the associated test function da_word_works.


To ensure the correctness of the da_word function encoding and that all edge cases are handled, we need to locate and review the test cases for da_word. Let's perform a more comprehensive search to locate the test function da_word_works and any other relevant test cases.


To ensure the correctness of the da_word function encoding and that all edge cases are handled, we need to extract and review the implementation of the da_word_works test function from crates/orchestrator/src/jobs/da_job/mod.rs.


To ensure the correctness of the da_word function encoding and that all edge cases are handled, we need to perform a broader search to locate the da_word_works function and any other relevant test cases.


The da_word function's encoding appears to be tested by the da_word_works function, which uses the rstest framework to validate various cases. The test cases cover different combinations of class_flag, new_nonce, and num_changes, ensuring that the function handles these inputs correctly.

The test cases provided are:

  • #[case(false, 1, 1, "18446744073709551617")]
  • #[case(false, 1, 0, "18446744073709551616")]
  • #[case(false, 0, 6, "6")]
  • #[case(true, 1, 0, "340282366920938463481821351505477763072")]

These cases seem to cover a range of scenarios, including different values for class_flag, new_nonce, and num_changes.

  • The da_word function implementation and the associated test function da_word_works are located in crates/orchestrator/src/jobs/da_job/mod.rs.

Based on the provided context and the test cases, the encoding logic in the da_word function appears to be correct and well-tested.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of encoding in `da_word`.
# Test: Search for tests related to `da_word`.
rg --type rust 'da_word'

Length of output: 741



Script:

#!/bin/bash
# Description: Retrieve the implementation of `da_word` and the test function `da_word_works`.
# Extract the `da_word` function implementation
ast-grep --lang rust --pattern 'fn da_word($_, $_, $_) -> $_ { $$$ }' crates/orchestrator/src/jobs/da_job/mod.rs

# Extract the `da_word_works` test function implementation
ast-grep --lang rust --pattern 'fn da_word_works($_) { $$$ }' crates/orchestrator/src/jobs/da_job/mod.rs

Length of output: 3225



Script:

#!/bin/bash
# Description: Perform a comprehensive search for the test function `da_word_works` and any other relevant test cases for `da_word`.
# Search for the `da_word_works` function definition
rg --type rust 'fn da_word_works'

# Search for test cases related to `da_word`
rg --type rust 'da_word'

Length of output: 842



Script:

#!/bin/bash
# Description: Extract the implementation of the `da_word_works` test function.
# Extract the `da_word_works` function implementation
ast-grep --lang rust --pattern 'fn da_word_works($_) { $$$ }' crates/orchestrator/src/jobs/da_job/mod.rs

Length of output: 106



Script:

#!/bin/bash
# Description: Perform a broader search for the `da_word_works` function and any other relevant test cases.
# Search for the `da_word_works` function definition
rg 'fn da_word_works' --context 10

# Search for test cases related to `da_word`
rg 'da_word' --context 10

Length of output: 8284

crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/da_clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1b44e56 and 1b058c7.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (4)
  • crates/da_clients/ethereum/src/config.rs (1 hunks)
  • crates/da_clients/ethereum/src/lib.rs (1 hunks)
  • crates/orchestrator/Cargo.toml (2 hunks)
  • crates/orchestrator/src/jobs/da_job/mod.rs (6 hunks)
Additional comments not posted (22)
crates/da_clients/ethereum/src/config.rs (2)

8-8: Added private_key field to EthereumDaConfig.

This addition aligns with the PR's objective to handle Ethereum transactions, which typically require authentication via a private key.


16-16: Ensure environment variable PRIVATE_KEY is well-documented.

crates/orchestrator/Cargo.toml (2)

16-17: Added dependencies on majin-blob-types and majin-blob-core.

These additions are necessary for handling blob data types, which are part of the new functionality to send state diff data to Ethereum.


Line range hint 18-36: Updated and added various dependencies to support new functionality.

These updates include necessary libraries for bigint operations, async handling, and Ethereum interactions, which are crucial for the new features.

crates/da_clients/ethereum/src/lib.rs (10)

3-9: Imported multiple modules from alloy, which are essential for Ethereum transaction handling.

These imports are necessary for the new functionality related to Ethereum transactions.


11-11: Added imports for handling asynchronous traits and HTTP transactions.

These are crucial for the async operations and HTTP communications within the Ethereum client.


16-19: Updated imports to reflect changes in dependencies and error handling.

This update ensures compatibility with the latest versions of the dependencies and proper error handling.


23-27: Added imports for KZG cryptography operations, which are part of the new sidecar transaction functionality.

These additions are essential for the cryptographic operations required by the new Ethereum transaction features.


31-33: Updated EthereumDaClient struct to include new fields for provider, wallet, and trusted setup.

These updates are crucial for the enhanced functionality of handling Ethereum transactions with proper authentication and cryptographic settings.


38-73: Refactored publish_state_diff to handle new data structures and Ethereum transaction logic.

This refactoring is aligned with the PR's objectives to handle state diff data and includes comprehensive handling from preparation to transaction submission.


80-86: Added methods to determine transaction and blob size limits.

These methods are necessary for managing the size constraints of Ethereum transactions, which is a new requirement mentioned in the PR.


91-99: Refactored the From implementation for EthereumDaClient to include new configurations and error handling.

This refactoring ensures that the Ethereum client is correctly configured with environmental settings and error handling.


102-125: Added prepare_sidecar function to handle the preparation of transaction sidecars.

This function is crucial for preparing the necessary components of a transaction sidecar, which is part of the new functionality.


127-198: Enhanced test coverage for KZG operations.

This enhancement is crucial for ensuring the reliability of the cryptographic operations involved in the new features.

crates/orchestrator/src/jobs/da_job/mod.rs (8)

5-14: Added multiple imports to support new functionality in job processing.

These imports are necessary for handling bigint operations, async traits, and other functionalities required by the new features.


22-40: Defined constants using lazy_static for cryptographic operations.

Defining these constants is essential for the cryptographic operations required by the new Ethereum transaction features.


73-98: Enhanced job processing logic to handle new blob data transformations and Ethereum transaction constraints.

This enhancement is aligned with the PR's objectives to handle state diff data and includes comprehensive logic for data transformation and transaction handling.


123-140: Added fft_transformation function to perform Fast Fourier Transform on data.

This function is crucial for the data transformation required by the new features, particularly in preparing data for Ethereum transactions.


142-191: Added convert_to_biguint and data_to_blobs functions to handle data conversions necessary for blob data preparation.

These functions are essential for converting state update data into the appropriate formats for Ethereum transactions.


Line range hint 193-268: Refactored state_update_to_blob_data to handle new data structures and processing logic.

This refactoring is crucial for converting state update data into blob data, aligning with the new requirements for Ethereum transactions.


275-306: Refined da_word encoding logic to handle new nonce and class flag settings.

This refinement is necessary for the correct encoding of data attributes, which is crucial for the new Ethereum transaction features.


Line range hint 314-417: Enhanced test coverage for state update to blob data conversions and FFT transformations.

This enhancement is crucial for ensuring the reliability and correctness of the data transformations involved in the new features.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (3)
crates/da_clients/da-client-interface/src/lib.rs (1)

25-27: Addition of max_blob_per_txn and max_bytes_per_blob functions to manage transaction size limits. Please provide documentation for these functions to clarify their usage and constraints.

crates/orchestrator/src/tests/jobs/da_job/mod.rs (1)

58-61: The test test_process_job uses the new blob size limits effectively to simulate Ethereum transaction conditions. Consider adding more edge cases to ensure robustness.

crates/orchestrator/src/jobs/da_job/mod.rs (1)

Line range hint 193-268: Refine the state update to blob data transformation.

Consider refactoring the state_update_to_blob_data function to reduce complexity and improve readability. The function currently handles multiple tasks, which could be split into smaller, more focused functions. Additionally, the handling of special cases and error conditions could be separated out to make the main logic clearer.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b058c7 and 90e4a70.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (9)
  • crates/da_clients/da-client-interface/src/lib.rs (2 hunks)
  • crates/da_clients/ethereum/Cargo.toml (1 hunks)
  • crates/da_clients/ethereum/src/lib.rs (1 hunks)
  • crates/orchestrator/src/jobs/da_job/mod.rs (6 hunks)
  • crates/orchestrator/src/jobs/da_job/test_data/nonces_from_block_631861.txt (1 hunks)
  • crates/orchestrator/src/jobs/da_job/test_data/nonces_from_block_638353.txt (1 hunks)
  • crates/orchestrator/src/jobs/da_job/test_data/nonces_from_block_640641.txt (1 hunks)
  • crates/orchestrator/src/tests/common/constants.rs (1 hunks)
  • crates/orchestrator/src/tests/jobs/da_job/mod.rs (2 hunks)
Files skipped from review due to trivial changes (3)
  • crates/orchestrator/src/jobs/da_job/test_data/nonces_from_block_631861.txt
  • crates/orchestrator/src/jobs/da_job/test_data/nonces_from_block_638353.txt
  • crates/orchestrator/src/tests/common/constants.rs
Additional comments not posted (9)
crates/da_clients/ethereum/Cargo.toml (3)

7-15: The alloy dependency has been updated with several new features necessary for Ethereum operations. Ensure all new features are utilized appropriately in the codebase.


21-22: Addition of c-kzg and dotenv for cryptographic operations and environment management is appropriate. Ensure that the cryptographic operations are secure and correctly implemented.


20-20: Update to reqwest version 0.12.3 noted. Please ensure there are no breaking changes from this update that might affect existing functionality.

Verification successful

The reqwest version update to 0.12.3 does not introduce any breaking changes as per the changelog. The reqwest::Client is used in crates/da_clients/ethereum/src/lib.rs, but no specific breaking changes were found that would affect this usage. Additionally, there are tests in place that indirectly cover the functionality that relies on reqwest.

  • crates/da_clients/ethereum/src/lib.rs: Usage of reqwest::Client.
  • crates/da_clients/ethereum/src/lib.rs: Tests available under mod tests.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for breaking changes in reqwest update.
# Test: Search for migration guides or breaking changes in reqwest documentation.
curl https://docs.rs/reqwest/0.12.3

Length of output: 354



Script:

#!/bin/bash
# Find all Cargo.toml files and search for reqwest dependency to confirm all versions in use.
fd Cargo.toml --exec grep -H 'reqwest'

# Find all Rust files that use reqwest to identify usage patterns.
fd .rs --exec grep -H 'reqwest'

# Check if there are any tests related to reqwest usage.
fd .rs --exec grep -H 'reqwest' | grep -H 'test'

Length of output: 371



Script:

#!/bin/bash
# Extract the code in crates/da_clients/ethereum/src/lib.rs that uses reqwest::Client.
grep -A 10 -B 10 'reqwest::Client' crates/da_clients/ethereum/src/lib.rs

# Check the reqwest changelog for version 0.12.3.
curl -s https://raw.githubusercontent.com/seanmonstar/reqwest/master/CHANGELOG.md | grep -A 10 -B 10 '0.12.3'

# Identify functions in crates/da_clients/ethereum/src/lib.rs using reqwest and check for corresponding tests.
ast-grep --lang rust --pattern 'fn $_($$) -> $_ { $$$ }' crates/da_clients/ethereum/src/lib.rs | grep -A 10 'reqwest'

Length of output: 1600



Script:

#!/bin/bash
# Extract more lines around the reqwest::Client usage in crates/da_clients/ethereum/src/lib.rs to understand the context better.
grep -A 50 -B 50 'reqwest::Client' crates/da_clients/ethereum/src/lib.rs

# Search for test files that may indirectly cover reqwest functionality.
fd .rs --exec grep -H 'test'

Length of output: 9307

crates/da_clients/da-client-interface/src/lib.rs (1)

21-21: The change in parameter type for publish_state_diff from Vec<FieldElement> to Vec<Vec<u8>> is noted. Ensure that all callers of this function are updated to use the new data type.

Verification successful

The search results show multiple occurrences of publish_state_diff. To ensure the function call in crates/orchestrator/src/jobs/da_job/mod.rs uses the new signature, we need to examine the specific code around that call.


The function data_to_blobs returns a Result<Vec<Vec<u8>>>, which confirms that blob_array is of type Vec<Vec<u8>> and matches the new signature of publish_state_diff.

  • crates/orchestrator/src/jobs/da_job/mod.rs: let blob_array = data_to_blobs(max_bytes_per_blob, transformed_data).expect("error while converting blob data to vec<u8>");
  • crates/orchestrator/src/jobs/da_job/mod.rs: let external_id = config.da_client().publish_state_diff(blob_array).await?;

This confirms that all callers of publish_state_diff have been updated to use the new data type.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `publish_state_diff` match the new signature.
# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust $'publish_state_diff'

Length of output: 562



Script:

#!/bin/bash
# Description: Verify the function call in `crates/orchestrator/src/jobs/da_job/mod.rs` uses the new signature.
# Test: Extract the relevant code around the function call.
rg -C 5 'publish_state_diff' crates/orchestrator/src/jobs/da_job/mod.rs

Length of output: 390



Script:

#!/bin/bash
# Description: Verify the type of `blob_array` used in the `publish_state_diff` call.
# Test: Search for `blob_array` in the file to find its definition and type.
rg 'blob_array' crates/orchestrator/src/jobs/da_job/mod.rs

Length of output: 244



Script:

#!/bin/bash
# Description: Extract the full initialization code of `blob_array`.
# Test: Extract the full line where `blob_array` is initialized to verify its type.
rg -A 1 'let blob_array =' crates/orchestrator/src/jobs/da_job/mod.rs

Length of output: 215



Script:

#!/bin/bash
# Description: Verify the return type of `data_to_blobs`.
# Test: Search for the definition of `data_to_blobs` to confirm its return type.
rg 'fn data_to_blobs' --type rust

Length of output: 163

crates/orchestrator/src/tests/jobs/da_job/mod.rs (1)

9-12: Importing new constants for Ethereum blob size limits is appropriate. Ensure these values are consistent with Ethereum's current specifications.

crates/da_clients/ethereum/src/lib.rs (2)

94-99: The methods max_blob_per_txn and max_bytes_per_blob have been added to manage transaction size limits. Ensure these values are configurable and validated against Ethereum's current capabilities.


37-77: The publish_state_diff method has been significantly refactored to handle Ethereum transactions. Ensure that this method and its dependencies are thoroughly tested, especially the new transaction creation and signing logic.

crates/orchestrator/src/jobs/da_job/mod.rs (2)

22-40: Review the use of lazy_static! for constants.

The use of lazy_static! for defining constants like GENERATOR, BLS_MODULUS, and BLOB_LEN is appropriate given their constant nature and the need for complex initialization. Good use of resources.


161-190: Validate and handle blob size correctly.

The function data_to_blobs correctly checks the blob size to ensure it meets the minimum requirements and handles the conversion of data into blobs efficiently. Good error handling and data processing practices are observed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (1)
crates/orchestrator/src/jobs/da_job/mod.rs (1)

Line range hint 193-268: Complete the implementation of test_state_update_to_blob_data.

The test function test_state_update_to_blob_data is marked as not yet done. Completing this test is crucial for ensuring the reliability and correctness of the state_update_to_blob_data function. Would you like me to help by providing a draft implementation or opening a GitHub issue to track this task?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 90e4a70 and a0e4c2e.

Files selected for processing (1)
  • crates/orchestrator/src/jobs/da_job/mod.rs (6 hunks)

Comment on lines +22 to +40
lazy_static! {
/// EIP-4844 BLS12-381 modulus.
///
/// As defined in https://eips.ethereum.org/EIPS/eip-4844

/// Generator of the group of evaluation points (EIP-4844 parameter).
pub static ref GENERATOR: BigUint = BigUint::from_str(
"39033254847818212395286706435128746857159659164139250548781411570340225835782",
)
.unwrap();

pub static ref BLS_MODULUS: BigUint = BigUint::from_str(
"52435875175126190479447740508185965837690552500527637822603658699938581184513",
)
.unwrap();
pub static ref TWO: BigUint = 2u32.to_biguint().unwrap();

pub static ref BLOB_LEN: usize = 4096;
}
Copy link

Choose a reason for hiding this comment

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

Move common constants to a central location for better maintainability.

The constants GENERATOR, BLS_MODULUS, TWO, and BLOB_LEN are defined within a lazy_static! block. For better maintainability and to avoid duplication, consider moving these constants to a central configuration or constants file. This change would align with the previously discussed improvements and centralize the configuration, making the codebase easier to manage.

Comment on lines +161 to +168
fn data_to_blobs(blob_size: u64, block_data: Vec<BigUint>) -> Result<Vec<Vec<u8>>> {
// Validate blob size
if blob_size < 32 {
return Err(eyre!(
"Blob size must be at least 32 bytes to accommodate a single FieldElement/BigUint, but was {}",
blob_size,
));
}
Copy link

Choose a reason for hiding this comment

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

Replace panic with error handling in data_to_blobs.

Instead of panicking when the blob size is too small, consider returning an error. This approach enhances the robustness of the function and improves user experience by providing a clear error message instead of terminating the application.

if blob_size < 32 {
    return Err("Blob size must be at least 32 bytes to accommodate a single FieldElement/BigUint".into());
}

Comment on lines 275 to 306
// padding of 127 bits
let mut binary_string = "0".repeat(127);

// class flag of one bit
if class_flag {
word += FieldElement::from_hex_be(CLASS_FLAG_TRUE).unwrap();
binary_string += "1"
} else {
binary_string += "0"
}
if let Some(new_nonce) = nonce_change {
word += new_nonce + FieldElement::from_hex_be(NONCE_BASE).unwrap();

// checking for nonce here
if let Some(_new_nonce) = nonce_change {
let bytes: [u8; 32] = nonce_change.unwrap().to_bytes_be();
let biguint = BigUint::from_bytes_be(&bytes);
let binary_string_local = format!("{:b}", biguint);
let padded_binary_string = format!("{:0>64}", binary_string_local);
binary_string += &padded_binary_string;
} else {
let binary_string_local = "0".repeat(64);
binary_string += &binary_string_local;
}

word += FieldElement::from(num_changes);
let binary_representation = format!("{:b}", num_changes);
let padded_binary_string = format!("{:0>64}", binary_representation);
binary_string += &padded_binary_string;

let biguint = BigUint::from_str_radix(binary_string.as_str(), 2).expect("Invalid binary string");

// Now convert the BigUint to a decimal string
let decimal_string = biguint.to_str_radix(10);

let word = FieldElement::from_dec_str(&decimal_string).expect("issue while converting to fieldElement");
Copy link

Choose a reason for hiding this comment

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

Optimize nonce handling in da_word.

Consider refactoring the nonce handling to avoid unnecessary conversions and potential performance issues. Here's a proposed change:

if let Some(new_nonce) = nonce_change {
    let biguint = BigUint::from_bytes_be(&new_nonce.to_bytes_be());
    binary_string += &format!("{:0>64}", biguint.to_str_radix(2));
} else {
    binary_string += &"0".repeat(64);
}

This change avoids redundant conversions and directly formats the BigUint into a binary string.

crates/orchestrator/src/jobs/da_job/mod.rs Show resolved Hide resolved

let tx = TxEip4844 {
chain_id,
nonce: 0, // can be block number
Copy link
Contributor

@unstark unstark Jun 14, 2024

Choose a reason for hiding this comment

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

If I'm not missing something, it won't be set right?
There should be NonceFiller in the alloy provider chain to handle that, couldn't find it explicitly set.

Copy link
Contributor

Choose a reason for hiding this comment

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

ya makes sense, @Mohiiit let's fetch the nonce from the RPC itself

gas_limit: 30_000_000,
max_fee_per_gas: eip1559_est.max_fee_per_gas.to_string().parse()?,
max_priority_fee_per_gas,
to: addr, // maybe to the L1 contract for verification??
Copy link
Contributor

@unstark unstark Jun 14, 2024

Choose a reason for hiding this comment

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

to, input, and gas_limit should probably be function arguments, if the goal is to reuse Starknet core contract, that would be its address, updateStateKzgDA calldata, and appropriate gas_limit to account for the spendings

Copy link
Contributor

Choose a reason for hiding this comment

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

right. i think we should fill in to and gas_limit for now. input can be done in a refactor later on when we integrate updateState

@Mohiiit we can ideally take to as an input and gas_limit can be estimated?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @unstark, I have set the nonce by fetching it directly and used the to address as an input. Created an issue for the gas limit for now :)

@apoorvsadana apoorvsadana merged commit 4343a41 into madara-alliance:main Jun 17, 2024
6 checks passed
@0x5ea000000 0x5ea000000 mentioned this pull request Jul 9, 2024
ocdbytes pushed a commit that referenced this pull request Oct 16, 2024
* strucutre for sending blob added

* [test]: function defined

* added condition to fetch nonce when the state_diff len is not-zero

* updated the condition for nonce getting, to not get it for one contract address

* test added for fft function

* removed some unused comments

* updated test_state_update_to_blob_Data test

* deleted extra files

* issue resolved

* mocking added for state update to blob function

* estimation added for txn and chain id dynamically setting

* txn inclusion logic added and code cleanup

* error message updated for blob length error

* linting fix

* linting fix

* toml linting fixed

* added nonce and to address

---------

Co-authored-by: apoorvsadana <[email protected]>
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