From b0018df29b547a37bb9c20213ca2d9bd9827e27d Mon Sep 17 00:00:00 2001 From: Or Neeman Date: Tue, 8 Jun 2021 08:36:09 -0600 Subject: [PATCH 1/4] Make updateMembershipHistory in Validators.sol correct if epoch number is 0. Celo-blockchain has a tool called mycelo which applies the core contract migrations as part of genesis generation. This means that the epoch number when they are run is zero. However, the updateMembershipHistory() method in Validators.sol did not expect that to be possible. As a result, when mycelo adds a validator to a validator group, the method does not add a new entry to the member's history (specifically, it does not increase numEntries from 0 to 1 as it should). This commit fixes that by adding a condition to the check for whether to replace an existing entry, namely that the number of entries isn't zero. --- packages/protocol/contracts/governance/Validators.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/governance/Validators.sol b/packages/protocol/contracts/governance/Validators.sol index 6f8e3cd60c6..b58f962751b 100644 --- a/packages/protocol/contracts/governance/Validators.sol +++ b/packages/protocol/contracts/governance/Validators.sol @@ -1167,7 +1167,7 @@ contract Validators is history.lastRemovedFromGroupTimestamp = now; } - if (history.entries[head].epochNumber == epochNumber) { + if (history.numEntries > 0 && history.entries[head].epochNumber == epochNumber) { // There have been no elections since the validator last changed membership, overwrite the // previous entry. history.entries[head] = MembershipHistoryEntry(epochNumber, group); From 481d37f58608ac422b5250f88cb89d215566def7 Mon Sep 17 00:00:00 2001 From: Or Neeman Date: Tue, 8 Jun 2021 14:26:41 -0600 Subject: [PATCH 2/4] Switch from Initializable to InitializableV2 --- packages/protocol/contracts/governance/Validators.sol | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/governance/Validators.sol b/packages/protocol/contracts/governance/Validators.sol index b58f962751b..60bcd7a1c10 100644 --- a/packages/protocol/contracts/governance/Validators.sol +++ b/packages/protocol/contracts/governance/Validators.sol @@ -8,7 +8,7 @@ import "solidity-bytes-utils/contracts/BytesLib.sol"; import "./interfaces/IValidators.sol"; import "../common/CalledByVm.sol"; -import "../common/Initializable.sol"; +import "../common/InitializableV2.sol"; import "../common/FixidityLib.sol"; import "../common/linkedlists/AddressLinkedList.sol"; import "../common/UsingRegistry.sol"; @@ -24,7 +24,7 @@ contract Validators is ICeloVersionedContract, Ownable, ReentrancyGuard, - Initializable, + InitializableV2, UsingRegistry, UsingPrecompiles, CalledByVm @@ -207,6 +207,12 @@ contract Validators is setDowntimeGracePeriod(_downtimeGracePeriod); } + /** + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ + constructor(bool test) public InitializableV2(test) {} + /** * @notice Updates the block delay for a ValidatorGroup's commission udpdate * @param delay Number of blocks to delay the update From 4b024be0df6564108a2796af2c454d7dc6f04f39 Mon Sep 17 00:00:00 2001 From: Or Neeman Date: Tue, 8 Jun 2021 14:49:17 -0600 Subject: [PATCH 3/4] Update Validators.sol version (increment patch version) --- packages/protocol/contracts/governance/Validators.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/governance/Validators.sol b/packages/protocol/contracts/governance/Validators.sol index 60bcd7a1c10..e99c4670b54 100644 --- a/packages/protocol/contracts/governance/Validators.sol +++ b/packages/protocol/contracts/governance/Validators.sol @@ -163,7 +163,7 @@ contract Validators is * @return The storage, major, minor, and patch version of the contract. */ function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 2, 0, 0); + return (1, 2, 0, 1); } /** From b9088e247a71dfedca3139c0503693217f1dec39 Mon Sep 17 00:00:00 2001 From: Or Neeman Date: Tue, 8 Jun 2021 16:48:03 -0600 Subject: [PATCH 4/4] Update ValidatorsTest.sol to work now that Validators uses InitializableV2 --- packages/protocol/contracts/governance/test/ValidatorsTest.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/governance/test/ValidatorsTest.sol b/packages/protocol/contracts/governance/test/ValidatorsTest.sol index da51a58b95e..d6169085013 100644 --- a/packages/protocol/contracts/governance/test/ValidatorsTest.sol +++ b/packages/protocol/contracts/governance/test/ValidatorsTest.sol @@ -6,7 +6,7 @@ import "../../common/FixidityLib.sol"; /** * @title A wrapper around Validators that exposes onlyVm functions for testing. */ -contract ValidatorsTest is Validators { +contract ValidatorsTest is Validators(true) { function updateValidatorScoreFromSigner(address signer, uint256 uptime) external { return _updateValidatorScoreFromSigner(signer, uptime); }