7
7
"sync"
8
8
"testing"
9
9
10
+ "go.sia.tech/core/consensus"
10
11
proto4 "go.sia.tech/core/rhp/v4"
11
12
"go.sia.tech/core/types"
12
13
"go.sia.tech/coreutils/chain"
@@ -119,6 +120,13 @@ func (ec *EphemeralContractor) AddV2Contract(formationSet rhp4.TransactionSet, _
119
120
}
120
121
fc := formationTxn .FileContracts [0 ]
121
122
123
+ sigHash := consensus.State {}.ContractSigHash (fc )
124
+ if ! fc .RenterPublicKey .VerifyHash (sigHash , fc .RenterSignature ) {
125
+ return errors .New ("invalid renter signature" )
126
+ } else if ! fc .HostPublicKey .VerifyHash (sigHash , fc .HostSignature ) {
127
+ return errors .New ("invalid host signature" )
128
+ }
129
+
122
130
contractID := formationTxn .V2FileContractID (formationTxn .ID (), 0 )
123
131
if _ , ok := ec .contracts [contractID ]; ok {
124
132
return errors .New ("contract already exists" )
@@ -160,6 +168,13 @@ func (ec *EphemeralContractor) RenewV2Contract(renewalSet rhp4.TransactionSet, _
160
168
return errors .New ("contract already exists" )
161
169
}
162
170
171
+ sigHash := consensus.State {}.ContractSigHash (renewal .NewContract )
172
+ if ! existing .RenterPublicKey .VerifyHash (sigHash , renewal .NewContract .RenterSignature ) {
173
+ return errors .New ("invalid renter signature" )
174
+ } else if ! existing .HostPublicKey .VerifyHash (sigHash , renewal .NewContract .HostSignature ) {
175
+ return errors .New ("invalid host signature" )
176
+ }
177
+
163
178
delete (ec .contracts , existingID ) // remove the existing contract
164
179
ec .contracts [contractID ] = renewal .NewContract
165
180
ec .roots [contractID ] = append ([]types.Hash256 (nil ), ec .roots [existingID ]... )
@@ -179,6 +194,13 @@ func (ec *EphemeralContractor) ReviseV2Contract(contractID types.FileContractID,
179
194
return errors .New ("revision number must be greater than existing" )
180
195
}
181
196
197
+ sigHash := consensus.State {}.ContractSigHash (revision )
198
+ if ! existing .RenterPublicKey .VerifyHash (sigHash , revision .RenterSignature ) {
199
+ return errors .New ("invalid renter signature" )
200
+ } else if ! existing .HostPublicKey .VerifyHash (sigHash , revision .HostSignature ) {
201
+ return errors .New ("invalid host signature" )
202
+ }
203
+
182
204
ec .contracts [contractID ] = revision
183
205
ec .roots [contractID ] = append ([]types.Hash256 (nil ), roots ... )
184
206
return nil
@@ -202,11 +224,26 @@ func (ec *EphemeralContractor) CreditAccountsWithContract(deposits []proto4.Acco
202
224
ec .mu .Lock ()
203
225
defer ec .mu .Unlock ()
204
226
227
+ existing , ok := ec .contracts [contractID ]
228
+ if ! ok {
229
+ return nil , errors .New ("contract not found" )
230
+ } else if revision .RevisionNumber <= existing .RevisionNumber {
231
+ return nil , errors .New ("revision number must be greater than existing" )
232
+ }
233
+
234
+ sigHash := consensus.State {}.ContractSigHash (revision )
235
+ if ! existing .RenterPublicKey .VerifyHash (sigHash , revision .RenterSignature ) {
236
+ return nil , errors .New ("invalid renter signature" )
237
+ } else if ! existing .HostPublicKey .VerifyHash (sigHash , revision .HostSignature ) {
238
+ return nil , errors .New ("invalid host signature" )
239
+ }
240
+
205
241
var balance = make ([]types.Currency , 0 , len (deposits ))
206
242
for _ , deposit := range deposits {
207
243
ec .accounts [deposit .Account ] = ec .accounts [deposit .Account ].Add (deposit .Amount )
208
244
balance = append (balance , ec .accounts [deposit .Account ])
209
245
}
246
+
210
247
ec .contracts [contractID ] = revision
211
248
return balance , nil
212
249
}
0 commit comments