Skip to content

Commit

Permalink
Update isStandardOutputBytecode to allow P2SH32
Browse files Browse the repository at this point in the history
Fixes #133
  • Loading branch information
bitjson committed May 28, 2024
1 parent 49bcce4 commit 1f34ca4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .changeset/curvy-pandas-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@bitauth/libauth': patch
---

Update `isStandardOutputBytecode` to allow P2SH32

Fixes #133. Thanks for the report @rkalis!
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ High-level utilities are composed from lower-level utilities which are also expo
- [`isArbitraryDataOutput`](https://libauth.org/functions/isArbitraryDataOutput.html)
- [`isSimpleMultisig`](https://libauth.org/functions/isSimpleMultisig.html)
- [`isStandardOutputBytecode`](https://libauth.org/functions/isStandardOutputBytecode.html)
- [`isStandardOutputBytecode2023`](https://libauth.org/functions/isStandardOutputBytecode2023.html)
- [`isStandardOutputBytecodePre2023`](https://libauth.org/functions/isStandardOutputBytecodePre2023.html)
- [`isStandardMultisig`](https://libauth.org/functions/isStandardMultisig.html)
- [`isWitnessProgram`](https://libauth.org/functions/isWitnessProgram.html)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
isArbitraryDataOutput,
isDustOutput,
isPushOnly,
isStandardOutputBytecode2023,
isStandardOutputBytecode,
isWitnessProgram,
mapOverOperations,
op0NotEqual,
Expand Down Expand Up @@ -686,7 +686,7 @@ export const createInstructionSetBch2023 = <

// eslint-disable-next-line functional/no-loop-statements
for (const [index, output] of sourceOutputs.entries()) {
if (!isStandardOutputBytecode2023(output.lockingBytecode)) {
if (!isStandardOutputBytecode(output.lockingBytecode)) {
return `Standard transactions may only spend standard output types, but source output ${index} is non-standard.`;
}
}
Expand All @@ -695,7 +695,7 @@ export const createInstructionSetBch2023 = <
let totalArbitraryDataBytes = 0;
// eslint-disable-next-line functional/no-loop-statements
for (const [index, output] of transaction.outputs.entries()) {
if (!isStandardOutputBytecode2023(output.lockingBytecode)) {
if (!isStandardOutputBytecode(output.lockingBytecode)) {
return `Standard transactions may only create standard output types, but transaction output ${index} is non-standard.`;
}
// eslint-disable-next-line functional/no-conditional-statements
Expand Down
27 changes: 18 additions & 9 deletions src/lib/vm/instruction-sets/common/instruction-sets-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,21 +922,30 @@ export const isStandardMultisig = (lockingBytecode: Uint8Array) => {
return true;
};

export const isStandardOutputBytecode = (lockingBytecode: Uint8Array) =>
/**
* Test that the provided locking bytecode matches one of the standard output
* bytecode patterns prior to the `BCH_2023_05` upgrade (following
* P2SH32 activation).
* @param lockingBytecode - the locking bytecode to test for standardness
*/
export const isStandardOutputBytecodePre2023 = (lockingBytecode: Uint8Array) =>
isPayToPublicKeyHash(lockingBytecode) ||
isPayToScriptHash20(lockingBytecode) ||
isPayToPublicKey(lockingBytecode) ||
isArbitraryDataOutput(lockingBytecode) ||
isStandardMultisig(lockingBytecode);

// eslint-disable-next-line complexity
export const isStandardOutputBytecode2023 = (lockingBytecode: Uint8Array) =>
isPayToPublicKeyHash(lockingBytecode) ||
isPayToScriptHash20(lockingBytecode) ||
isPayToScriptHash32(lockingBytecode) ||
isPayToPublicKey(lockingBytecode) ||
isArbitraryDataOutput(lockingBytecode) ||
isStandardMultisig(lockingBytecode);
/**
* Test that the provided locking bytecode matches one of the standard output
* bytecode patterns as of the `BCH_2023_05` upgrade (following
* P2SH32 activation).
* @param lockingBytecode - the locking bytecode to test for standardness
*/
export const isStandardOutputBytecode = (lockingBytecode: Uint8Array) =>
isStandardOutputBytecodePre2023(lockingBytecode) ||
isPayToScriptHash32(lockingBytecode);

export const isStandardOutputBytecode2023 = isStandardOutputBytecode;

const enum SegWit {
minimumLength = 4,
Expand Down

0 comments on commit 1f34ca4

Please sign in to comment.