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

Remove address from encoding #119

Merged
merged 3 commits into from
Oct 1, 2024
Merged

Conversation

ryardley
Copy link
Contributor

@ryardley ryardley commented Oct 1, 2024

After the conversation with @auryn-macmillan this removes the encoding of the inputValidator from the e3Params and relies on the Mock contract to pass in the inputValidator

e3ProgramParams now only need to be the bytes representation of the BfvParamerters

Summary by CodeRabbit

Release Notes

  • New Features

    • Simplified event processing logic for E3Requested and CiphertextOutputPublished events.
    • Updated MockE3Program contract to allow dynamic input validator management.
  • Bug Fixes

    • Enhanced clarity and correctness in test cases for the Enclave contract.
  • Chores

    • Streamlined the script for launching and managing cipher nodes in the EVM environment.

Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The pull request introduces significant changes across multiple files, primarily focusing on the handling of events related to the E3Requested and CiphertextOutputPublished functionalities. Key alterations include the removal of encoding and decoding functions, simplification of parameter handling, and updates to related tests and deployment scripts. Additionally, the MockE3Program contract has been modified to enhance its input validation capabilities, and the deployment logic for mock contracts has been reorganized.

Changes

Files Change Summary
packages/ciphernode/core/src/evm_enclave.rs Removed decode_e3_params and encode_e3_params functions; simplified E3Requested and CiphertextOutputPublished event processing; removed the test module.
packages/ciphernode/core/src/lib.rs Removed public exports for decode_e3_params and encode_e3_params.
packages/ciphernode/enclave_node/src/bin/pack_e3_params.rs Removed no_crp and input_validator fields from Args struct; eliminated related logic and function calls.
packages/evm/contracts/test/MockE3Program.sol Introduced storageInputValidator variable; updated constructor and added setInputValidator method; modified validate function to read state variables.
packages/evm/deploy/mocks.ts Renamed and reordered mock contract deployments; updated deployment logic to reflect new contract names and dependencies.
packages/evm/test/Enclave.spec.ts Updated setup to include inputValidator address; simplified e3ProgramParams handling in tests; adjusted assertions to match new parameter structures.
packages/evm/test/fixtures/MockE3Program.fixture.ts Modified deployE3ProgramFixture to accept inputValidatorAddress as a parameter during contract deployment.
tests/basic_integration/test.sh Launched four cipher nodes in parallel; removed --input-validator parameter from ENCODED_PARAMS assignment.

Possibly related PRs

Suggested reviewers

  • auryn-macmillan
  • hmzakhalid
  • nginnever

🐇 In the code we hop and play,
Simplifying things along the way.
Events now dance with ease and grace,
No more clutter, just a clear space.
With every change, we leap so high,
A cleaner code, oh me, oh my! 🐇


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.

@ryardley ryardley marked this pull request as ready for review October 1, 2024 01:16
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: 2

🧹 Outside diff range and nitpick comments (8)
packages/evm/test/fixtures/MockE3Program.fixture.ts (1)

6-8: LGTM: Contract deployment updated correctly.

The deploy method now correctly includes the inputValidatorAddress parameter, aligning with the PR objectives.

Consider using object destructuring for better readability:

- const deployment = await (
-   await ethers.getContractFactory("MockE3Program")
- ).deploy(inputValidatorAddress);
+ const MockE3Program = await ethers.getContractFactory("MockE3Program");
+ const deployment = await MockE3Program.deploy(inputValidatorAddress);
packages/ciphernode/enclave_node/src/bin/pack_e3_params.rs (2)

Line range hint 13-25: Update struct documentation to reflect removed fields

The removal of no_crp and input_validator fields from the Args struct aligns with the PR objective. This simplification of the command-line interface is a positive change.

Consider updating the struct's documentation comment to reflect these changes. The current comment mentions CRP generation, which is no longer applicable:

- #[command(author, version, about="Encodes BFV parameters whilst generating a random CRP", long_about = None)]
+ #[command(author, version, about="Encodes BFV parameters", long_about = None)]

32-33: LGTM: Simplified encoding process

The removal of encode_e3_params and direct use of encode_bfv_params aligns with the PR objective and simplifies the encoding process. This change maintains the core functionality while removing unnecessary complexity.

For improved clarity, consider adding a brief comment explaining the purpose of the encoded variable:

