Skip to content

Commit

Permalink
Audit fix (#3)
Browse files Browse the repository at this point in the history
* audit fix

* Update address

* verison

* Update address
  • Loading branch information
hujw77 authored Aug 16, 2024
1 parent 92078e4 commit ccbc17c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 58 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

## Koi
```
Delegation Wall: 0xA1f68f22830fF74D617d9021C0fFf1cB4dcE3855
TokenVoting Plugin Setup: 0x0860B316305D7f3F0460057d4608447B1d47FB3c
TokenVoting Plugin Repo: 0x81cC3d1915af283491F2B34160893d773C03eb5a
Ring DAO: 0xAA3B8e182b6E9Ee46F5A68e31171EC6444F76DCF
Delegation Wall: 0xc254EE0075aF3317b261F541Eea000261c68CEE0
TokenVoting Plugin Setup: 0x096512bb0B02E7177e1e6CDa2c272E7773F3d812
TokenVoting Plugin Repo: 0xbF45529032c2E21e93f4CA5b023372A0CB6088b2
Ring DAO: 0x422c45B07D7c50Bd57697D464F6763fa510e5f2B
Installed Plugins:
- 0x0394Fdc83232B85c03F7d2c4184619768c92bbC1
- 0x2112ad23aBb169942418E87c95A1B3126Db4EA45
```

## Token Voting plugin
Expand Down
2 changes: 1 addition & 1 deletion lib/osx
Submodule osx updated from 70bc25 to 537872
15 changes: 13 additions & 2 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,19 @@ contract Deploy is Script {
}
}

function getMinVotingPower() public view returns (uint256) {
if (block.chainid == 701) {
return 400e18;
} else if (block.chainid == 44) {
revert("TODO");
} else if (block.chainid == 46) {
return 40000000e18;
}
}

function deployPluginSetup() public {
tokenVotingPluginSetup = new TokenVotingPluginSetup();
uint256 minVotingPower = getMinVotingPower();
tokenVotingPluginSetup = new TokenVotingPluginSetup(minVotingPower);
}

