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

add: block number to e3 struct #150

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

auryn-macmillan
Copy link
Member

@auryn-macmillan auryn-macmillan commented Oct 18, 2024

This PR adds adds requestBlock to the E3 struct, allowing for simpler queries to fetch inputs for a given E3.

Summary by CodeRabbit

  • New Features

    • Enhanced tracking of requests by adding a requestBlock field to the E3 structure, capturing the block number at the time of the request.
    • Introduced a new modifier, onlyOwnerOrCiphernode, to improve access control for functions in the NaiveRegistryFilter contract.
  • Bug Fixes

    • Added a new error type, CiphernodeNotEnabled, to handle eligibility issues for ciphernodes.
  • Tests

    • Updated test cases for the request() method to verify the correct assignment of the new requestBlock property.

Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The changes in this pull request involve modifications to the Enclave contract and related files within the EVM package. A new field, requestBlock, has been added to the E3 struct in both the Enclave.sol and IE3.sol files to capture the block number at the time of a request. Additionally, the NaiveRegistryFilter contract introduces a new error type and modifier for enhanced access control. Corresponding updates are made to the test suite to validate the new functionality of the request() method.

Changes

File Path Change Summary
packages/evm/contracts/Enclave.sol Added uint256 requestBlock to E3 struct; modified request function to initialize requestBlock with block.number.
packages/evm/contracts/interfaces/IE3.sol Updated E3 struct to include uint256 requestBlock.
packages/evm/contracts/registry/NaiveRegistryFilter.sol Introduced new error CiphernodeNotEnabled; added modifier onlyOwnerOrCiphernode.
packages/evm/test/Enclave.spec.ts Enhanced tests for request() method to include assertions for requestBlock; updated tests to align with the new structure of E3.

Possibly related PRs

Suggested reviewers

  • nginnever
  • samepant
  • hmzakhalid

🐇 In the meadow where requests bloom,
A block number now finds its room.
With each call, the data flows,
Tracking where the request goes.
A hop, a jump, a new delight,
In the code, our future's bright! 🌼


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>, 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.

CodeRabbit Configuration 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
Contributor

@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

🧹 Outside diff range and nitpick comments (5)
packages/evm/contracts/interfaces/IE3.sol (1)

25-25: Consider potential gas cost impacts.

While the addition of the requestBlock field is straightforward and beneficial for querying, it's worth considering any potential impacts on gas costs, especially if E3 structs are frequently stored or retrieved from storage.

Consider running gas benchmarks before and after this change to quantify any differences in gas consumption for operations involving E3 structs.

packages/evm/contracts/registry/NaiveRegistryFilter.sol (1)

51-58: Consider documenting the intended usage of this modifier.

While the onlyOwnerOrCiphernode modifier is well-implemented, it's not currently applied to any functions in this contract. Consider adding a comment explaining its intended future usage or apply it to relevant functions if applicable.

packages/evm/contracts/Enclave.sol (1)

163-163: LGTM: requestBlock initialization in request function

The addition of requestBlock: block.number, in the E3 struct initialization within the request function is correct and aligns with the intended functionality. This change effectively captures the block number at which the E3 request is made.

Consider the following optimization:

To potentially save a small amount of gas, you could consider declaring a local variable for block.number at the beginning of the function and using it for both the requestBlock initialization and the seed calculation. This would ensure that the same block number is used consistently throughout the function and might save a small amount of gas by reducing the number of BLOCKNUMBER opcodes. For example:

uint256 currentBlock = block.number;
uint256 seed = uint256(keccak256(abi.encode(block.prevrandao, e3Id)));
// ... other code ...
E3 memory e3 = E3({
    // ... other fields ...
    requestBlock: currentBlock,
    // ... other fields ...
});

This change is optional and the current implementation is also correct.

packages/evm/test/Enclave.spec.ts (2)

590-592: Improve error handling for block retrieval

The error handling for getBlock is good practice, but it's unclear what happens if an error occurs. Consider logging the error or handling it more explicitly.

