Skip to content

Commit

Permalink
Prevent submitting roots on a proposal in voting
Browse files Browse the repository at this point in the history
  • Loading branch information
kanewallmann committed Apr 10, 2024
1 parent 70a360a commit 04f0488
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
9 changes: 7 additions & 2 deletions contracts/contract/dao/protocol/RocketDAOProtocolVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,13 @@ contract RocketDAOProtocolVerifier is RocketBase, RocketDAOProtocolVerifierInter
/// @param _index The global index of the node for which the proposer is submitting a new pollard
/// @param _nodes A list of nodes making up the new pollard
function submitRoot(uint256 _proposalID, uint256 _index, Types.Node[] calldata _nodes) external onlyLatestContract("rocketDAOProtocolVerifier", address(this)) onlyRegisteredNode(msg.sender) {
{
{ // Scope to prevent stack too deep
// Check whether the proposal is in the Pending state
RocketDAOProtocolProposalInterface daoProposal = RocketDAOProtocolProposalInterface(getContractAddress("rocketDAOProtocolProposal"));
RocketDAOProtocolProposalInterface.ProposalState proposalState = daoProposal.getState(_proposalID);
require(proposalState == RocketDAOProtocolProposalInterface.ProposalState.Pending, "Can not submit root for a valid proposal");
}
{ // Scope to prevent stack too deep
// Get challenge state
bytes32 challengeKey = keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _index));
uint256 state = getUint(challengeKey);
Expand All @@ -408,7 +414,6 @@ contract RocketDAOProtocolVerifier is RocketBase, RocketDAOProtocolVerifierInter
state = setChallengeState(state, Types.ChallengeState.Responded);
setUint(challengeKey, state);
}

// Load the proposal
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));

Expand Down
31 changes: 31 additions & 0 deletions test/dao/dao-protocol-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,37 @@ export default function() {
}
});

it(printTitle('proposer', 'can not respond to a challenge after proposal enters voting'), async () => {
// Setup
await setDAOProtocolBootstrapEnableGovernance();
await mockNodeSet();
await createNode(1, proposer);

// Create a minipool with a node to use as a challenger
let challenger = node1;
await createNode(1, challenger);

// Create a valid proposal
const { propId, leaves, block } = await createValidProposal();

// Challenge/response
const phase1Depth = getMaxDepth(leaves.length);
const maxDepth = phase1Depth * 2;
const { phase1Indices, subRootIndex, phase2Indices } = getChallengeIndices(2 ** maxDepth, leaves.length);

// Challenge
let index = phase1Indices[0]
const challenge = daoProtocolGenerateChallengeProof(leaves, depthPerRound, index);
await daoProtocolCreateChallenge(propId, index, challenge.node, challenge.proof, { from: challenger });

// Let proposal enter voting
await increaseTime(hre.web3, voteDelayTime + 1);

// Response
let pollard = await daoProtocolGeneratePollard(leaves, depthPerRound, index);
await shouldRevert(daoProtocolSubmitRoot(propId, index, pollard, { from: proposer }), 'Was able to submit root', 'Can not submit root for a valid proposal');
});

it(printTitle('proposer', 'can successfully claim proposal bond'), async () => {
// Setup
await setDAOProtocolBootstrapEnableGovernance();
Expand Down

0 comments on commit 04f0488

Please sign in to comment.