function deployPluginRepo() public {
Expand Down Expand Up @@ -111,7 +122,7 @@ contract Deploy is Script {
minDuration: 60 minutes,
minProposerVotingPower: 1e18
}),
TokenVotingPluginSetup.TokenSettings({addr: gRING, underlyingTotalSupply: 1_000_000_000e18})
TokenVotingPluginSetup.TokenSettings({addr: gRING})
);
PluginRepo.Tag memory tag = PluginRepo.Tag(1, 1);
return DAOFactory.PluginSettings(PluginSetupRef(tag, tokenVotingPluginRepo), pluginSettingsData);
Expand Down
54 changes: 18 additions & 36 deletions src/plugins/token-voting/TokenVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,33 @@ contract TokenVoting is IMembership, IERC6372Upgradeable, MajorityVotingBase {
/// @notice The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract.
bytes4 internal constant TOKEN_VOTING_INTERFACE_ID = this.initialize.selector ^ this.getVotingToken.selector;

/// @notice The minimum voting power needed.
uint256 public immutable MIN_VOTING_POWER;

/// @notice An [OpenZeppelin `Votes`](https://docs.openzeppelin.com/contracts/4.x/api/governance#Votes) compatible contract referencing the token being used for voting.
IERC5805Upgradeable private votingToken;

/// @notice Total supply of underlying token in voting token.
uint256 public underlyingTotalSupply;

/// @notice Thrown if the voting power is zero
error NoVotingPower();

/// @notice The implementation constructor.
constructor(uint256 minVotingPower) {
MIN_VOTING_POWER = minVotingPower;
}

/// @notice Initializes the component.
/// @dev This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822).
/// @param _dao The IDAO interface of the associated DAO.
/// @param _votingSettings The voting settings.
/// @param _token The [ERC-20](https://eips.ethereum.org/EIPS/eip-20) token used for voting.
/// @param _underlyingTotalSupply The Total supply of underlying token in the voting token..
function initialize(
IDAO _dao,
VotingSettings calldata _votingSettings,
IVotesUpgradeable _token,
uint256 _underlyingTotalSupply
) external initializer {
function initialize(IDAO _dao, VotingSettings calldata _votingSettings, IVotesUpgradeable _token)
external
initializer
{
__MajorityVotingBase_init(_dao, _votingSettings);

votingToken = IERC5805Upgradeable(address(_token));

underlyingTotalSupply = _underlyingTotalSupply;

emit MembershipContractAnnounced({definingContract: address(_token)});
}

Expand All @@ -73,8 +73,8 @@ contract TokenVoting is IMembership, IERC6372Upgradeable, MajorityVotingBase {
}

/// @inheritdoc MajorityVotingBase
function totalVotingPower(uint256) public view override returns (uint256) {
return underlyingTotalSupply;
function totalVotingPower(uint256 _timepoint) public view override returns (uint256) {
return votingToken.getPastTotalSupply(_timepoint);
}

/// @dev Clock (as specified in EIP-6372) is set to match the token's clock. Fallback to block numbers if the token
Expand All @@ -97,16 +97,6 @@ contract TokenVoting is IMembership, IERC6372Upgradeable, MajorityVotingBase {
}
}

/// @notice Updates the total supply of underlying token in voting token.
/// @param _underlyingTotalSupply The new total supply of underlying token in voting token.
function updateUnderlyingTotalSupply(uint256 _underlyingTotalSupply)
external
virtual
auth(UPDATE_VOTING_SETTINGS_PERMISSION_ID)
{
underlyingTotalSupply = _underlyingTotalSupply;
}

/// @inheritdoc MajorityVotingBase
function createProposal(
bytes calldata _metadata,
Expand Down Expand Up @@ -160,7 +150,7 @@ contract TokenVoting is IMembership, IERC6372Upgradeable, MajorityVotingBase {
proposal_.parameters.snapshotTimepoint = snapshotTimepoint;
proposal_.parameters.votingMode = votingMode();
proposal_.parameters.supportThreshold = supportThreshold();
proposal_.parameters.minVotingPower = _applyRatioCeiled(totalVotingPower_, minParticipation());
proposal_.parameters.minVotingPower = MIN_VOTING_POWER;

// Reduce costs
if (_allowFailureMap != 0) {
Expand Down Expand Up @@ -259,20 +249,12 @@ contract TokenVoting is IMembership, IERC6372Upgradeable, MajorityVotingBase {
}

/// @inheritdoc MajorityVotingBase
function isSupportThresholdReachedEarly(uint256 _proposalId) public view virtual override returns (bool) {
Proposal storage proposal_ = proposals[_proposalId];

uint256 noVotesWorstCase =
totalVotingPower(proposal_.parameters.snapshotTimepoint) - proposal_.tally.yes - proposal_.tally.abstain;

// The code below implements the formula of the early execution support criterion explained in the top of this file.
// `(1 - supportThreshold) * N_yes > supportThreshold * N_no,worst-case`
return (RATIO_BASE - proposal_.parameters.supportThreshold) * proposal_.tally.yes
> proposal_.parameters.supportThreshold * noVotesWorstCase;
function isSupportThresholdReachedEarly(uint256) public view virtual override returns (bool) {
return false;
}

/// @dev This empty reserved space is put in place to allow future versions to add new
/// variables without shifting down storage in the inheritance chain.
/// https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
uint256[48] private __gap;
uint256[49] private __gap;
}
11 changes: 3 additions & 8 deletions src/plugins/token-voting/TokenVotingPluginSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ contract TokenVotingPluginSetup is PluginSetup {

/// @notice The token settings struct.
/// @param addr The voting token contract address.
/// @param underlyingTotalSupply Total supply of underlying token in voting token.
struct TokenSettings {
address addr;
uint256 underlyingTotalSupply;
}

/// @notice Thrown if token address is passed which is not a token.
Expand All @@ -55,8 +53,8 @@ contract TokenVotingPluginSetup is PluginSetup {
error WrongHelpersArrayLength(uint256 length);

/// @notice The contract constructor deploying the plugin implementation contract.
constructor() {
tokenVotingBase = new TokenVoting();
constructor(uint256 minVotingPower) {
tokenVotingBase = new TokenVoting(minVotingPower);
}

/// @inheritdoc IPluginSetup
Expand Down Expand Up @@ -93,10 +91,7 @@ contract TokenVotingPluginSetup is PluginSetup {
// Prepare and deploy plugin proxy.
plugin = createERC1967Proxy(
address(tokenVotingBase),
abi.encodeCall(
TokenVoting.initialize,
(IDAO(_dao), votingSettings, IVotesUpgradeable(token), tokenSettings.underlyingTotalSupply)
)
abi.encodeCall(TokenVoting.initialize, (IDAO(_dao), votingSettings, IVotesUpgradeable(token)))
);

// Prepare permissions
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/token-voting/build-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@
"name": "token",
"type": "address",
"description": "The voting token contract address."
},
{
"internalType": "uint256",
"name": "underlyingTotalSupply",
"type": "uint256",
"description": "Total supply of underlying token in voting token."
}
],
"internalType": "struct TokenVotingPluginSetup.TokenSettings",
Expand Down

0 comments on commit ccbc17c

Please sign in to comment.