Skip to content

Commit 462583d

Browse files
1706 improve versioning for the light client contract (#1800)
* switched to using contract inheritance for new versions of the LC contract * added initialize methods for each version and a third version of the LC contract * added documentation about smart contract upgrades to read me and modified tests * adding more context to the docs with example that include the LC contract * add more deployment notes * use the reinitializer modifier to safeguard against more that one re-initialization in new implementations of an upgradable contract * improving comments
1 parent 2a26637 commit 462583d

8 files changed

+704
-325
lines changed

contracts/src/LightClient.sol

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,14 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
174174
function getVersion()
175175
public
176176
pure
177+
virtual
177178
returns (uint8 majorVersion, uint8 minorVersion, uint8 patchVersion)
178179
{
179180
return (1, 0, 0);
180181
}
181182

182183
/// @notice only the owner can authorize an upgrade
183-
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
184+
function _authorizeUpgrade(address newImplementation) internal virtual override onlyOwner {
184185
emit Upgrade(newImplementation);
185186
}
186187

@@ -237,7 +238,7 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
237238
function newFinalizedState(
238239
LightClientState memory newState,
239240
IPlonkVerifier.PlonkProof memory proof
240-
) external {
241+
) external virtual {
241242
//revert if we're in permissionedProver mode and the permissioned prover has not been set
242243
if (permissionedProverEnabled && msg.sender != permissionedProver) {
243244
if (permissionedProver == address(0)) {
@@ -287,12 +288,12 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
287288
}
288289

289290
/// @dev Simple getter function for the genesis state
290-
function getGenesisState() public view returns (LightClientState memory) {
291+
function getGenesisState() public view virtual returns (LightClientState memory) {
291292
return states[genesisState];
292293
}
293294

294295
/// @dev Simple getter function for the finalized state
295-
function getFinalizedState() public view returns (LightClientState memory) {
296+
function getFinalizedState() public view virtual returns (LightClientState memory) {
296297
return states[finalizedState];
297298
}
298299

@@ -322,7 +323,7 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
322323

323324
/// @notice Advance to the next epoch (without any precondition check!)
324325
/// @dev This meant to be invoked only internally after appropriate precondition checks are done
325-
function _advanceEpoch() private {
326+
function _advanceEpoch() internal virtual {
326327
bytes32 newStakeTableComm = computeStakeTableComm(states[finalizedState]);
327328
votingStakeTableCommitment = frozenStakeTableCommitment;
328329
frozenStakeTableCommitment = newStakeTableComm;
@@ -335,7 +336,12 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
335336
}
336337

337338
/// @notice Given the light client state, compute the short commitment of the stake table
338-
function computeStakeTableComm(LightClientState memory state) public pure returns (bytes32) {
339+
function computeStakeTableComm(LightClientState memory state)
340+
public
341+
pure
342+
virtual
343+
returns (bytes32)
344+
{
339345
return keccak256(
340346
abi.encodePacked(
341347
state.stakeTableBlsKeyComm,
@@ -349,7 +355,7 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
349355
/// non-zero address provided
350356
/// @dev this function can also be used to update the permissioned prover once it's a different
351357
/// address
352-
function setPermissionedProver(address prover) public onlyOwner {
358+
function setPermissionedProver(address prover) public virtual onlyOwner {
353359
if (prover == address(0)) {
354360
revert InvalidAddress();
355361
}
@@ -363,7 +369,7 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
363369

364370
/// @notice set the permissionedProverMode to false and set the permissionedProver to address(0)
365371
/// @dev if it was already disabled (permissioneProverMode == false), then revert with
366-
function disablePermissionedProverMode() public onlyOwner {
372+
function disablePermissionedProverMode() public virtual onlyOwner {
367373
if (permissionedProverEnabled) {
368374
permissionedProver = address(0);
369375
permissionedProverEnabled = false;
@@ -419,7 +425,7 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
419425
}
420426

421427
/// @notice get the number of L1 block updates
422-
function getStateUpdateBlockNumbersCount() public view returns (uint256) {
428+
function getStateUpdateBlockNumbersCount() public view virtual returns (uint256) {
423429
return stateUpdateBlockNumbers.length;
424430
}
425431

@@ -429,6 +435,7 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
429435
function getHotShotCommitment(uint256 hotShotBlockHeight)
430436
public
431437
view
438+
virtual
432439
returns (HotShotCommitment memory)
433440
{
434441
uint256 commitmentsHeight = hotShotCommitments.length;
@@ -447,7 +454,7 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
447454
}
448455

449456
/// @notice get the number of HotShot block commitments
450-
function getHotShotBlockCommitmentsCount() public view returns (uint256) {
457+
function getHotShotBlockCommitmentsCount() public view virtual returns (uint256) {
451458
return hotShotCommitments.length;
452459
}
453460
}

contracts/test/LightClientUpgradeToV2.t.sol

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)