Skip to content

Commit 615e4f4

Browse files
fix: enum hashed outcomes
1 parent 8c6f33d commit 615e4f4

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

packages/bitcoin-dlc-provider/lib/BitcoinDlcProvider.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ export default class BitcoinDlcProvider
599599
dlcAccept.acceptCollateralSatoshis -
600600
outcome.localPayout,
601601
});
602-
messagesList.push({ messages: [outcome.outcome.toString()] });
602+
messagesList.push({ messages: [outcome.outcome.toString('hex')] });
603603
}
604604
} else {
605605
const payoutResponses = this.GetPayouts(dlcOffer);
@@ -1731,8 +1731,8 @@ Payout Group not found',
17311731
const outcomeIndex = ((dlcOffer.contractInfo as ContractInfoV0)
17321732
.contractDescriptor as ContractDescriptorV0).outcomes.findIndex(
17331733
(outcome) =>
1734-
outcome.outcome.toString() ===
1735-
oracleAttestation.outcomes[0].toString(),
1734+
outcome.outcome.toString('hex') ===
1735+
sha256(Buffer.from(oracleAttestation.outcomes[0])).toString('hex'),
17361736
);
17371737

17381738
signCetRequest = {
@@ -2877,7 +2877,7 @@ Payout Group not found',
28772877
) {
28782878
for (const outcome of ((dlcOffer.contractInfo as ContractInfoV0)
28792879
.contractDescriptor as ContractDescriptorV0).outcomes) {
2880-
messagesList.push({ messages: [outcome.outcome.toString()] });
2880+
messagesList.push({ messages: [outcome.outcome.toString('hex')] });
28812881
}
28822882
} else {
28832883
const payoutResponses = this.GetPayouts(dlcOffer);

tests/integration/dlc/dlc.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
OracleInfoV0,
3232
RoundingIntervalsV0,
3333
} from '@node-dlc/messaging';
34-
import { xor } from '@node-lightning/crypto';
34+
import { sha256, xor } from '@node-lightning/crypto';
3535
import BN from 'bignumber.js';
3636
import { math } from 'bip-schnorr';
3737
import { BitcoinNetworks, chainHashFromNetwork } from 'bitcoin-networks';
@@ -185,15 +185,15 @@ describe('dlc provider', () => {
185185

186186
contractDescriptor.outcomes = [
187187
{
188-
outcome: Buffer.from('trump', 'utf8'),
188+
outcome: sha256(Buffer.from('trump')),
189189
localPayout: BigInt(1e6),
190190
},
191191
{
192-
outcome: Buffer.from('kamala', 'utf8'),
192+
outcome: sha256(Buffer.from('kamala')),
193193
localPayout: BigInt(0),
194194
},
195195
{
196-
outcome: Buffer.from('neither', 'utf8'),
196+
outcome: sha256(Buffer.from('neither')),
197197
localPayout: BigInt(500000),
198198
},
199199
];
@@ -218,6 +218,9 @@ describe('dlc provider', () => {
218218
[aliceInput],
219219
);
220220

221+
const dlcOfferV0 = DlcOfferV0.deserialize(dlcOffer.serialize());
222+
dlcOfferV0.validate();
223+
221224
const acceptDlcOfferResponse: AcceptDlcOfferResponse = await bob.dlc.acceptDlcOffer(
222225
dlcOffer,
223226
[bobInput],

tests/integration/utils/contract.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
PayoutFunctionV0,
2121
RoundingIntervalsV0,
2222
} from '@node-dlc/messaging';
23+
import { sha256 } from '@node-lightning/crypto';
2324
import BN from 'bignumber.js';
2425
import { math } from 'bip-schnorr';
2526

@@ -307,7 +308,10 @@ export function generateEnumOracleAttestation(
307308
const sigs: Buffer[] = [];
308309

309310
const m = math
310-
.taggedHash('DLC/oracle/attestation/v0', outcome)
311+
.taggedHash(
312+
'DLC/oracle/attestation/v0',
313+
sha256(Buffer.from(outcome)).toString('hex'),
314+
)
311315
.toString('hex');
312316
sigs.push(Buffer.from(oracle.GetSignature(m), 'hex'));
313317

0 commit comments

Comments
 (0)