disallow delegatee to create and cosign proposals

This commit is contained in:
Hongrui Fang 2022-11-10 18:21:59 +08:00
parent 287054d95e
commit 7c3d66f365

View file

@ -50,6 +50,7 @@ import Agora.Stake (
) )
import Plutarch.Api.V1.Address (PCredential) import Plutarch.Api.V1.Address (PCredential)
import Plutarch.Api.V2 (PMaybeData) import Plutarch.Api.V2 (PMaybeData)
import Plutarch.Extra.Bool (passert)
import Plutarch.Extra.Field (pletAll, pletAllC) import Plutarch.Extra.Field (pletAll, pletAllC)
import "liqwid-plutarch-extra" Plutarch.Extra.List (pisSingleton, ptryDeleteFirstBy, ptryFromSingleton) import "liqwid-plutarch-extra" Plutarch.Extra.List (pisSingleton, ptryDeleteFirstBy, ptryFromSingleton)
import Plutarch.Extra.Maybe (pdjust, pdnothing, pmaybeData) import Plutarch.Extra.Maybe (pdjust, pdnothing, pmaybeData)
@ -159,17 +160,13 @@ pvoteHelper ::
:--> PStakeRedeemerHandler :--> PStakeRedeemerHandler
) )
pvoteHelper = phoistAcyclic $ pvoteHelper = phoistAcyclic $
plam $ \valProposalCtx ctx -> unTermCont $ do plam $ \valProposalCtx ctx ->
pguardC "Owner or delegate signs this transaction" $
pisSignedBy # pconstant True # ctx
-- This puts trust into the Proposal. The Proposal must necessarily check -- This puts trust into the Proposal. The Proposal must necessarily check
-- that this is not abused. -- that this is not abused.
passert
pguardC "Correct outputs" $ "Correct outputs"
ponlyLocksUpdated # (valProposalCtx # ctx) # ctx (ponlyLocksUpdated # (valProposalCtx # ctx) # ctx)
(pconstant ())
pure $ pconstant ()
-- | Add new lock the the existing list of locked. -- | Add new lock the the existing list of locked.
paddNewLock :: paddNewLock ::
@ -199,19 +196,25 @@ ppermitVote = pvoteHelper #$ phoistAcyclic $
pguardC "Only one stake input allowed" $ pguardC "Only one stake input allowed" $
pisSingleton # ctxF.stakeInputDatums pisSingleton # ctxF.stakeInputDatums
pguardC "Owner signs this transaction" $
pisSignedBy # pconstant False # ctx
pure lock pure lock
pure $ pure $
paddNewLock #$ pmatch ctxF.proposalContext $ \case paddNewLock #$ pmatch ctxF.proposalContext $ \case
PSpendProposal pid _ r -> pmatch r $ \case PSpendProposal pid _ r -> pmatch r $ \case
PVote ((pfromData . (pfield @"resultTag" #)) -> voteFor) -> PVote ((pfromData . (pfield @"resultTag" #)) -> voteFor) ->
mkRecordConstr passert
PVoted "Owner or delegatee signs the transaction"
( #votedOn (pisSignedBy # pconstant True # ctx)
.= pdata pid $ mkRecordConstr
.& #votedFor PVoted
.= pdata voteFor ( #votedOn
) .= pdata pid
.& #votedFor
.= pdata voteFor
)
PCosign _ -> PCosign _ ->
withOnlyOneStakeInput withOnlyOneStakeInput
#$ mkRecordConstr #$ mkRecordConstr
@ -269,8 +272,8 @@ premoveLocks = phoistAcyclic $
-} -}
pretractVote :: forall (s :: S). Term s PStakeRedeemerHandler pretractVote :: forall (s :: S). Term s PStakeRedeemerHandler
pretractVote = pvoteHelper #$ phoistAcyclic $ pretractVote = pvoteHelper #$ phoistAcyclic $
plam $ plam $ \ctx ->
flip pmatch $ \ctxF -> pmatch ctx $ \ctxF ->
pmatch ctxF.proposalContext $ \case pmatch ctxF.proposalContext $ \case
PSpendProposal pid s r -> pmatch r $ \case PSpendProposal pid s r -> pmatch r $ \case
PUnlockStake _ -> PUnlockStake _ ->
@ -279,7 +282,11 @@ pretractVote = pvoteHelper #$ phoistAcyclic $
(s #== pconstant Finished) (s #== pconstant Finished)
(pcon PRemoveAllLocks) (pcon PRemoveAllLocks)
(pcon PRemoveVoterLockOnly) (pcon PRemoveVoterLockOnly)
in premoveLocks # pid # mode authorized = pisSignedBy # pconstant True # ctx
in passert
"Authorized by owner or delegatee"
authorized
$ premoveLocks # pid # mode
_ -> ptraceError "Expected unlock" _ -> ptraceError "Expected unlock"
_ -> ptraceError "Expected spending proposal" _ -> ptraceError "Expected spending proposal"