Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable governance to call resetStakes() #1193

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/plugins/governance/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ contract Governance is
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
require(startedInSameEra(proposalId), "new era");
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}

function _cancel(
Expand Down
70 changes: 70 additions & 0 deletions test/Governance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'chai'
import { BigNumber } from 'ethers'
import { ethers } from 'hardhat'
import { IConfig } from '../common/configuration'
import { setStorageAt } from '@nomicfoundation/hardhat-network-helpers'
import {
ProposalState,
ZERO_ADDRESS,
Expand Down Expand Up @@ -1185,5 +1186,74 @@ describeP1(`Governance - P${IMPLEMENTATION}`, () => {
// Check value was not updated
expect(await governor.votingDelay()).to.equal(VOTING_DELAY)
})

it('Should be able to call resetStakes() -- regression test 09/04/2024', async () => {
// Context: https://github.com/code-423n4/2024-07-reserve-findings/issues/36

const era = await stRSRVotes.currentEra()

await setStorageAt(stRSR.address, 263, fp('1e-6')) // MIN_SAFE_STAKE_RATE

const encodedCall = stRSR.interface.encodeFunctionData('resetStakes')

// Propose
const proposeTx = await governor
.connect(addr1)
.propose([stRSR.address], [0], [encodedCall], proposalDescription)

const proposeReceipt = await proposeTx.wait(1)
const proposalId = proposeReceipt.events![0].args!.proposalId

// Check proposal state
expect(await governor.state(proposalId)).to.equal(ProposalState.Pending)

// Advance time to start voting
await advanceBlocks(VOTING_DELAY + 1)

// Check proposal state
expect(await governor.state(proposalId)).to.equal(ProposalState.Active)

let voteWay = 1 // for

// vote
await governor.connect(addr1).castVote(proposalId, voteWay)
await advanceBlocks(1)

// Quorum should be equal to cast votes
const expectedQuorum = stkAmt1.mul(2).mul(QUORUM_PERCENTAGE).div(100)
expect(await governor.quorum((await getLatestBlockTimestamp()) - 1)).to.equal(expectedQuorum)

voteWay = 2 // abstain
await governor.connect(addr2).castVoteWithReason(proposalId, voteWay, 'I abstain')
await advanceBlocks(1)

// Quorum should be equal to sum of abstain + for votes
expect(await governor.quorum((await getLatestBlockTimestamp()) - 1)).to.equal(expectedQuorum)

// Check proposal state
expect(await governor.state(proposalId)).to.equal(ProposalState.Active)

// Advance time till voting is complete
await advanceBlocks(VOTING_PERIOD + 1)

// Finished voting - Check proposal state
expect(await governor.state(proposalId)).to.equal(ProposalState.Succeeded)

// Queue proposal
await governor.connect(addr1).queue([stRSR.address], [0], [encodedCall], proposalDescHash)

// Check proposal state
expect(await governor.state(proposalId)).to.equal(ProposalState.Queued)

// Advance time required by timelock
await advanceTime(MIN_DELAY + 1)
await advanceBlocks(1)

// Execute -- regression test, should not revert
await governor.connect(addr1).execute([stRSR.address], [0], [encodedCall], proposalDescHash)

// Check era changed
expect(await stRSRVotes.currentEra()).to.equal(era.add(1))
})
})
})
Loading