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: add support for UUPS proxy in QGB contract #177

Merged
merged 10 commits into from
Sep 8, 2023

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Aug 21, 2023

Overview

Closes #146

This provides the UUPS upgradability mechanism for the QGB smart contract. The deployment and upgrade scripts will be handled in a separate issue.

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

@rach-id rach-id added enhancement New feature or request contracts labels Aug 21, 2023
@rach-id rach-id self-assigned this Aug 21, 2023
@rach-id rach-id changed the title Upgradable feat: add support for UUPS proxy in QGB contract Aug 21, 2023
evan-forbes
evan-forbes previously approved these changes Aug 22, 2023
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

LGTM and makes sense but I'll defer to authors who are more up to date on upgradability patterns

@@ -35,7 +35,8 @@ contract RelayerTest is DSTest {

validators.push(Validator(cheats.addr(testPriv1), votingPower));
bytes32 hash = computeValidatorSetHash(validators);
bridge = new QuantumGravityBridge(initialVelsetNonce, (2 * votingPower) / 3, hash);
bridge = new QuantumGravityBridge();
bridge.initialize(initialVelsetNonce, (2 * votingPower) / 3, hash);
Copy link
Member

Choose a reason for hiding this comment

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

unrelated to this change question

I don't think so, but is there ever a scenario where we have to be worried about this math?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just a test, and we're defining ourselves the voting power for that validator. So it's okey

@rach-id
Copy link
Member Author

rach-id commented Aug 22, 2023

Turning to draft as I have some questions about the implementation I did, and I need to answer them before being 100% confident in this PR

@rach-id rach-id marked this pull request as draft August 22, 2023 09:33
@rach-id rach-id marked this pull request as ready for review August 22, 2023 18:14
@rach-id
Copy link
Member Author

rach-id commented Aug 22, 2023

Reopening for review, the implementation looks fine

Comment on lines 5 to 7
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
import "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol";
Copy link
Member

Choose a reason for hiding this comment

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

Nit, but can these be ordered alphabetically (including path)?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -31,7 +34,8 @@ struct Signature {
/// (see ./DataRootTuple.sol), with each tuple representing a single data root
/// in a Celestia block header. Relayed tuples are in the same order as the
/// block headers.
contract QuantumGravityBridge is IDAOracle {
/// @dev DO NOT REMOVE ANY INHERITED CONTRACT! They're essential for upgradability.
Copy link
Member

Choose a reason for hiding this comment

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

Since IDAOOracle isn't part of the upgradability logic, can it be removed later? If so then maybe document specifically which inherited contracts cant be removed.

Also, is there some way to enforce (potentially imperfectly, but at least as a first line of defence) that they aren't removed in CI? Maybe something like outputting a contract inheritance tree from the compiler and analyzing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've created the following bash script:

#!/usr/bin/env bash

out=$(surya inheritance src/QuantumGravityBridge.sol | grep -i "\"QuantumGravityBridge\" ->" | cut -d ">" -f 2  | sed 's/"//g' | sed 's/;//g')

required_contracts=("Initializable" "UUPSUpgradeable" "OwnableUpgradeable")
missing_contracts=()

for field in "${required_contracts[@]}"; do
    if ! grep -q "\<$field\>" <<< "$out"; then
        missing_contracts+=("$field")
    fi
done

if [ ${#missing_contracts[@]} -eq 0 ]; then
    echo "The QuantumGravityBridge contract is inheritting the right contracts. Exiting."
    exit 0
else
    echo "The QuantumGravityBridge contract is missing the necessary inherited contracts: ${missing_contracts[*]}"
    exit 1
fi

I can add it in a separate PR.

@rach-id rach-id enabled auto-merge (squash) September 7, 2023 14:06
@rach-id rach-id merged commit 42bb4d8 into celestiaorg:master Sep 8, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement upgradability
3 participants