only allow script inputs from the effect and governor

This commit is contained in:
fanghr 2022-05-10 17:22:15 +08:00
parent df8fc484c9
commit 2e21e4c94a
No known key found for this signature in database
GPG key ID: 35CD9A71CD5D5870
2 changed files with 21 additions and 2 deletions

View file

@ -62,6 +62,7 @@ import Agora.Governor.Scripts (
governorSTAssetClassFromGovernor,
)
import Agora.Utils (
isScriptAddress,
mustBePDJust,
mustBePJust,
passert,
@ -148,8 +149,19 @@ mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov)
passert "Nothing should be minted/burnt other than GAT" $
plength # mint #== 1
passert "Only self and governor inputs are allowed" $
plength # pfromData txInfo.inputs #== 2
passert "Only self and governor script inputs are allowed" $
pfoldr
# phoistAcyclic
( plam $ \inInfo count ->
let address = pfield @"address" #$ pfield @"resolved" # inInfo
in pif
(isScriptAddress # address)
(count + 1)
count
)
# (0 :: Term _ PInteger)
# pfromData txInfo.inputs
#== 2
let inputWithGST =
mustBePJust # "Governor input not found" #$ pfind

View file

@ -59,6 +59,7 @@ module Agora.Utils (
validatorHashToAddress,
pmergeBy,
phalve,
isScriptAddress
) where
--------------------------------------------------------------------------------
@ -619,6 +620,12 @@ scriptHashFromAddress = phoistAcyclic $
PScriptCredential ((pfield @"_0" #) -> h) -> pcon $ PJust h
_ -> pcon PNothing
isScriptAddress :: Term s (PAddress :--> PBool)
isScriptAddress = phoistAcyclic $ plam $ \addr ->
pmatch (pfromData $ pfield @"credential" # addr) $ \case
PScriptCredential _ -> pconstant True
_ -> pconstant False
-- | Find all TxOuts sent to an Address
findOutputsToAddress :: Term s (PBuiltinList (PAsData PTxOut) :--> PAddress :--> PBuiltinList (PAsData PTxOut))
findOutputsToAddress = phoistAcyclic $