-      const block = await ethers.provider.getBlock("latest").catch((e) => e);
+      const block = await ethers.provider.getBlock("latest").catch((e) => {
+        console.error("Error retrieving latest block:", e);
+        throw e; // or handle the error in a way that makes sense for your tests
+      });

This change will provide more visibility into any potential issues with block retrieval.


590-595: Consider adding more test cases for requestBlock

While the current changes adequately test the basic functionality of the new requestBlock field, consider adding more specific test cases to ensure comprehensive coverage. For example:

  1. Test that requestBlock is set correctly for multiple E3 requests across different blocks.
  2. Verify that requestBlock remains unchanged after other operations like activation or output publishing.
  3. Test edge cases, such as when the block number is at its maximum value.

These additional tests would help ensure the robustness of the new requestBlock functionality.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c75f232 and 1fbb950.

📒 Files selected for processing (4)
  • packages/evm/contracts/Enclave.sol (1 hunks)
  • packages/evm/contracts/interfaces/IE3.sol (2 hunks)
  • packages/evm/contracts/registry/NaiveRegistryFilter.sol (2 hunks)
  • packages/evm/test/Enclave.spec.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (9)
packages/evm/contracts/interfaces/IE3.sol (2)

11-11: LGTM: Documentation updated correctly.

The new documentation line for the requestBlock field is clear, concise, and follows the existing documentation style.


25-25: LGTM: New field added correctly. Verify usage across codebase.

The requestBlock field has been added correctly to the E3 struct. This addition aligns with the PR objectives and should facilitate simpler queries for fetching inputs associated with a specific E3.

To ensure consistency, please verify that all parts of the codebase that create or use E3 structs have been updated to include this new field. Run the following script to check for potential places that might need updates:

✅ Verification successful

LGTM: requestBlock field added correctly. Verified usage across codebase.

The requestBlock field has been successfully added to the E3 struct. All existing usages in the codebase have been verified to ensure consistency and correctness.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find potential places where E3 structs are used and might need updates.

# Search for E3 struct usage
echo "Searching for E3 struct usage:"
rg --type solidity -i '\bE3\b' --glob '!**/interfaces/IE3.sol'

# Search for functions that might create or return E3 structs
echo -e "\nSearching for functions that might create or return E3 structs:"
rg --type solidity -i 'function.*\bE3\b'

Length of output: 387


Script:

#!/bin/bash
# Description: Find potential places where E3 structs are used and might need updates.

# Search for E3 struct usage in Solidity files
echo "Searching for E3 struct usage in .sol files:"
rg '\bE3\b' --type-add 'sol=*.sol' --type sol --glob '!**/interfaces/IE3.sol'

# Search for functions that might create or return E3 structs
echo -e "\nSearching for functions that might create or return E3 structs in .sol files:"
rg 'function\s+\w+\s*\(.*\)\s*returns\s*\(.*E3.*\)' --type-add 'sol=*.sol' --type sol

Length of output: 557


Script:

#!/bin/bash
# Description: Find potential places where E3 structs are used and might need updates.

# Add custom type for Solidity files
rg --type-add 'sol:*.sol'

# Search for E3 struct usage in Solidity files
echo "Searching for E3 struct usage in .sol files:"
rg '\bE3\b' --type sol --glob '!**/interfaces/IE3.sol'

# Search for functions that might create or return E3 structs in Solidity files
echo -e "\nSearching for functions that might create or return E3 structs in .sol files:"
rg 'function\s+\w+\s*\(.*\)\s*returns\s*\(.*E3.*\)' --type sol

Length of output: 872


Script:

#!/bin/bash
# Description: Find potential places where E3 structs are used and might need updates.

# Search for E3 struct usage in Solidity files, excluding interfaces/IE3.sol
echo "Searching for E3 struct usage in .sol files excluding interfaces/IE3.sol:"
rg '\bE3\b' -g '*.sol' -g '!interfaces/IE3.sol'

