Skip to content

Commit 2d3d606

Browse files
Implementation of Secret types with SecretArguments for endpoints. (IntersectMBO#3908)
* Implementation of Secret types with SecretArguments for endpoints. File plutus-tx/src/PlutusTx/Extensions/Secrets.hs introduces the types for secrets and secret arguments and plutus-use-cases/src/Plutus/Contracts/GameStateMachineWithSecretArguments.hs features an example of how to use them. File plutus-use-cases/src/Plutus/Contracts/SealedBidAuction.hs features a more realistic sealed bid auction example whose specification and tests can be found in plutus-use-cases/test/Spec/SealedBidAuction.hs. * Fix formatting and add INLINE pragmas to key functions * Folded the GameStateMachine example into one example instead of two * Fixed flakyness related to timing in the sealed bid auction example * move the secrets interface from PlutusTx to Plutus.Contract * fix build warning * updated something as a result of running some magic nix incantation * updated tutorial * supress intended deprecation error in tests * Make secret arguments an instance of IsString when the argument type is * Faster packing of integers into byte-strings * fix compiler warnings
1 parent dd6e778 commit 2d3d606

File tree

19 files changed

+758
-18
lines changed

19 files changed

+758
-18
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pkgs/.stack
6666
.psc-ide-port
6767
.dir-locals.el
6868
*.code-workspace
69+
.*.sw*
6970

7071
# Frontend generated files (NPM/Yarn, Spago, generated PS, etc.)
7172
# N.B. officially we use NPM; ignoring Yarn files allows the local use of Yarn for those that want
@@ -112,4 +113,4 @@ node.sock
112113
secrets/*/.gpg-id
113114
ghcid.txt
114115
plutus-pab/test-node/testnet/db
115-
plutus-pab/test-node/alonzo-purple/db
116+
plutus-pab/test-node/alonzo-purple/db

doc/plutus/tutorials/GameModel.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ import qualified Ledger.Typed.Scripts as Scripts
5353
import Plutus.Trace.Emulator as Trace
5454
-- END import Emulator
5555

56+
-- START import Contract.Security
57+
import Plutus.Contract.Secrets
58+
-- END import Contract.Security
59+
60+
5661
-- * QuickCheck model
5762

5863
-- START GameModel
@@ -94,13 +99,13 @@ instance ContractModel GameModel where
9499
perform handle s cmd = case cmd of
95100
Lock w new val -> do
96101
callEndpoint @"lock" (handle $ WalletKey w)
97-
LockArgs{ lockArgsSecret = new
102+
LockArgs{ lockArgsSecret = secretArg new
98103
, lockArgsValue = Ada.lovelaceValueOf val }
99104
delay 2
100105
Guess w old new val -> do
101106
callEndpoint @"guess" (handle $ WalletKey w)
102107
GuessArgs{ guessArgsOldSecret = old
103-
, guessArgsNewSecret = new
108+
, guessArgsNewSecret = secretArg new
104109
, guessArgsValueTakenOut = Ada.lovelaceValueOf val }
105110
delay 1
106111
GiveToken w' -> do
@@ -383,12 +388,12 @@ v1_model = ()
383388
perform handle s cmd = case cmd of
384389
Lock w new val -> do
385390
callEndpoint @"lock" (handle $ WalletKey w)
386-
LockArgs{ lockArgsSecret = new
391+
LockArgs{ lockArgsSecret = secretArg new
387392
, lockArgsValue = Ada.lovelaceValueOf val}
388393
Guess w old new val -> do
389394
callEndpoint @"guess" (handle $ WalletKey w)
390395
GuessArgs{ guessArgsOldSecret = old
391-
, guessArgsNewSecret = new
396+
, guessArgsNewSecret = secretArg new
392397
, guessArgsValueTakenOut = Ada.lovelaceValueOf val}
393398
GiveToken w' -> do
394399
let w = fromJust (s ^. contractState . hasToken)

nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-contract.nix

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-use-cases.nix

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-contract.nix

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-use-cases.nix

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-contract.nix

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-use-cases.nix

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground-common/src/Schema.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import Ledger (Ada, AssetClass, Curr
6262
POSIXTime, POSIXTimeRange, PubKey, PubKeyHash, RedeemerHash,
6363
Signature, TokenName, TxId, TxOutRef, ValidatorHash, Value)
6464
import Ledger.Bytes (LedgerBytes)
65+
import Plutus.Contract.Secrets (SecretArgument (EndpointSide, UserSide))
6566
import Plutus.Contract.StateMachine.ThreadToken (ThreadToken)
6667
import qualified PlutusTx.AssocMap
6768
import qualified PlutusTx.Prelude as P
@@ -423,3 +424,10 @@ deriving anyclass instance ToArgument WalletNumber
423424

424425
instance ToArgument WalletId where
425426
toArgument = Fix . FormStringF . Just . show
427+
428+
instance forall a. ToSchema a => ToSchema (SecretArgument a) where
429+
toSchema = toSchema @a
430+
431+
instance forall a. ToArgument a => ToArgument (SecretArgument a) where
432+
toArgument (UserSide a) = toArgument a
433+
toArgument (EndpointSide _) = Fix $ FormUnsupportedF "endpoint side secrets are not supported in toArgument"

plutus-contract/plutus-contract.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ library
6060
Plutus.Contract.Util
6161
Plutus.Contract.Wallet
6262
Plutus.Contract.Typed.Tx
63+
Plutus.Contract.Secrets
6364
Wallet.Emulator
6465
Wallet.Emulator.Types
6566
Wallet.Emulator.Chain
@@ -174,6 +175,7 @@ test-suite plutus-contract-test
174175
Spec.Rows
175176
Spec.State
176177
Spec.ThreadToken
178+
Spec.Secrets
177179
build-depends:
178180
base >=4.9 && <5,
179181
bytestring -any,
@@ -184,6 +186,7 @@ test-suite plutus-contract-test
184186
tasty -any,
185187
tasty-golden -any,
186188
tasty-hunit -any,
189+
tasty-quickcheck -any,
187190
tasty-hedgehog -any,
188191
text -any,
189192
mtl -any,

0 commit comments

Comments
 (0)