Skip to content

Commit 7c796ac

Browse files
authored
Merge pull request #133 from zkFold/124-extra-addresses
Support for extra addresses in smart wallet
2 parents f622a23 + 7d67d73 commit 7c796ac

File tree

6 files changed

+138
-7
lines changed

6 files changed

+138
-7
lines changed

.github/workflows/main-pull.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
132132
- name: Lint Haskell
133133
run: |
134-
find . -name '*.hs' -exec sh -c 'for file do stylish-haskell --inplace "$file"; done' sh {} +
134+
find zkfold* -name '*.hs' -exec sh -c 'for file do stylish-haskell --inplace "$file"; done' sh {} +
135135
136136
- name: Auto-commit lint
137137
uses: stefanzweifel/git-auto-commit-action@v4
@@ -160,6 +160,17 @@ jobs:
160160
run: |
161161
cabal build all -f Pedantic
162162
163+
- name: Check compiled scripts
164+
run: |
165+
cabal run zkfold-cardano-scripts-compiler
166+
diff=$(git diff | wc -l)
167+
if [ "$diff" -gt "0" ]; then
168+
echo "Compiled scripts in the commit do not correspond to the code in zkfold-cardano-scripts. Did you forget to run cabal run zkfold-cardano-scripts-compiler?"
169+
exit 1
170+
fi
171+
172+
173+
163174
# - name: Test
164175
# run: cabal test all
165176

@@ -170,4 +181,4 @@ jobs:
170181
# run: cabal haddock all
171182

172183
# - name: Prepare package for publishing
173-
# run: cabal sdist all
184+
# run: cabal sdist all

zkfold-cardano-scripts-common/data/compiled-scripts/rollup-simple.blueprint

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