# Search for functions that create or return E3 structs in Solidity files, excluding interfaces/IE3.sol
echo -e "\nSearching for functions that might create or return E3 structs in .sol files excluding interfaces/IE3.sol:"
rg 'function\s+\w+\s*\(.*\)\s*returns\s*\(.*E3.*\)' -g '*.sol' -g '!interfaces/IE3.sol'

Length of output: 8325

packages/evm/contracts/registry/NaiveRegistryFilter.sol (3)

37-37: LGTM: New error enhances error handling for ciphernode eligibility.

The CiphernodeNotEnabled error is well-named and includes the relevant ciphernode address, which will be useful for debugging and logging. This addition aligns with the PR objective of improving access control for ciphernodes.


51-58: LGTM: New modifier enhances access control.

The onlyOwnerOrCiphernode modifier correctly implements the intended access control, allowing either the contract owner or an eligible ciphernode to proceed. It appropriately uses the ICiphernodeRegistry interface for eligibility checks and throws the newly added CiphernodeNotEnabled error when conditions are not met.


Line range hint 37-58: Summary: Enhancements to access control for ciphernodes.

The changes in this file successfully implement improved access control for ciphernodes:

  1. A new CiphernodeNotEnabled error provides clear error reporting.
  2. The onlyOwnerOrCiphernode modifier establishes a mechanism to restrict access to either the contract owner or eligible ciphernodes.

These additions align well with the PR objectives and are implemented consistently with the existing code style. Consider documenting the intended usage of the new modifier to provide clarity for future development.

packages/evm/contracts/Enclave.sol (3)

163-163: LGTM: Addition of requestBlock enhances E3 tracking

The addition of the requestBlock field to the E3 struct is a good improvement. It allows for easier tracking of when each E3 request was made, which aligns with the PR objective of facilitating simpler queries for fetching inputs associated with a specific E3.

Using block.number is a standard and reliable way to record the block at which the request occurred. This information can be valuable for various purposes, such as auditing, debugging, or implementing time-based logic in relation to E3 requests.


163-163: Summary: Addition of requestBlock enhances E3 tracking with minimal impact

The changes in this PR successfully add the requestBlock field to the E3 struct, achieving the objective of facilitating simpler queries for fetching inputs associated with a specific E3. The implementation is straightforward and doesn't introduce any apparent issues.

Key points:

  1. The change is localized to the E3 struct and request function.
  2. It provides valuable information for tracking when each E3 request was made.
  3. The impact on gas costs is likely minimal but should be verified.
  4. External integrations may need to be updated to handle the new field.

Overall, this change improves the functionality of the Enclave contract while maintaining its overall structure and logic. Ensure that appropriate testing is done, especially regarding gas costs and integration with existing systems.


163-163: Consider the impact on gas costs and external integrations

While the addition of the requestBlock field is beneficial, it's important to consider its implications:

  1. Gas Costs: The additional field in the E3 struct will slightly increase the gas cost of the request function. While this increase is likely minimal, it's worth noting, especially if this function is called frequently.

  2. External Integrations: Ensure that any off-chain services or other contracts that interact with the E3 struct are updated to handle the new field. This might include updating any parsing logic, database schemas, or interfaces that work with E3 data.

  3. Backwards Compatibility: If there are any existing E3 instances, consider how they will be handled. Will they have a default value for requestBlock, or will there be a migration process?

To assess the impact on gas costs, you could run gas profiling tests. Here's a script to help with that:

This will help quantify the gas cost impact of the change.

packages/evm/test/Enclave.spec.ts (1)

595-595: LGTM: New assertion aligns with PR objectives

The new assertion expect(e3.requestBlock).to.equal(block.number); correctly verifies that the requestBlock field is set to the current block number when the E3 is created. This change aligns well with the PR objective of adding a requestBlock field to the E3 struct.

@auryn-macmillan auryn-macmillan merged commit 95d32d8 into main Oct 18, 2024
3 checks passed
@auryn-macmillan auryn-macmillan deleted the auryn/add-block-timestamp-to-e3 branch October 18, 2024 15:47
@coderabbitai coderabbitai bot mentioned this pull request Nov 3, 2024
5 tasks
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.

2 participants