bypass intermediate buffer in SigHash

parent 12948c24
......@@ -154,11 +154,12 @@ func (uc UnlockConditions) UnlockHash() UnlockHash {
// SigHash returns the hash of the fields in a transaction covered by a given
// signature. See CoveredFields for more details.
func (t Transaction) SigHash(i int) crypto.Hash {
func (t Transaction) SigHash(i int) (hash crypto.Hash) {
cf := t.TransactionSignatures[i].CoveredFields
var signedData []byte
h := crypto.NewHash()
enc := encoding.NewEncoder(h)
if cf.WholeTransaction {
signedData = encoding.MarshalAll(
enc.EncodeAll(
t.SiacoinInputs,
t.SiacoinOutputs,
t.FileContracts,
......@@ -174,39 +175,40 @@ func (t Transaction) SigHash(i int) crypto.Hash {
)
} else {
for _, input := range cf.SiacoinInputs {
signedData = append(signedData, encoding.Marshal(t.SiacoinInputs[input])...)
enc.Encode(t.SiacoinInputs[input])
}
for _, output := range cf.SiacoinOutputs {
signedData = append(signedData, encoding.Marshal(t.SiacoinOutputs[output])...)
enc.Encode(t.SiacoinOutputs[output])
}
for _, contract := range cf.FileContracts {
signedData = append(signedData, encoding.Marshal(t.FileContracts[contract])...)
enc.Encode(t.FileContracts[contract])
}
for _, revision := range cf.FileContractRevisions {
signedData = append(signedData, encoding.Marshal(t.FileContractRevisions[revision])...)
enc.Encode(t.FileContractRevisions[revision])
}
for _, storageProof := range cf.StorageProofs {
signedData = append(signedData, encoding.Marshal(t.StorageProofs[storageProof])...)
enc.Encode(t.StorageProofs[storageProof])
}
for _, siafundInput := range cf.SiafundInputs {
signedData = append(signedData, encoding.Marshal(t.SiafundInputs[siafundInput])...)
enc.Encode(t.SiafundInputs[siafundInput])
}
for _, siafundOutput := range cf.SiafundOutputs {
signedData = append(signedData, encoding.Marshal(t.SiafundOutputs[siafundOutput])...)
enc.Encode(t.SiafundOutputs[siafundOutput])
}
for _, minerFee := range cf.MinerFees {
signedData = append(signedData, encoding.Marshal(t.MinerFees[minerFee])...)
enc.Encode(t.MinerFees[minerFee])
}
for _, arbData := range cf.ArbitraryData {
signedData = append(signedData, encoding.Marshal(t.ArbitraryData[arbData])...)
enc.Encode(t.ArbitraryData[arbData])
}
}
for _, sig := range cf.TransactionSignatures {
signedData = append(signedData, encoding.Marshal(t.TransactionSignatures[sig])...)
enc.Encode(t.TransactionSignatures[sig])
}
return crypto.HashBytes(signedData)
h.Sum(hash[:0])
return
}
// sortedUnique checks that 'elems' is sorted, contains no repeats, and that no
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment