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

Upgrade OZ libraries #1707

Merged
merged 10 commits into from
Feb 12, 2024
Merged

Upgrade OZ libraries #1707

merged 10 commits into from
Feb 12, 2024

Conversation

StefanIliev545
Copy link
Contributor

Why this change is needed

Migrate OZ libraries to version 5

What changes were made as part of this PR

Upgraded the packages, made the contracts compile. Fix for shadowing is separate.

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Dec 19, 2023

Walkthrough

The recent updates to the smart contract codebase include a Solidity compiler version bump to 0.8.20, the introduction of additional warnings for test files, and enhancements to contract functionality. The ManagementContract and MessageBus contracts now leverage an updated inheritance pattern using Ownable, and there's improved security with the use of MessageHashUtils for hash computations in the ManagementContract.

Changes

File Path Change Summary
contracts/hardhat.config.ts Updated Solidity version from 0.8.9 to 0.8.20 and added warning settings for src/testing directory.
contracts/src/management/ManagementContract.sol Added MessageHashUtils imports, updated constructor for Ownable, and changed hash computation logic.
contracts/src/messaging/MessageBus.sol Introduced a constructor invoking Ownable with msg.sender.
contracts/src/common/ConstantSupplyERC20.sol Modified import statement and refactored constructor for ERC20 contract.

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b528fcb and 8099ea5.
Files ignored due to filter (1)
  • contracts/package.json
Files selected for processing (3)
  • contracts/hardhat.config.ts (2 hunks)
  • contracts/src/management/ManagementContract.sol (2 hunks)
  • contracts/src/messaging/MessageBus.sol (1 hunks)
Additional comments: 5
contracts/hardhat.config.ts (1)
  • 23-23: The Solidity compiler version has been updated to 0.8.20. Ensure that all smart contracts in the project are compatible with this version and that no deprecated features are being used that could cause compilation errors or warnings.
contracts/src/management/ManagementContract.sol (3)
  • 7-7: The import of MessageHashUtils is new. Verify that the usage of this utility aligns with the intended cryptographic practices and that it's being used securely throughout the contract.

  • 18-18: The constructor now explicitly sets the owner to msg.sender using the Ownable constructor. Confirm that this change is consistent with the intended ownership initialization logic for all contracts inheriting from Ownable.

Verification successful

The initial script intended to search for constructors inheriting from Ownable and using the new explicit ownership assignment failed because solidity is not a supported language for ast-grep. To continue the verification process, we can use rg (ripgrep) to search for constructors in Solidity files that inherit from Ownable. We will look for the pattern constructor() Ownable(msg.sender) to confirm that the change is consistent across the codebase.


The script has successfully identified that the explicit ownership assignment using Ownable(msg.sender) in the constructor is present in both MessageBus.sol and ManagementContract.sol. This confirms that the change to the constructor in ManagementContract.sol is consistent with at least one other contract in the codebase that inherits from Ownable.

Based on the information provided, it appears that the intended ownership initialization logic for contracts inheriting from Ownable has been correctly implemented in the instances found.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for constructors that inherit Ownable to ensure they are using the new explicit ownership assignment
ast-grep --lang solidity --pattern $'contract $$$ is Ownable { constructor() Ownable($_) { $$$ } }'

Length of output: 217



Script:

#!/bin/bash
# Search for constructors in Solidity files that inherit from Ownable and use the new explicit ownership assignment
rg 'constructor\(\) Ownable\(msg.sender\)' --glob '*.sol'

Length of output: 227

* 124-127: The signature verification logic has been updated. Ensure that the new logic correctly verifies the signer's address and that there are no security implications due to the changes in how `calculatedHashSigned` is computed.
contracts/src/messaging/MessageBus.sol (1)
  • 11-11: The MessageBus contract now includes a constructor that sets the owner to msg.sender. This is a significant change in terms of contract ownership. Ensure that this change is intentional and that it does not introduce any security risks, especially if the MessageBus contract is meant to be owned by a specific entity or contract.

Comment on lines +58 to +60
},
'src/testing/**/*': {
default: 'off'
Copy link

Choose a reason for hiding this comment

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

The warning settings for files in the 'src/testing' directory have been turned off. This could potentially hide important warnings during the testing phase. It's recommended to only disable specific warnings that are known to be non-critical after thorough evaluation.

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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8099ea5 and 2201141.
Files ignored due to filter (10)
  • contracts/generated/ConstantSupplyERC20/ConstantSupplyERC20.go
  • contracts/generated/CrossChainMessenger/CrossChainMessenger.go
  • contracts/generated/EthereumBridge/EthereumBridge.go
  • contracts/generated/GasConsumerBalance/GasConsumerBalance.go
  • contracts/generated/ManagementContract/ManagementContract.go
  • contracts/generated/MessageBus/MessageBus.go
  • contracts/generated/ObsERC20/ObsERC20.go
  • contracts/generated/ObscuroBridge/ObscuroBridge.go
  • contracts/generated/WrappedERC20/WrappedERC20.go
  • contracts/package.json
Files selected for processing (2)
  • contracts/src/common/ConstantSupplyERC20.sol (1 hunks)
  • contracts/test/bridge-test.ts (1 hunks)
Additional comments: 4
contracts/src/common/ConstantSupplyERC20.sol (2)
  • 4-4: The import statement has been changed to use destructuring. This is a stylistic choice and does not impact functionality.

  • 8-12: The constructor reformatting improves readability and maintains the same logic.

contracts/test/bridge-test.ts (2)
  • 35-45: The addition of the owner parameter when deploying the ConstantSupplyERC20 contract is consistent with the new constructor signature. Ensure that the owner variable is used correctly in the context of the contract deployment.

  • 40-45: The use of a try-catch block for the ERC20 contract deployment is a good practice for handling potential deployment errors.

@@ -1,11 +1,13 @@
// SPDX-License-Identifier: Apache 2
pragma solidity >=0.7.0 <0.9.0;
Copy link

Choose a reason for hiding this comment

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

Consider narrowing the pragma solidity version to ^0.8.20 to match the updated Solidity version in hardhat.config.ts and ensure compatibility with the new OpenZeppelin library version.


const ERC20 = await hre.ethers.getContractFactory("ConstantSupplyERC20", owner);

console.log(`Deploying erc20`);
Copy link

Choose a reason for hiding this comment

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

Consider removing or commenting out the console.log statement before deployment for cleaner production code.


const erc20 = await ERC20.deploy("XXX", "XXX");
erc20address = erc20.address;
console.log(`Deployed erc20`);
Copy link

Choose a reason for hiding this comment

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

Consider removing or commenting out the console.log statement after deployment for cleaner production code.

Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

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

LGTM (I think).
@BedrockSquirrel , pls have a look as well when you get a chance

// the data must be signed with by the correct private key
// signature = f(PubKey, PrivateKey, message)
// address = f(signature, message)
// valid if attesterID = address
bytes32 calculatedHashSigned = ECDSA.toEthSignedMessageHash(abi.encodePacked(attesterID, requesterID, hostAddress, responseSecret));
bytes32 calculatedHashSigned = abi.encodePacked(attesterID, requesterID, hostAddress, responseSecret).toEthSignedMessageHash();
Copy link
Collaborator

Choose a reason for hiding this comment

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

this was the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, its in the go code where the signature is generated; We need to append to correct recovery id.

@StefanIliev545 StefanIliev545 merged commit cc3b104 into main Feb 12, 2024
3 checks passed
@StefanIliev545 StefanIliev545 deleted the siliev/upgrade-openzeppelin branch February 12, 2024 08:14
StefanIliev545 added a commit that referenced this pull request Feb 12, 2024
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