+ // Encode BFV parameters
let encoded = encode_bfv_params(args.moduli, args.degree, args.plaintext_modulus);
tests/basic_integration/test.sh (2)

Line range hint 95-106: LGTM: Efficient parallel launch of cipher nodes.

The parallel launch of four cipher nodes with unique addresses is well-implemented and aligns with the PR objectives. This approach potentially improves the efficiency of the testing process.

Consider using a loop to launch the cipher nodes, which could make the code more maintainable:

for address in $CIPHERNODE_ADDRESS_1 $CIPHERNODE_ADDRESS_2 $CIPHERNODE_ADDRESS_3 $CIPHERNODE_ADDRESS_4; do
  heading "Launch ciphernode $address"
  yarn ciphernode:launch --address $address --rpc "$RPC_URL" --enclave-contract $ENCLAVE_CONTRACT --registry-contract $REGISTRY_CONTRACT &
done

Line range hint 166-166: LGTM: Clarifying comment for plaintext comparison.

The added comment "Assume plaintext is shorter" provides useful context for the subsequent comparison operation, improving code readability.

Consider expanding the comment to provide more context about why this assumption is made and what implications it has. For example:

# Assume decrypted plaintext might be longer due to padding, so we check if it starts with the expected plaintext
packages/evm/test/Enclave.spec.ts (2)

47-49: LGTM! Consider adding a comment for clarity.

The changes to the deployE3ProgramFixture function call and the simplification of e3ProgramParams align well with the PR objective of removing the address from encoding. This should make the tests more focused on the actual behavior rather than the encoding details.

Consider adding a brief comment explaining the significance of the "0x12345678" value used for e3ProgramParams. This would help other developers understand the purpose and meaning of this test data.

Also applies to: 84-84


544-547: LGTM! Consider adding an assertion for improved clarity.

The changes to this test case appropriately adjust for the new e3ProgramParams format and focus on the correct behavior when the E3 Program doesn't return a valid input validator address. This is an important edge case to cover.

To improve the clarity of the test, consider adding an assertion before the main test expectation to verify that the input validator has indeed been set to the zero address. This would make the test setup more explicit:

expect(await mocks.e3Program.inputValidator()).to.equal(ethers.ZeroAddress);

Also applies to: 555-555

packages/ciphernode/core/src/evm_enclave.rs (1)

Line range hint 15-29: Consider removing inputValidator from the E3 struct if it's no longer required

Since the inputValidator is no longer being encoded within e3ProgramParams as per the PR objectives, and given that the encoding functions have been removed, consider removing the inputValidator field from the E3 struct if it is no longer used elsewhere in the codebase. This will help simplify the structure and prevent potential confusion.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e8b6ce9 and bf2da43.

📒 Files selected for processing (8)
  • packages/ciphernode/core/src/evm_enclave.rs (2 hunks)
  • packages/ciphernode/core/src/lib.rs (0 hunks)
  • packages/ciphernode/enclave_node/src/bin/pack_e3_params.rs (2 hunks)
  • packages/evm/contracts/test/MockE3Program.sol (1 hunks)
  • packages/evm/deploy/mocks.ts (1 hunks)
  • packages/evm/test/Enclave.spec.ts (7 hunks)
  • packages/evm/test/fixtures/MockE3Program.fixture.ts (1 hunks)
  • tests/basic_integration/test.sh (3 hunks)
💤 Files with no reviewable changes (1)
  • packages/ciphernode/core/src/lib.rs
🔇 Additional comments (22)
packages/evm/test/fixtures/MockE3Program.fixture.ts (3)

5-5: LGTM: Function signature updated correctly.

The addition of the inputValidatorAddress parameter aligns with the PR objectives and allows for more flexible testing scenarios.


10-10: LGTM: Return statement remains correct.

The return statement correctly creates and returns a contract instance using the deployed address. No changes were necessary here.


5-10: Summary: Changes successfully implement PR objectives.

The modifications to deployE3ProgramFixture align well with the PR objectives:

  1. The function now accepts inputValidatorAddress as a parameter.
  2. The MockE3Program contract deployment uses this address directly.
  3. This change removes the need for encoding the inputValidator within the e3Params.

These changes should improve clarity and maintainability as intended.

To ensure these changes are consistently applied throughout the codebase, run the following script:

✅ Verification successful

Verification Successful: All calls to deployE3ProgramFixture include the inputValidatorAddress parameter.

