improve performance of the governor validator

This commit is contained in:
Hongrui Fang 2022-07-13 19:01:51 +08:00
parent a19bbce198
commit b6fb23975c
No known key found for this signature in database
GPG key ID: 1E0454204FC7D755
13 changed files with 166 additions and 319 deletions

View file

@ -62,8 +62,6 @@ data GovernorDatumCases
= ExecuteLE0
| CreateLE0
| VoteLE0
| CreateLEVote
| ExecuteLVote
| Correct
deriving stock (Eq, Show)
@ -72,8 +70,6 @@ instance Universe GovernorDatumCases where
[ ExecuteLE0
, CreateLE0
, VoteLE0
, CreateLEVote
, ExecuteLVote
, Correct
]
@ -94,8 +90,6 @@ governorDatumValidProperty =
| e < 0 = ExecuteLE0
| c < 0 = CreateLE0
| v < 0 = VoteLE0
| c > v = CreateLEVote
| v >= e = ExecuteLVote
| otherwise = Correct
expected :: GovernorDatum -> Maybe Bool
@ -127,16 +121,6 @@ governorDatumValidProperty =
VoteLE0 ->
-- vote < 0
return $ ProposalThresholds execute create le0
CreateLEVote -> do
-- c > vote
nv <- taggedInteger (0, untag create - 1)
ne <- taggedInteger (untag nv + 1, 1000000000)
return $ ProposalThresholds ne create nv
ExecuteLVote -> do
-- vote >= execute
ne <- taggedInteger (0, untag vote)
nc <- taggedInteger (0, untag vote)
return $ ProposalThresholds ne nc vote
Correct -> do
-- c <= vote < execute
nv <- taggedInteger (0, untag execute - 1)

View file

@ -11,19 +11,18 @@ module Spec.AuthorityToken (specs) where
import Agora.AuthorityToken (singleAuthorityTokenBurned)
import Plutarch (ClosedTerm, POpaque, compile, perror, popaque)
import Plutarch.Unsafe (punsafeCoerce)
import PlutusLedgerApi.V1 (
Address (Address),
Credential (PubKeyCredential, ScriptCredential),
CurrencySymbol,
Script,
TxInInfo (TxInInfo),
TxInfo (..),
TxOut (TxOut),
TxOutRef (TxOutRef),
ValidatorHash (ValidatorHash),
Value,
)
import PlutusLedgerApi.V1.Interval qualified as Interval (always)
import PlutusLedgerApi.V1.Value qualified as Value (
Value (Value),
singleton,
@ -36,37 +35,25 @@ import Test.Specification (
scriptSucceeds,
)
import Prelude (
Functor (fmap),
Maybe (Nothing),
PBool,
Semigroup ((<>)),
fmap,
pconstant,
pconstantData,
pif,
($),
)
currencySymbol :: CurrencySymbol
currencySymbol = "deadbeef"
mkTxInfo :: Value -> [TxOut] -> TxInfo
mkTxInfo mint outs =
TxInfo
{ txInfoInputs = fmap (TxInInfo (TxOutRef "" 0)) outs
, txInfoOutputs = []
, txInfoFee = Value.singleton "" "" 1000
, txInfoMint = mint
, txInfoDCert = []
, txInfoWdrl = []
, txInfoValidRange = Interval.always
, txInfoSignatories = []
, txInfoData = []
, txInfoId = ""
}
mkInputs :: [TxOut] -> [TxInInfo]
mkInputs = fmap (TxInInfo (TxOutRef "" 0))
singleAuthorityTokenBurnedTest :: Value -> [TxOut] -> Script
singleAuthorityTokenBurnedTest mint outs =
let actual :: ClosedTerm PBool
actual = singleAuthorityTokenBurned (pconstant currencySymbol) (pconstantData (mkTxInfo mint outs)) (pconstant mint)
actual = singleAuthorityTokenBurned (pconstant currencySymbol) (punsafeCoerce $ pconstant $ mkInputs outs) (pconstant mint)
s :: ClosedTerm POpaque
s =
pif

View file

@ -40,7 +40,7 @@ specs =
"use other's stake"
Create.useStakeOwnBySomeoneElseParameters
True
False
True
False
, Create.mkTestTree
"altered stake"