Skip to content

Commit 073ba29

Browse files
committed
Merge branch 'master' into struct-namespace
# Conflicts: # wrappers/QuantumGravityBridge.sol/wrapper.go
2 parents 55167a1 + 3bacf00 commit 073ba29

File tree

11 files changed

+691
-12
lines changed

11 files changed

+691
-12
lines changed

Diff for: .github/workflows/contract-inheritance-check.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check Contract Inheritance
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
check_inheritance:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: 16
21+
22+
- name: Install Surya
23+
run: |
24+
npm install -g surya
25+
26+
- name: Run Surya Inheritance Check
27+
run: |
28+
./scripts/upgradability_check.sh

Diff for: .github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
check-solidity-formatting:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
with:
1515
submodules: recursive
1616

Diff for: .github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
forge-test:
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222
with:
2323
submodules: recursive
2424

@@ -39,7 +39,7 @@ jobs:
3939
runs-on: ubuntu-latest
4040
needs: forge-test
4141
steps:
42-
- uses: actions/checkout@v3
42+
- uses: actions/checkout@v4
4343
with:
4444
submodules: recursive
4545

Diff for: .gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "ethereum/solidity/lib/openzeppelin-contracts"]
55
path = lib/openzeppelin-contracts
66
url = https://github.com/openzeppelin/openzeppelin-contracts
7+
[submodule "lib/openzeppelin-contracts-upgradeable"]
8+
path = lib/openzeppelin-contracts-upgradeable
9+
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ It does not support bridging assets such as fungible or non-fungible tokens dire
8181
It works by relying on a set of signers to attest to some event on Celestia: the Celestia validator set.
8282
The QGB contract keeps track of the Celestia validator set by updating its view of the validator set with `updateValidatorSet()`.
8383
More than 2/3 of the voting power of the current view of the validator set must sign off on new relayed events, submitted with `submitDataRootTupleRoot()`.
84-
Each event is a batch of `DataRootTuple`s, with each tuple representing a single [data root (i.e. block header)](https://celestiaorg.github.io/celestia-specs/latest/specs/data_structures.html#header).
84+
Each event is a batch of `DataRootTuple`s, with each tuple representing a single [data root (i.e. block header)](https://celestiaorg.github.io/celestia-app/specs/data_structures.html#header).
8585
Relayed tuples are in the same order as Celestia block headers.
8686

8787
### Events and messages relayed

Diff for: lib/openzeppelin-contracts-upgradeable

Diff for: scripts/upgradability_check.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# this script will check if the QGB contract is inheriting the correct upgradability contracts.
4+
5+
out=$(surya inheritance src/QuantumGravityBridge.sol | grep -i "\"QuantumGravityBridge\" ->" | cut -d ">" -f 2 | sed 's/[";]//g')
6+
7+
required_contracts=("Initializable" "UUPSUpgradeable" "OwnableUpgradeable")
8+
missing_contracts=()
9+
10+
for field in "${required_contracts[@]}"; do
11+
if ! grep -q "\<$field\>" <<< "$out"; then
12+
missing_contracts+=("$field")
13+
fi
14+
done
15+
16+
if [ ${#missing_contracts[@]} -eq 0 ]; then
17+
echo "The QuantumGravityBridge contract is inheriting the right contracts. Exiting."
18+
exit 0
19+
else
20+
echo "The QuantumGravityBridge contract is missing the necessary inherited contracts: ${missing_contracts[*]}"
21+
exit 1
22+
fi

Diff for: src/QuantumGravityBridge.sol

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.19;
33

4+
import "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol";
5+
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
6+
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
47
import "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol";
58

69
import "./Constants.sol";
@@ -31,7 +34,9 @@ struct Signature {
3134
/// (see ./DataRootTuple.sol), with each tuple representing a single data root
3235
/// in a Celestia block header. Relayed tuples are in the same order as the
3336
/// block headers.
34-
contract QuantumGravityBridge is IDAOracle {
37+
/// @dev DO NOT REMOVE INHERITENCE OF THE FOLLOWING CONTRACTS: Initializable, UUPSUpgradeable and
38+
/// OwnableUpgradeable! They're essential for upgradability.
39+
contract QuantumGravityBridge is IDAOracle, Initializable, UUPSUpgradeable, OwnableUpgradeable {
3540
// Don't change the order of state for working upgrades AND BE AWARE OF
3641
// INHERITANCE VARIABLES! Inherited contracts contain storage slots and must
3742
// be accounted for in any upgrades. Always test an exact upgrade on testnet
@@ -99,7 +104,8 @@ contract QuantumGravityBridge is IDAOracle {
99104
/// @param _validatorSetHash Initial validator set hash. This does not need
100105
/// to be the genesis validator set of the bridged chain, only the initial
101106
/// validator set of the bridge.
102-
constructor(uint256 _nonce, uint256 _powerThreshold, bytes32 _validatorSetHash) {
107+
/// @dev DO NOT REMOVE THE INITIALIZER! It is mandatory for upgradability.
108+
function initialize(uint256 _nonce, uint256 _powerThreshold, bytes32 _validatorSetHash) public initializer {
103109
// CHECKS
104110

105111
bytes32 newCheckpoint = domainSeparateValidatorSetHash(_nonce, _powerThreshold, _validatorSetHash);
@@ -110,11 +116,20 @@ contract QuantumGravityBridge is IDAOracle {
110116
state_lastValidatorSetCheckpoint = newCheckpoint;
111117
state_powerThreshold = _powerThreshold;
112118

119+
/// @dev Initialize the OwnableUpgradeable explicitly.
120+
/// DO NOT REMOVE! It is mandatory for allowing the owner to upgrade.
121+
__Ownable_init(_msgSender());
122+
113123
// LOGS
114124

115125
emit ValidatorSetUpdatedEvent(_nonce, _powerThreshold, _validatorSetHash);
116126
}
117127

128+
/// @dev only authorize the upgrade for the owner of the contract.
129+
/// Additional access control logic can be added to allow multiple actors to upgrade.
130+
/// @dev DO NOT REMOVE! It is mandatory for upgradability.
131+
function _authorizeUpgrade(address) internal override onlyOwner {}
132+
118133
/// @notice Utility function to check if a signature is nil.
119134
/// If all bytes of the 65-byte signature are zero, then it's a nil signature.
120135
function isSigNil(Signature calldata _sig) private pure returns (bool) {

Diff for: src/lib/verifier/test/DAVerifier.t.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ contract DAVerifierTest is DSTest {
7777

7878
validators.push(Validator(cheats.addr(testPriv1), votingPower));
7979
bytes32 hash = computeValidatorSetHash(validators);
80-
bridge = new QuantumGravityBridge(initialVelsetNonce, (2 * votingPower) / 3, hash);
80+
bridge = new QuantumGravityBridge();
81+
bridge.initialize(initialVelsetNonce, (2 * votingPower) / 3, hash);
8182

8283
bytes32 newDataRootTupleRoot =
8384
domainSeparateDataRootTupleRoot(fixture.dataRootTupleRootNonce(), fixture.dataRootTupleRoot());

Diff for: src/test/QuantumGravityBridge.t.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ contract RelayerTest is DSTest {
3535

3636
validators.push(Validator(cheats.addr(testPriv1), votingPower));
3737
bytes32 hash = computeValidatorSetHash(validators);
38-
bridge = new QuantumGravityBridge(initialVelsetNonce, (2 * votingPower) / 3, hash);
38+
bridge = new QuantumGravityBridge();
39+
bridge.initialize(initialVelsetNonce, (2 * votingPower) / 3, hash);
3940
}
4041

4142
function testUpdateValidatorSet() public {

0 commit comments

Comments
 (0)