The modifications to deployE3ProgramFixture have been consistently applied throughout the codebase:

  • All instances of deployE3ProgramFixture now include the inputValidatorAddress parameter as intended.

These changes confirm that the PR objectives are fully met, enhancing the clarity and maintainability of the code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all calls to deployE3ProgramFixture include the inputValidatorAddress parameter

# Test: Search for function calls to deployE3ProgramFixture
# Expect: All calls should include a parameter for inputValidatorAddress
rg --type typescript 'deployE3ProgramFixture\s*\(' -A 3

Length of output: 92


Script:

#!/bin/bash
# Description: Verify that all calls to deployE3ProgramFixture include the inputValidatorAddress parameter

# Test: Search for function calls to deployE3ProgramFixture without specifying the file type
# Expect: All calls should include a parameter for inputValidatorAddress
rg 'deployE3ProgramFixture\s*\(' -A 3

Length of output: 682

packages/ciphernode/enclave_node/src/bin/pack_e3_params.rs (2)

2-2: LGTM: Import change aligns with PR objective

The change from encode_e3_params to encode_bfv_params is consistent with the PR's goal of removing address encoding and simplifying the parameter encoding process.


Line range hint 1-38: Summary: Changes align well with PR objectives

The modifications in this file consistently support the PR's goal of removing address encoding from the e3Params. The simplification of the Args struct, removal of encode_e3_params, and focus on BFV parameter encoding contribute to a more streamlined and focused codebase. These changes appear to be well-considered and align with the discussion mentioned in the PR description.

packages/evm/deploy/mocks.ts (4)

14-18: LGTM. Deployment order changed as expected.

The deployment of MockDecryptionVerifier remains unchanged in its implementation, but its position in the deployment order has been adjusted as mentioned in the AI summary. This change doesn't affect its functionality or usage later in the file.


20-24: LGTM. New MockInputValidator aligns with PR objectives.

The addition of the MockInputValidator deployment is in line with the PR objectives of relying on the Mock contract to provide the inputValidator. This change supports the removal of inputValidator encoding from e3Params.


Line range hint 1-54: Overall, changes align well with PR objectives.

The modifications in this file successfully implement the intended changes outlined in the PR objectives. The reordering and renaming of mock contract deployments, along with the introduction of MockInputValidator, effectively support the removal of inputValidator encoding from e3Params. The changes are consistent and well-implemented.


26-30: LGTM. Significant change in MockE3Program deployment.

The deployment of MockE3Program (previously MockComputeProvider) now includes the address of MockInputValidator as an argument. This change is crucial and aligns perfectly with the PR objectives of removing the encoding of the inputValidator from e3Params and instead relying on the Mock contract to provide it.

To ensure this change is reflected in the contract implementation, please run the following script:

#!/bin/bash
# Check the MockE3Program contract for changes related to inputValidator
ast-grep --lang solidity --pattern 'contract MockE3Program {
  $$$
  constructor($_) {
    $$$
  }
  $$$
}'
tests/basic_integration/test.sh (4)

93-94: LGTM: Clear comment for cipher node launch.

This comment effectively introduces the subsequent operations for launching cipher nodes, improving code readability.


107-108: LGTM: Aggregator node configuration.

The addition of an aggregator node with specific configuration is well-implemented and aligns with the PR objectives. The comment provides useful context about its role.

Could you clarify which of the four previously launched nodes is configured as the aggregator? It might be helpful to add this information to the comment or consider launching the aggregator node with one of the predefined addresses for consistency.


Line range hint 1-180: Overall assessment: Well-implemented changes with minor suggestions for improvement.

The modifications to this integration test script align well with the PR objectives. The changes improve the handling of cipher nodes, including the parallel launch of multiple nodes and the addition of an aggregator node. The removal of the inputValidator from the encoded parameters is consistent with the PR summary.

Key improvements:

  1. Efficient parallel launch of cipher nodes
  2. Clear identification of the aggregator node
  3. Removal of inputValidator from encoded parameters
  4. Enhanced comments for better readability

Consider implementing the suggested refactorings and clarifications to further improve the script's maintainability and clarity.


128-129: LGTM: Removal of input validator from encoded parameters.

The removal of the --input-validator parameter from the ENCODED_PARAMS assignment aligns with the PR objectives and the discussion mentioned in the PR summary.