zkfold-cardano-scripts-common/data/compiled-scripts/smart-wallet.blueprint

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
}
5555
},
5656
"parameters": [
57+
{
58+
"title": "CurrencySymbol",
59+
"purpose": "spend",
60+
"schema": {
61+
"$ref": "#/definitions/CurrencySymbol"
62+
}
63+
},
5764
{
5865
"title": "ScriptHash",
5966
"purpose": "spend",
@@ -65,6 +72,49 @@
6572
"compiledCode": "59011b0101003232232322232323255333573466e1d200000111300633300700a00a357426ae88d5d11aba235744004226012aa666ae68cdc3a4004002226464664600200244b200318014886400a44aa666ae68cdd780100388c00044cc01801800c0023374a900119aba037526eb80192f5c066600e0140146ae84d5d11aba2357446ae88d5d11aba2002118011bad357426ae88008d55cf1baa357420026aae78dd5000991800800912c800c4c0160052219002912a999ab9a3375e0040102260130001133006006003088c88d4008dd5800999180080091092999aab9f001180009991400e002600e6aae7400a600c6aae780093533005005120010011aba100135744002240024b2003149a264c66ae712401035054350080008005",
6673
"hash": "40c54280c732450bbf835d17687d05aaa7f332720f9d91eeed152fc8"
6774
},
75+
{
76+
"title": "wallet'",
77+
"description": "Smart wallet spending validator",
78+
"redeemer": {
79+
"title": "Unit",
80+
"purpose": "spend",
81+
"schema": {
82+
"$ref": "#/definitions/Unit"
83+
}
84+
},
85+
"datum": {
86+
"purpose": "spend",
87+
"schema": {
88+
"$ref": "#/definitions/BuiltinData"
89+
}
90+
},
91+
"parameters": [
92+
{
93+
"title": "Script index",
94+
"description": "Dummy parameter to generate extra addresses for the same wallet",
95+
"purpose": "spend",
96+
"schema": {
97+
"$ref": "#/definitions/Integer"
98+
}
99+
},
100+
{
101+
"title": "CurrencySymbol",
102+
"purpose": "spend",
103+
"schema": {
104+
"$ref": "#/definitions/CurrencySymbol"
105+
}
106+
},
107+
{
108+
"title": "ScriptHash",
109+
"purpose": "spend",
110+
"schema": {
111+
"$ref": "#/definitions/ScriptHash"
112+
}
113+
}
114+
],
115+
"compiledCode": "59011b01010032322232322232323255333573466e1d200000111300633300700b00b357426ae88d5d11aba235744004226014aa666ae68cdc3a4004002226464664600200244b200318014886400a44aa666ae68cdd780100388c00044cc01801800c0023374a900119aba037526eb80192f5c066600e0160166ae84d5d11aba2357446ae88d5d11aba2002118011bad357426ae88008d55cf1baa357420026aae78dd5000991800800912c800c4c01a0052219002912a999ab9a3375e0040102260150001133006006003088c88d4008dd5800999180080091092999aab9f001180009991400e002600e6aae7400a600c6aae780093533005005120010011aba100135744002240024b2003149a264c66ae71241035054350080008005",
116+
"hash": "70253571744c6c83a1155bd363dd363a5e495208747cfbdfa7e49f60"
117+
},
68118
{
69119
"title": "web2Auth",
70120
"description": "Smart wallet web2 authentication minting policy",

zkfold-cardano-scripts/src/ZkFold/Cardano/UPLC/Wallet.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module ZkFold.Cardano.UPLC.Wallet (
1010
module ZkFold.Cardano.UPLC.Wallet.Types,
1111
web2Auth,
1212
checkSig,
13+
wallet',
1314
wallet,
1415
) where
1516

@@ -143,6 +144,19 @@ checkSig (unsafeFromBuiltinData -> (symb :: CurrencySymbol)) sc =
143144
& BI.head
144145
& unsafeFromBuiltinData
145146

147+
{-# INLINEABLE wallet' #-}
148+
wallet' ::
149+
-- | Dummy parameter for extra addresses
150+
BuiltinData ->
151+
-- | Currency symbol of user's minting script.
152+
BuiltinData ->
153+
-- | Script hash of stake validator.
154+
BuiltinData ->
155+
-- | Script context.
156+
BuiltinData ->
157+
BuiltinUnit
158+
wallet' _ = wallet
159+
146160
{-# INLINEABLE wallet #-}
147161
wallet ::
148162
-- | Currency symbol of user's minting script.

zkfold-cardano-scripts/src/ZkFold/Cardano/UPLC/Wallet/Compile.hs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module ZkFold.Cardano.UPLC.Wallet.Compile (
22
writeSmartWalletBP,
33
web2AuthSerialisedScript,
44
web2AuthCompiledCode,
5+
wallet'SerialisedScript,
6+
wallet'CompiledCode,
57
walletSerialisedScript,
68
walletCompiledCode,
79
checkSigSerialisedScript,
@@ -62,6 +64,46 @@ smartWalletBP =
6264
, validatorDatum = Nothing
6365
, validatorCompiled = Just $ compiledValidator commonPlutusVersion web2AuthSerialisedScript
6466
}
67+
, MkValidatorBlueprint
68+
{ validatorTitle = "wallet'"
69+
, validatorRedeemer =
70+
MkArgumentBlueprint
71+
{ argumentTitle = Just "Unit"
72+
, argumentSchema = definitionRef @()
73+
, argumentPurpose = Set.singleton Spend
74+
, argumentDescription = Nothing
75+
}
76+
, validatorParameters =
77+
[ MkParameterBlueprint
78+
{ parameterTitle = Just "Script index"
79+
, parameterSchema = definitionRef @PlutusTx.Integer
80+
, parameterPurpose = Set.singleton Spend
81+
, parameterDescription = Just "Dummy parameter to generate extra addresses for the same wallet"
82+
}
83+
, MkParameterBlueprint
84+
{ parameterTitle = Just "CurrencySymbol"
85+
, parameterSchema = definitionRef @CurrencySymbol
86+
, parameterPurpose = Set.singleton Spend
87+
, parameterDescription = Nothing
88+
}
89+
, MkParameterBlueprint
90+
{ parameterTitle = Just "ScriptHash"
91+
, parameterSchema = definitionRef @ScriptHash
92+
, parameterPurpose = Set.singleton Spend
93+
, parameterDescription = Nothing
94+
}
95+
]
96+
, validatorDescription = Just "Smart wallet spending validator"
97+
, validatorDatum =
98+
Just $
99+
MkArgumentBlueprint
100+
{ argumentTitle = Nothing
101+
, argumentSchema = definitionRef @PlutusTx.BuiltinData
102+
, argumentPurpose = Set.singleton Spend
103+
, argumentDescription = Nothing
104+
}
105+
, validatorCompiled = Just $ compiledValidator commonPlutusVersion wallet'SerialisedScript
106+
}
65107
, MkValidatorBlueprint
66108
{ validatorTitle = "wallet"
67109
, validatorRedeemer =
@@ -73,6 +115,12 @@ smartWalletBP =
73115
}
74116
, validatorParameters =
75117
[ MkParameterBlueprint
118+
{ parameterTitle = Just "CurrencySymbol"
119+
, parameterSchema = definitionRef @CurrencySymbol
120+
, parameterPurpose = Set.singleton Spend
121+
, parameterDescription = Nothing
122+
}
123+
, MkParameterBlueprint
76124
{ parameterTitle = Just "ScriptHash"
77125
, parameterSchema = definitionRef @ScriptHash
78126
, parameterPurpose = Set.singleton Spend
@@ -112,7 +160,7 @@ smartWalletBP =
112160
, validatorCompiled = Just $ compiledValidator commonPlutusVersion checkSigSerialisedScript
113161
}
114162
]
115-
, contractDefinitions = deriveDefinitions @'[Web2Auth, OnChainWalletConfig, PlutusTx.BuiltinByteString, (), ScriptHash, PlutusTx.BuiltinData, Signature, CurrencySymbol]
163+
, contractDefinitions = deriveDefinitions @'[PlutusTx.Integer, Web2Auth, OnChainWalletConfig, PlutusTx.BuiltinByteString, (), ScriptHash, PlutusTx.BuiltinData, Signature, CurrencySymbol]
116164
}
117165
where
118166
commonPlutusVersion = PlutusV3
@@ -126,6 +174,12 @@ web2AuthSerialisedScript = serialiseCompiledCode web2AuthCompiledCode & fromShor
126174
web2AuthCompiledCode :: PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinUnit)
127175
web2AuthCompiledCode = $$(PlutusTx.compile [||web2Auth||])
128176

177+
wallet'SerialisedScript :: ByteString
178+
wallet'SerialisedScript = serialiseCompiledCode wallet'CompiledCode & fromShort
179+
180+
wallet'CompiledCode :: PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinUnit)
181+
wallet'CompiledCode = $$(PlutusTx.compile [||wallet'||])
182+
129183
walletSerialisedScript :: ByteString
130184
walletSerialisedScript = serialiseCompiledCode walletCompiledCode & fromShort
131185

zkfold-cardano-scripts/zkfold-cardano-scripts.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ common lang
3636
RecordWildCards
3737
ScopedTypeVariables
3838
StandaloneDeriving
39+
Strict
3940
TemplateHaskell
4041
TypeApplications
4142
ViewPatterns
@@ -180,6 +181,7 @@ executable zkfold-cardano-scripts-compiler
180181
zkfold-cardano-scripts,
181182

182183
test-suite buildCrosschainHash-test
184+
import: lang
183185
type: exitcode-stdio-1.0
184186
main-is: Main.hs
185187
hs-source-dirs: test/asterizm

0 commit comments

Comments
 (0)