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

feat: Instant Rewards contract audit suggestions #177

Merged

Conversation

andresaiello
Copy link
Collaborator

@andresaiello andresaiello commented Aug 29, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced signature verification process in the InstantRewards contract using EIP712 for improved security and usability.
    • Updated claim data handling to allow raw byte signatures, simplifying the signature process.
    • Improved test functions to support multi-chain environments by including chain ID and verifying contract parameters.
  • Bug Fixes

    • Removed outdated hashing functions that could lead to inconsistencies in NFT update processing.
  • Documentation

    • Updated test documentation to reflect changes in function signatures and parameters for clarity.
  • Chores

    • Updated development dependencies for improved functionality and security.

Copy link

coderabbitai bot commented Aug 29, 2024

Walkthrough

Walkthrough

The recent changes involve updates to the InstantRewards and ZetaXP smart contracts, focusing on enhancing signature verification processes and simplifying data structures. The InstantRewards contract now utilizes EIP712 for typed data signatures, improving security. The ZetaXP contract has removed the _calculateHash function, affecting its update logic. Additionally, modifications to the testing files enhance the signature generation process by including chain ID and verifying contract details.

Changes

Files Change Summary
packages/zevm-app-contracts/contracts/instant-rewards/InstantRewards.sol Updated Solidity version, added inheritance from Ownable2Step and EIP712, modified ClaimData structure, and refactored signature verification.
packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol Removed the _calculateHash function, impacting NFT update logic.
packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts Enhanced getClaimDataSigned function to include chainId and verifyingContract parameters.
packages/zevm-app-contracts/test/instant-rewards/test.helpers.ts Removed Signature interface, simplified ClaimDataSigned structure, and updated getSignature function to include new parameters.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract
    participant SignatureChecker

    User->>Contract: Request claim
    Contract->>SignatureChecker: Verify signature with EIP712
    SignatureChecker-->>Contract: Return verification result
    Contract-->>User: Claim processed or rejected
Loading

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

@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 db688da and 0250c90.

Files selected for processing (4)
  • packages/zevm-app-contracts/contracts/instant-rewards/InstantRewards.sol (2 hunks)
  • packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol (1 hunks)
  • packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts (11 hunks)
  • packages/zevm-app-contracts/test/instant-rewards/test.helpers.ts (2 hunks)
Additional comments not posted (20)
packages/zevm-app-contracts/test/instant-rewards/test.helpers.ts (2)

12-12: LGTM!

The change to simplify the signature property to a string type is approved.


15-45: LGTM!

The changes to the getSignature function, including the use of EIP-712 typed data signing, are approved. This enhances the security and clarity of the signature generation process.

packages/zevm-app-contracts/contracts/instant-rewards/InstantRewards.sol (7)

2-2: LGTM!

The update to Solidity version 0.8.9 is approved.


7-8: LGTM!

The import statements for EIP712 and SignatureChecker are approved.


10-10: LGTM!

The contract's inheritance from EIP712 is approved.


11-12: LGTM!

The definition of the CLAIM_TYPEHASH constant is approved.


16-16: LGTM!

The change to the ClaimData struct, simplifying the signature field to a bytes type, is approved.


35-35: LGTM!

The update to the constructor to include EIP712("InstantRewards", "1") is approved.


42-51: LGTM!

The refactoring of the _verify function to use the CLAIM_TYPEHASH and SignatureChecker is approved. This enhances the security and clarity of the signature verification process.

packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol (1)

Line range hint 1-1: LGTM!

The removal of the _calculateHash function is approved. Ensure that any functionality relying on this hash computation is updated accordingly.

packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts (10)

10-10: LGTM!

The constant HARDHAT_CHAIN_ID is correctly defined.


22-23: LGTM!

The getClaimDataSigned function is correctly updated to include chainId and verifyingContract, enhancing the security and context of the signature.

Also applies to: 37-37


66-74: LGTM!

The test case is correctly updated to include HARDHAT_CHAIN_ID and instantRewards.address when calling getClaimDataSigned.


96-104: LGTM!

The test case is correctly updated to include HARDHAT_CHAIN_ID and instantRewards.address when calling getClaimDataSigned.


117-125: LGTM!

The test case is correctly updated to include HARDHAT_CHAIN_ID and instantRewards.address when calling getClaimDataSigned.


138-146: LGTM!

The test case is correctly updated to include HARDHAT_CHAIN_ID and instantRewards.address when calling getClaimDataSigned.


161-169: LGTM!

The test case is correctly updated to include HARDHAT_CHAIN_ID and instantRewards.address when calling getClaimDataSigned.


188-196: LGTM!

The test case is correctly updated to include HARDHAT_CHAIN_ID and instantRewards.address when calling getClaimDataSigned.


218-226: LGTM!

The test cases are correctly updated to include HARDHAT_CHAIN_ID and instantRewards.address when calling getClaimDataSigned.

Also applies to: 229-237


255-263: LGTM!

The test cases are correctly updated to include HARDHAT_CHAIN_ID and instantRewards.address when calling getClaimDataSigned.

Also applies to: 265-273

GMaiolo
GMaiolo previously approved these changes Aug 29, 2024
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 0250c90 and 8ec9bee.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (6)
  • package.json (2 hunks)
  • packages/zevm-app-contracts/contracts/instant-rewards/InstantRewards.sol (4 hunks)
  • packages/zevm-app-contracts/contracts/xp-nft/test/xpNFTV2.sol (1 hunks)
  • packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol (2 hunks)
  • packages/zevm-app-contracts/package.json (1 hunks)
  • packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts (12 hunks)
Files skipped from review due to trivial changes (1)
  • packages/zevm-app-contracts/package.json
Files skipped from review as they are similar to previous changes (2)
  • packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol
  • packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts
Additional comments not posted (3)
packages/zevm-app-contracts/contracts/xp-nft/test/xpNFTV2.sol (1)

2-2: Approve the pragma version update but verify compatibility.

The update of the Solidity version pragma to ^0.8.20 is approved as it allows the use of newer compiler features. However, it's crucial to ensure that this update does not introduce any breaking changes or unexpected behavior in the contract. Consider running comprehensive tests to verify that all functionalities behave as expected with the new compiler version.

package.json (1)

32-32: Approve the dependency updates but verify project compatibility.

The updates to @nomiclabs/hardhat-ethers to ^2.2.3, ethers to 5.7.2, and hardhat to 2.22.6 are approved as they likely include important bug fixes and optimizations. However, it's essential to verify that these updates do not introduce any compatibility issues within the project. Consider running the project's full test suite to ensure all functionalities and integrations work as expected with the updated dependencies.

Also applies to: 58-59

packages/zevm-app-contracts/contracts/instant-rewards/InstantRewards.sol (1)

5-8: Approve the contract changes but verify new functionalities.

The changes to the InstantRewards contract, including the adoption of Ownable2Step and EIP712, enhance security and simplify the contract's structure. The refactoring of the _verify function to use SignatureChecker and the simplification of the ClaimData struct are particularly noteworthy. However, it's crucial to thoroughly test and verify these changes to ensure that the signature verification process is secure and functions correctly under all expected conditions.

Also applies to: 10-11, 16-16, 36-36, 43-50, 55-55

@andresaiello andresaiello merged commit 96809eb into main Sep 2, 2024
10 of 12 checks passed
@andresaiello andresaiello deleted the andy/pd-6549-instant-rewards-contract-audit-suggestions branch September 2, 2024 15:38
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