To ensure this change doesn't have unintended consequences, please verify that:

  1. The Mock contract correctly provides the inputValidator.
  2. Any code that previously relied on the inputValidator being part of ENCODED_PARAMS has been updated accordingly.

You can use the following command to check for any remaining references to inputValidator in the codebase:

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

Line range hint 577-594: LGTM! Test case properly updated.

The changes to this test case correctly adapt to the new e3ProgramParams format and the way the input validator address is handled. The test now directly verifies that the correct input validator address is set in the E3 instance, which maintains good test coverage for this functionality.


Line range hint 1-1337: Overall, the changes look good and maintain test coverage.

The modifications in this file consistently adapt the tests to the new e3ProgramParams format, removing the encoding of the input validator address. The changes are focused and appear to maintain the existing test coverage while reflecting the updated implementation.

Key points:

  1. The setup function has been updated to pass the input validator address separately.
  2. Test cases checking the E3 instance properties have been adjusted to verify the input validator address directly.
  3. The e3ProgramParams format has been simplified across all relevant tests.

These changes align well with the PR objective of removing the address from encoding.

packages/evm/contracts/test/MockE3Program.sol (4)

9-10: Declaration of storageInputValidator is appropriate

Adding storageInputValidator as a private state variable of type IInputValidator appropriately stores the input validator instance.


11-13: Constructor correctly initializes storageInputValidator

The constructor accepts an IInputValidator and initializes storageInputValidator, which is correct.


26-26: Correctly updated validate function to view

Adding the view modifier to validate is appropriate since it now reads from the state variable storageInputValidator.


33-33: validate function now uses storageInputValidator directly

Assigning inputValidator = storageInputValidator aligns with the PR objective of removing the encoding of inputValidator from e3ProgramParams.

packages/ciphernode/core/src/evm_enclave.rs (3)

9-9: Import of Address from alloy::primitives is necessary and correct

The addition of primitives::{Address} ensures that the Address type is available for use in this file, particularly in the connect_evm_enclave function where contract_address: Address is a parameter.


53-53: Direct assignment of program_params to params simplifies the conversion

The direct conversion of e3ProgramParams to a vector and assigning it to params removes unnecessary decoding logic. This aligns with the goal of streamlining parameter handling and enhances code clarity.


Line range hint 70-80: Ensure test coverage is maintained after removing the test module

The removal of the test module (#[cfg(test)] mod tests) may reduce the overall test coverage for this file. To maintain code reliability and prevent regressions, please ensure that adequate tests are added elsewhere to cover the functionalities that were previously tested.

Run the following script to identify areas lacking test coverage:

Additionally, verify that there are no residual references to inputValidator:

✅ Verification successful

Test Coverage Maintained

Inline tests using #[test] annotations are present in events.rs and ordered_set.rs, ensuring that test coverage remains intact despite the removal of the separate test module.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: List all Rust test modules in the codebase to verify test coverage.

# Test: Search for all occurrences of test modules. Expect: Tests exist for critical functionalities.
rg --type rust '#\[cfg\(test\)\] mod tests' --pretty

Length of output: 54


Script:

#!/bin/bash
# Description: Search for any remaining references to `inputValidator` in the codebase.

# Test: Find all occurrences of `inputValidator`. Expect: Only necessary usages remain.
rg --type rust 'inputValidator'

Length of output: 107


Script:

#!/bin/bash
# Description: Search for Rust test functions and test files to verify test coverage.

# Test: Find all occurrences of test functions annotated with #[test].
rg --type rust '#\[test\]' --pretty

# Test: Find all test files following the *_test.rs naming convention or located in the tests/ directory.
rg --type rust 'tests?(/|/.*_test\.rs)' --files

Length of output: 423

packages/evm/deploy/mocks.ts Show resolved Hide resolved
packages/evm/contracts/test/MockE3Program.sol Show resolved Hide resolved
Copy link
Member

@auryn-macmillan auryn-macmillan left a comment

Choose a reason for hiding this comment

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

lgtm

@ryardley ryardley merged commit 5122d23 into main Oct 1, 2024
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 9, 2024
This was referenced Oct 31, 2024
@ryardley ryardley deleted the ry/remove_input_validator_addres branch December 5, 2024 06:39
@coderabbitai coderabbitai bot mentioned this pull request Feb 7, 2025
10 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