From 5783699bf7e90c8f6e4ac175b858031a42252d64 Mon Sep 17 00:00:00 2001 From: Aleksandr Kuperman Date: Mon, 13 May 2024 16:10:26 +0100 Subject: [PATCH 1/3] chore: small corrections --- .solcover.js | 9 ++++++--- test/VoteWeighting.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.solcover.js b/.solcover.js index 4e7bed3..8e55a91 100644 --- a/.solcover.js +++ b/.solcover.js @@ -9,10 +9,13 @@ module.exports = { "bridges/test/WormholeL1Receiver.sol", "bridges/test/WormholeL1Sender.sol", "bridges/test/WormholeL2ReceiverL1Sender.sol", + "multisigs/test/DelegatecallExploit.sol", + "multisigs/test/MockTimelockCM.sol", + "multisigs/test/MockTreasury.sol", "test/BridgeSetup.sol", "test/BrokenERC20.sol", + "test/EchidnaVoteWeightingAssert.sol", "test/SafeSetup.sol", - "multisigs/test/MockTimelockCM.sol", - "multisigs/test/MockTreasury.sol", + "test/VoteWeightingFuzzing.sol" ] -}; +}; \ No newline at end of file diff --git a/test/VoteWeighting.js b/test/VoteWeighting.js index 0657487..39576ae 100644 --- a/test/VoteWeighting.js +++ b/test/VoteWeighting.js @@ -4,7 +4,7 @@ const { expect } = require("chai"); const { ethers } = require("hardhat"); const helpers = require("@nomicfoundation/hardhat-network-helpers"); -describe("Voting Escrow OLAS", function () { +describe("Vot Weighting OLAS", function () { let olas; let ve; let vw; From 6b2925e55a9f767fe6ee4bd7cbf23179025d732e Mon Sep 17 00:00:00 2001 From: Aleksandr Kuperman Date: Mon, 13 May 2024 16:11:24 +0100 Subject: [PATCH 2/3] chore: comment --- test/VoteWeighting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/VoteWeighting.js b/test/VoteWeighting.js index 39576ae..dbb4439 100644 --- a/test/VoteWeighting.js +++ b/test/VoteWeighting.js @@ -4,7 +4,7 @@ const { expect } = require("chai"); const { ethers } = require("hardhat"); const helpers = require("@nomicfoundation/hardhat-network-helpers"); -describe("Vot Weighting OLAS", function () { +describe("Vote Weighting veOLAS", function () { let olas; let ve; let vw; From 122adc5817a5c94fa24512e0e5f7beaed1abf8ae Mon Sep 17 00:00:00 2001 From: Aleksandr Kuperman Date: Fri, 17 May 2024 14:27:04 +0100 Subject: [PATCH 3/3] chore: comments --- contracts/VoteWeighting.sol | 53 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/contracts/VoteWeighting.sol b/contracts/VoteWeighting.sol index b5ea92d..3273c93 100644 --- a/contracts/VoteWeighting.sol +++ b/contracts/VoteWeighting.sol @@ -190,7 +190,8 @@ contract VoteWeighting { owner = msg.sender; ve = _ve; timeSum = block.timestamp / WEEK * WEEK; - setNominees.push(Nominee(bytes32(0), 0)); + // Push empty element to the zero-th index + setNominees.push(Nominee(0, 0)); } /// @dev Fill sum of nominee weights for the same type week-over-week for missed checkins and return the sum for the future week. @@ -367,12 +368,12 @@ contract VoteWeighting { dispenser = newDispenser; } - /// @dev Checkpoint to fill data common for all nominees. + /// @dev Checkpoints to fill data common for all nominees. function checkpoint() external { _getSum(); } - /// @dev Checkpoint to fill data for both a specific nominee and common for all nominees. + /// @dev Checkpoints to fill data for both a specific nominee and common for all nominees. /// @param account Address of the nominee. /// @param chainId Chain Id. function checkpointNominee(bytes32 account, uint256 chainId) external { @@ -380,11 +381,10 @@ contract VoteWeighting { _getSum(); } - /// @dev Get Nominee relative weight (not more than 1.0) normalized to 1e18 (e.g. 1.0 == 1e18) and a sum of weights. - /// Inflation which will be received by it is inflation_rate * relativeWeight / 1e18. + /// @dev Gets Nominee relative weight (not more than 1.0) normalized to 1e18 (e.g. 1.0 == 1e18) and a sum of weights. /// @param account Address of the nominee in byte32 standard. /// @param chainId Chain Id. - /// @param time Relative weight at the specified timestamp in the past or present. + /// @param time Timestamp in the past or present. /// @return weight Value of relative weight normalized to 1e18. /// @return totalSum Sum of nominee weights. function _nomineeRelativeWeight( @@ -404,12 +404,10 @@ contract VoteWeighting { } } - /// @dev Get Nominee relative weight (not more than 1.0) normalized to 1e18 and the sum of weights. - /// (e.g. 1.0 == 1e18). Inflation which will be received by it is - /// inflation_rate * relativeWeight / 1e18. + /// @dev Gets Nominee relative weight (not more than 1.0) normalized to 1e18 (e.g. 1.0 == 1e18) and a sum of weights. /// @param account Address of the nominee in bytes32 form. /// @param chainId Chain Id. - /// @param time Relative weight at the specified timestamp in the past or present. + /// @param time Timestamp in the past or present. /// @return weight Value of relative weight normalized to 1e18. /// @return totalSum Sum of nominee weights. function nomineeRelativeWeight( @@ -420,12 +418,11 @@ contract VoteWeighting { (weight, totalSum) = _nomineeRelativeWeight(account, chainId, time); } - /// @dev Get nominee weight normalized to 1e18 and also fill all the unfilled values for type and nominee records. - /// Also, get the total sum of all the nominee weights. - /// @notice Any address can call, however nothing is recorded if the values are filled already. + /// @dev Gets nominee weight normalized to 1e18 and also gets the total sum of all the nominee weights. + /// @notice Nothing is recorded if the values are already filled. /// @param account Address of the nominee in bytes32 form. /// @param chainId Chain Id. - /// @param time Relative weight at the specified timestamp in the past or present. + /// @param time Timestamp in the past or present. /// @return weight Value of relative weight normalized to 1e18. /// @return totalSum Sum of nominee weights. function nomineeRelativeWeightWrite( @@ -438,7 +435,7 @@ contract VoteWeighting { (weight, totalSum) = _nomineeRelativeWeight(account, chainId, time); } - /// @dev Allocate voting power for changing pool weights. + /// @dev Allocates voting power for changing pool weights. /// @param account Address of the nominee the `msg.sender` votes for in bytes32 form. /// @param chainId Chain Id. /// @param weight Weight for a nominee in bps (units of 0.01%). Minimal is 0.01%. Ignored if 0. @@ -523,7 +520,7 @@ contract VoteWeighting { emit VoteForNominee(msg.sender, account, chainId, weight); } - /// @dev Allocate voting power for changing pool weights in batch. + /// @dev Allocates voting power for changing pool weights in a batch set. /// @param accounts Set of nominee addresses in bytes32 form the `msg.sender` votes for. /// @param chainIds Set of corresponding chain Ids. /// @param weights Weights for a nominees in bps (units of 0.01%). Minimal is 0.01%. Ignored if 0. @@ -658,28 +655,28 @@ contract VoteWeighting { /// @dev Gets a full set of nominees. /// @notice The returned set includes the zero-th empty nominee instance. - /// @return nominees Set of all the nominees in the contract. - function getAllNominees() external view returns (Nominee[] memory nominees) { - nominees = setNominees; + /// @return Set of all the nominees in the contract. + function getAllNominees() external view returns (Nominee[] memory) { + return setNominees; } /// @dev Gets the nominee Id in the global nominees set. /// @param account Nominee address in bytes32 form. /// @param chainId Chain Id. - /// @return id Nominee Id in the global set of Nominee struct values. - function getNomineeId(bytes32 account, uint256 chainId) external view returns (uint256 id) { + /// @return Nominee Id in the global set of Nominee struct values. + function getNomineeId(bytes32 account, uint256 chainId) external view returns (uint256) { // Get the nominee struct and hash Nominee memory nominee = Nominee(account, chainId); bytes32 nomineeHash = keccak256(abi.encode(nominee)); - id = mapNomineeIds[nomineeHash]; + return mapNomineeIds[nomineeHash]; } /// @dev Get the nominee address and its corresponding chain Id. /// @notice The zero-th default nominee Id with id == 0 does not count. /// @param id Nominee Id in the global set of Nominee struct values. - /// @return nominee Nominee address in bytes32 form and chain Id. - function getNominee(uint256 id) external view returns (Nominee memory nominee) { + /// @return Nominee address in bytes32 form and chain Id. + function getNominee(uint256 id) external view returns (Nominee memory) { // Get the total number of nominees in the contract uint256 totalNumNominees = setNominees.length - 1; // Check for the zero id or the overflow @@ -689,7 +686,7 @@ contract VoteWeighting { revert Overflow(id, totalNumNominees); } - nominee = setNominees[id]; + return setNominees[id]; } /// @dev Get the set of nominee addresses and corresponding chain Ids. @@ -697,11 +694,7 @@ contract VoteWeighting { /// @param startId Start Id of the nominee in the global set of Nominee struct values. /// @param numNominees Number of nominees to get. /// @return nominees Set of nominee accounts in bytes32 form and chain Ids. - function getNominees( - uint256 startId, - uint256 numNominees - ) external view returns (Nominee[] memory nominees) - { + function getNominees(uint256 startId, uint256 numNominees) external view returns (Nominee[] memory nominees) { // Check for the zero id or the overflow if (startId == 0 || numNominees == 0) { revert ZeroValue();