From e5e896d9783b9f0f90610fb59a4de8d9dce3d2b8 Mon Sep 17 00:00:00 2001 From: Hongrui Fang Date: Mon, 31 Oct 2022 22:33:55 +0800 Subject: [PATCH] regression tests for proposal fast-forward attack --- agora-specs/Sample/Proposal/Advance.hs | 34 +++++++++++++++++++++++++- agora-specs/Spec/Proposal.hs | 10 ++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/agora-specs/Sample/Proposal/Advance.hs b/agora-specs/Sample/Proposal/Advance.hs index 01aa7f1..c06fd38 100644 --- a/agora-specs/Sample/Proposal/Advance.hs +++ b/agora-specs/Sample/Proposal/Advance.hs @@ -35,6 +35,7 @@ module Sample.Proposal.Advance ( mkMintGATsWithoutTagBundle, mkBadGovernorOutputDatumBundle, mkUnexpectedOutputStakeBundles, + mkFastforwardToFinishBundles, ) where import Agora.Governor ( @@ -278,7 +279,7 @@ mkVotes ps = -- | The starting time of every generated proposal. proposalStartingTime :: POSIXTime -proposalStartingTime = 0 +proposalStartingTime = 100 -- | Create the input proposal datum given the parameters. mkProposalInputDatum :: ProposalParameters -> ProposalDatum @@ -1066,3 +1067,34 @@ mkBadGovernorOutputDatumBundle nCosigners nEffects = where template = mkValidFromLockedBundle nCosigners nEffects gov = GovernorParameters True + +mkFastforwardToFinishBundles :: + Word -> + Word -> + [ParameterBundle] +mkFastforwardToFinishBundles nCosigners nEffects = updateTemplate <$> templates + where + templates = mkValidToFailedStateBundles nCosigners nEffects + mkMaliciousTimRange = + let lb = proposalStartingTime - 1 + dub = + 1 + + proposalStartingTime + + (def :: ProposalTimingConfig).draftTime + vub = + dub + + (def :: ProposalTimingConfig).votingTime + + (def :: ProposalTimingConfig).lockingTime + lub = + vub + + (def :: ProposalTimingConfig).executingTime + go Draft = (lb, dub) + go VotingReady = (lb, vub) + go Locked = (lb, lub) + go Finished = error "cannot advance from Finished" + in uncurry closedBoundedInterval . go + updateTemplate template = + template + { transactionTimeRange = + mkMaliciousTimRange template.proposalParameters.fromStatus + } diff --git a/agora-specs/Spec/Proposal.hs b/agora-specs/Spec/Proposal.hs index dd82c4f..2d12fc6 100644 --- a/agora-specs/Spec/Proposal.hs +++ b/agora-specs/Spec/Proposal.hs @@ -327,6 +327,16 @@ specs = , forGovernorValidator = Just False , forAuthorityTokenPolicy = Just True } + , Advance.mkTestTree' + "fastforward to finished" + (\b -> unwords ["from", show b.proposalParameters.fromStatus]) + (Advance.mkFastforwardToFinishBundles cs es) + Advance.Validity + { forProposalValidator = False + , forStakeValidator = True + , forGovernorValidator = Just False + , forAuthorityTokenPolicy = Just True + } ] ] , group "unlocking" $