Skip to content

Commit

Permalink
Fix OP_TXVERSION VMB tests, reduce 2025 nonstandard hashing density l…
Browse files Browse the repository at this point in the history
…imit
  • Loading branch information
bitjson committed May 31, 2024
1 parent c0eadac commit d0d54b9
Show file tree
Hide file tree
Showing 23 changed files with 200 additions and 190 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-spies-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bitauth/libauth': patch
---

Fix OP_TXVERSION VMB tests, reduce 2025 nonstandard hashing density limit
8 changes: 6 additions & 2 deletions src/lib/vm/instruction-sets/bch/2023/bch-2023-consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ export enum ConsensusBch2023 {
*/
maximumStackItemLength = 520,
/**
* A.K.A. `MAX_STANDARD_VERSION`
* A.K.A. `MIN_CONSENSUS_VERSION`
*/
maximumStandardVersion = 2,
minimumConsensusVersion = 1,
/**
* A.K.A. `MAX_CONSENSUS_VERSION`
*/
maximumConsensusVersion = 2,
/**
* A.K.A. `MAX_TX_IN_SCRIPT_SIG_SIZE`
*/
Expand Down
15 changes: 7 additions & 8 deletions src/lib/vm/instruction-sets/bch/2023/bch-2023-instruction-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,16 +698,15 @@ export const createInstructionSetBch2023 = <
* included here for debugging purposes.
*/
if (firstDuplicate !== undefined) {
return `Unable to verify transaction: the transaction attempts to spend the same outpoint in multiple inputs. ${firstDuplicate}`;
return `Unable to verify transaction: the transaction attempts to spend the same outpoint in multiple inputs. ${firstDuplicate}.`;
}

Check warning on line 702 in src/lib/vm/instruction-sets/bch/2023/bch-2023-instruction-set.ts

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L701 - L702 were not covered by tests
if (
transaction.version < ConsensusBch2023.minimumConsensusVersion ||
transaction.version > ConsensusBch2023.maximumConsensusVersion
) {
return `Transaction version must be either 1 or 2. Encoded version number: ${transaction.version}.`;
}

if (standard) {
if (
transaction.version < 1 ||
transaction.version > ConsensusBch2023.maximumStandardVersion
) {
return `Standard transactions must have a version no less than 1 and no greater than ${ConsensusBch2023.maximumStandardVersion}.`;
}
if (
transactionLengthBytes >
ConsensusBch2023.maximumStandardTransactionSize
Expand Down
5 changes: 3 additions & 2 deletions src/lib/vm/instruction-sets/bch/2025/bch-2025-consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export enum ConsensusBch2025Overrides {
*/
maximumStackItemLength = 10_000,

standardHashDigestIterationsPerByte = 0.5,
nonstandardHashDigestIterationsPerByte = 5,
hashDigestIterationsPerByteStandard = 0.5,
hashDigestIterationsPerByteNonstandard = 4,
bytesPerCodeSeparatorStandard = 65,
}

/**
Expand Down
28 changes: 14 additions & 14 deletions src/lib/vm/instruction-sets/bch/2025/bch-2025-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export const incrementHashDigestIterations = <
}: {
/**
* If `true`, the limit will use
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
* it will use
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
*/
strict: boolean;
/**
Expand All @@ -75,8 +75,8 @@ export const incrementHashDigestIterations = <
(resultIsHashed ? 1 : 0) +
lengthToHashDigestIterationCount(messageLength);
const maximumIterationsPerByte = strict
? ConsensusBch2025.standardHashDigestIterationsPerByte
: ConsensusBch2025.nonstandardHashDigestIterationsPerByte;
? ConsensusBch2025.hashDigestIterationsPerByteStandard
: ConsensusBch2025.hashDigestIterationsPerByteNonstandard;
const maximumHashDigestIterations = Math.floor(
maximumIterationsPerByte * state.transactionLengthBytes,
);
Expand Down Expand Up @@ -109,9 +109,9 @@ export const opRipemd160ChipLimits =
}: {
/**
* If `true`, the limit will use
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
* it will use
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
*/
strict: boolean;
ripemd160: { hash: Ripemd160['hash'] };
Expand Down Expand Up @@ -140,9 +140,9 @@ export const opSha1ChipLimits =
sha1: { hash: Sha1['hash'] };
/**
* If `true`, the limit will use
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
* it will use
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
*/
strict: boolean;
} = { sha1: internalSha1, strict: true },
Expand Down Expand Up @@ -172,9 +172,9 @@ export const opSha256ChipLimits =
};
/**
* If `true`, the limit will use
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
* it will use
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
*/
strict: boolean;
} = { sha256: internalSha256, strict: true },
Expand Down Expand Up @@ -204,9 +204,9 @@ export const opHash160ChipLimits =
ripemd160: { hash: Ripemd160['hash'] };
/**
* If `true`, the limit will use
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
* it will use
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
*/
strict: boolean;
} = { ripemd160: internalRipemd160, sha256: internalSha256, strict: true },
Expand Down Expand Up @@ -237,9 +237,9 @@ export const opHash256ChipLimits =
};
/**
* If `true`, the limit will use
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
* it will use
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
*/
strict: boolean;
} = { sha256: internalSha256, strict: true },
Expand Down
Loading

0 comments on commit d0d54b9

Please sign in to comment.