Skip to content

Commit

Permalink
add renter and host signatures to rpc form, renew, and refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Dec 3, 2024
1 parent e086953 commit 2bcb90e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rhp/v4/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,10 @@ func RPCFormContract(ctx context.Context, t TransportClient, tp TxPool, signer F
// sign the renter inputs after the host inputs have been added
signer.SignV2Inputs(&formationTxn, toSign)
formationSigHash := cs.ContractSigHash(fc)
formationTxn.FileContracts[0].RenterSignature = signer.SignHash(formationSigHash)
fc.RenterSignature = signer.SignHash(formationSigHash)

renterPolicyResp := rhp4.RPCFormContractSecondResponse{
RenterContractSignature: formationTxn.FileContracts[0].RenterSignature,
RenterContractSignature: fc.RenterSignature,
}
for _, si := range formationTxn.SiacoinInputs[:len(renterSiacoinElements)] {
renterPolicyResp.RenterSatisfiedPolicies = append(renterPolicyResp.RenterSatisfiedPolicies, si.SatisfiedPolicy)
Expand Down Expand Up @@ -770,7 +770,7 @@ func RPCRenewContract(ctx context.Context, t TransportClient, tp TxPool, signer
return RPCRenewContractResult{
Contract: ContractRevision{
ID: params.ContractID.V2RenewalID(),
Revision: renewal.NewContract,
Revision: hostRenewal.NewContract,
},
RenewalSet: TransactionSet{
Basis: hostTransactionSetResp.Basis,
Expand Down Expand Up @@ -901,7 +901,7 @@ func RPCRefreshContract(ctx context.Context, t TransportClient, tp TxPool, signe
return RPCRefreshContractResult{
Contract: ContractRevision{
ID: params.ContractID.V2RenewalID(),
Revision: renewal.NewContract,
Revision: hostRenewal.NewContract,
},
RenewalSet: TransactionSet{
Basis: hostTransactionSetResp.Basis,
Expand Down
41 changes: 41 additions & 0 deletions rhp/v4/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ func TestFormContract(t *testing.T) {
} else if !known {
t.Fatal("expected transaction set to be known")
}

sigHash := cm.TipState().ContractSigHash(result.Contract.Revision)
if !renterKey.PublicKey().VerifyHash(sigHash, result.Contract.Revision.RenterSignature) {
t.Fatal("renter signature verification failed")
} else if !hostKey.PublicKey().VerifyHash(sigHash, result.Contract.Revision.HostSignature) {
t.Fatal("host signature verification failed")
}
}

func TestFormContractBasis(t *testing.T) {
Expand Down Expand Up @@ -420,6 +427,13 @@ func TestRPCRefresh(t *testing.T) {
} else if !known {
t.Fatal("expected transaction set to be known")
}

sigHash := cm.TipState().ContractSigHash(refreshResult.Contract.Revision)
if !renterKey.PublicKey().VerifyHash(sigHash, refreshResult.Contract.Revision.RenterSignature) {
t.Fatal("renter signature verification failed")
} else if !hostKey.PublicKey().VerifyHash(sigHash, refreshResult.Contract.Revision.HostSignature) {
t.Fatal("host signature verification failed")
}
})
}

Expand Down Expand Up @@ -473,6 +487,12 @@ func TestRPCRenew(t *testing.T) {
t.Fatal(err)
}
revision := result.Contract
sigHash := cm.TipState().ContractSigHash(revision.Revision)
if !renterKey.PublicKey().VerifyHash(sigHash, revision.Revision.RenterSignature) {
t.Fatal("renter signature verification failed")
} else if !hostKey.PublicKey().VerifyHash(sigHash, revision.Revision.HostSignature) {
t.Fatal("host signature verification failed")
}

// verify the transaction set is valid
if known, err := cm.AddV2PoolTransactions(result.FormationSet.Basis, result.FormationSet.Transactions); err != nil {
Expand Down Expand Up @@ -534,6 +554,13 @@ func TestRPCRenew(t *testing.T) {
} else if !known {
t.Fatal("expected transaction set to be known")
}

sigHash := cm.TipState().ContractSigHash(renewResult.Contract.Revision)
if !renterKey.PublicKey().VerifyHash(sigHash, renewResult.Contract.Revision.RenterSignature) {
t.Fatal("renter signature verification failed")
} else if !hostKey.PublicKey().VerifyHash(sigHash, renewResult.Contract.Revision.HostSignature) {
t.Fatal("host signature verification failed")
}
})

t.Run("full rollover", func(t *testing.T) {
Expand All @@ -556,6 +583,13 @@ func TestRPCRenew(t *testing.T) {
} else if !known {
t.Fatal("expected transaction set to be known")
}

sigHash := cm.TipState().ContractSigHash(renewResult.Contract.Revision)
if !renterKey.PublicKey().VerifyHash(sigHash, renewResult.Contract.Revision.RenterSignature) {
t.Fatal("renter signature verification failed")
} else if !hostKey.PublicKey().VerifyHash(sigHash, renewResult.Contract.Revision.HostSignature) {
t.Fatal("host signature verification failed")
}
})

t.Run("no rollover", func(t *testing.T) {
Expand All @@ -578,6 +612,13 @@ func TestRPCRenew(t *testing.T) {
} else if !known {
t.Fatal("expected transaction set to be known")
}

sigHash := cm.TipState().ContractSigHash(renewResult.Contract.Revision)
if !renterKey.PublicKey().VerifyHash(sigHash, renewResult.Contract.Revision.RenterSignature) {
t.Fatal("renter signature verification failed")
} else if !hostKey.PublicKey().VerifyHash(sigHash, renewResult.Contract.Revision.HostSignature) {
t.Fatal("host signature verification failed")
}
})
}

Expand Down

0 comments on commit 2bcb90e

Please sign in to comment.