Skip to content

Commit 1f34ca4

Browse files
committed
Update isStandardOutputBytecode to allow P2SH32
Fixes bitauth#133
1 parent 49bcce4 commit 1f34ca4

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

.changeset/curvy-pandas-agree.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@bitauth/libauth': patch
3+
---
4+
5+
Update `isStandardOutputBytecode` to allow P2SH32
6+
7+
Fixes #133. Thanks for the report @rkalis!

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ High-level utilities are composed from lower-level utilities which are also expo
319319
- [`isArbitraryDataOutput`](https://libauth.org/functions/isArbitraryDataOutput.html)
320320
- [`isSimpleMultisig`](https://libauth.org/functions/isSimpleMultisig.html)
321321
- [`isStandardOutputBytecode`](https://libauth.org/functions/isStandardOutputBytecode.html)
322-
- [`isStandardOutputBytecode2023`](https://libauth.org/functions/isStandardOutputBytecode2023.html)
322+
- [`isStandardOutputBytecodePre2023`](https://libauth.org/functions/isStandardOutputBytecodePre2023.html)
323323
- [`isStandardMultisig`](https://libauth.org/functions/isStandardMultisig.html)
324324
- [`isWitnessProgram`](https://libauth.org/functions/isWitnessProgram.html)
325325

src/lib/vm/instruction-sets/bch/2023/bch-2023-instruction-set.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
isArbitraryDataOutput,
3535
isDustOutput,
3636
isPushOnly,
37-
isStandardOutputBytecode2023,
37+
isStandardOutputBytecode,
3838
isWitnessProgram,
3939
mapOverOperations,
4040
op0NotEqual,
@@ -686,7 +686,7 @@ export const createInstructionSetBch2023 = <
686686

687687
// eslint-disable-next-line functional/no-loop-statements
688688
for (const [index, output] of sourceOutputs.entries()) {
689-
if (!isStandardOutputBytecode2023(output.lockingBytecode)) {
689+
if (!isStandardOutputBytecode(output.lockingBytecode)) {
690690
return `Standard transactions may only spend standard output types, but source output ${index} is non-standard.`;
691691
}
692692
}
@@ -695,7 +695,7 @@ export const createInstructionSetBch2023 = <
695695
let totalArbitraryDataBytes = 0;
696696
// eslint-disable-next-line functional/no-loop-statements
697697
for (const [index, output] of transaction.outputs.entries()) {
698-
if (!isStandardOutputBytecode2023(output.lockingBytecode)) {
698+
if (!isStandardOutputBytecode(output.lockingBytecode)) {
699699
return `Standard transactions may only create standard output types, but transaction output ${index} is non-standard.`;
700700
}
701701
// eslint-disable-next-line functional/no-conditional-statements

src/lib/vm/instruction-sets/common/instruction-sets-utils.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -922,21 +922,30 @@ export const isStandardMultisig = (lockingBytecode: Uint8Array) => {
922922
return true;
923923
};
924924

925-
export const isStandardOutputBytecode = (lockingBytecode: Uint8Array) =>
925+
/**
926+
* Test that the provided locking bytecode matches one of the standard output
927+
* bytecode patterns prior to the `BCH_2023_05` upgrade (following
928+
* P2SH32 activation).
929+
* @param lockingBytecode - the locking bytecode to test for standardness
930+
*/
931+
export const isStandardOutputBytecodePre2023 = (lockingBytecode: Uint8Array) =>
926932
isPayToPublicKeyHash(lockingBytecode) ||
927933
isPayToScriptHash20(lockingBytecode) ||
928934
isPayToPublicKey(lockingBytecode) ||
929935
isArbitraryDataOutput(lockingBytecode) ||
930936
isStandardMultisig(lockingBytecode);
931937

932-
// eslint-disable-next-line complexity
933-
export const isStandardOutputBytecode2023 = (lockingBytecode: Uint8Array) =>
934-
isPayToPublicKeyHash(lockingBytecode) ||
935-
isPayToScriptHash20(lockingBytecode) ||
936-
isPayToScriptHash32(lockingBytecode) ||
937-
isPayToPublicKey(lockingBytecode) ||
938-
isArbitraryDataOutput(lockingBytecode) ||
939-
isStandardMultisig(lockingBytecode);
938+
/**
939+
* Test that the provided locking bytecode matches one of the standard output
940+
* bytecode patterns as of the `BCH_2023_05` upgrade (following
941+
* P2SH32 activation).
942+
* @param lockingBytecode - the locking bytecode to test for standardness
943+
*/
944+
export const isStandardOutputBytecode = (lockingBytecode: Uint8Array) =>
945+
isStandardOutputBytecodePre2023(lockingBytecode) ||
946+
isPayToScriptHash32(lockingBytecode);
947+
948+
export const isStandardOutputBytecode2023 = isStandardOutputBytecode;
940949

941950
const enum SegWit {
942951
minimumLength = 4,

0 commit comments

Comments
 (0)