Skip to content

Commit d0d54b9

Browse files
committed
Fix OP_TXVERSION VMB tests, reduce 2025 nonstandard hashing density limit
1 parent c0eadac commit d0d54b9

23 files changed

Lines changed: 200 additions & 190 deletions

.changeset/famous-spies-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@bitauth/libauth': patch
3+
---
4+
5+
Fix OP_TXVERSION VMB tests, reduce 2025 nonstandard hashing density limit

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ export enum ConsensusBch2023 {
2828
*/
2929
maximumStackItemLength = 520,
3030
/**
31-
* A.K.A. `MAX_STANDARD_VERSION`
31+
* A.K.A. `MIN_CONSENSUS_VERSION`
3232
*/
33-
maximumStandardVersion = 2,
33+
minimumConsensusVersion = 1,
34+
/**
35+
* A.K.A. `MAX_CONSENSUS_VERSION`
36+
*/
37+
maximumConsensusVersion = 2,
3438
/**
3539
* A.K.A. `MAX_TX_IN_SCRIPT_SIG_SIZE`
3640
*/

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,16 +698,15 @@ export const createInstructionSetBch2023 = <
698698
* included here for debugging purposes.
699699
*/
700700
if (firstDuplicate !== undefined) {
701-
return `Unable to verify transaction: the transaction attempts to spend the same outpoint in multiple inputs. ${firstDuplicate}`;
701+
return `Unable to verify transaction: the transaction attempts to spend the same outpoint in multiple inputs. ${firstDuplicate}.`;
702+
}
703+
if (
704+
transaction.version < ConsensusBch2023.minimumConsensusVersion ||
705+
transaction.version > ConsensusBch2023.maximumConsensusVersion
706+
) {
707+
return `Transaction version must be either 1 or 2. Encoded version number: ${transaction.version}.`;
702708
}
703-
704709
if (standard) {
705-
if (
706-
transaction.version < 1 ||
707-
transaction.version > ConsensusBch2023.maximumStandardVersion
708-
) {
709-
return `Standard transactions must have a version no less than 1 and no greater than ${ConsensusBch2023.maximumStandardVersion}.`;
710-
}
711710
if (
712711
transactionLengthBytes >
713712
ConsensusBch2023.maximumStandardTransactionSize

src/lib/vm/instruction-sets/bch/2025/bch-2025-consensus.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export enum ConsensusBch2025Overrides {
99
*/
1010
maximumStackItemLength = 10_000,
1111

12-
standardHashDigestIterationsPerByte = 0.5,
13-
nonstandardHashDigestIterationsPerByte = 5,
12+
hashDigestIterationsPerByteStandard = 0.5,
13+
hashDigestIterationsPerByteNonstandard = 4,
14+
bytesPerCodeSeparatorStandard = 65,
1415
}
1516

1617
/**

src/lib/vm/instruction-sets/bch/2025/bch-2025-crypto.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export const incrementHashDigestIterations = <
5252
}: {
5353
/**
5454
* If `true`, the limit will use
55-
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
55+
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
5656
* it will use
57-
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
57+
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
5858
*/
5959
strict: boolean;
6060
/**
@@ -75,8 +75,8 @@ export const incrementHashDigestIterations = <
7575
(resultIsHashed ? 1 : 0) +
7676
lengthToHashDigestIterationCount(messageLength);
7777
const maximumIterationsPerByte = strict
78-
? ConsensusBch2025.standardHashDigestIterationsPerByte
79-
: ConsensusBch2025.nonstandardHashDigestIterationsPerByte;
78+
? ConsensusBch2025.hashDigestIterationsPerByteStandard
79+
: ConsensusBch2025.hashDigestIterationsPerByteNonstandard;
8080
const maximumHashDigestIterations = Math.floor(
8181
maximumIterationsPerByte * state.transactionLengthBytes,
8282
);
@@ -109,9 +109,9 @@ export const opRipemd160ChipLimits =
109109
}: {
110110
/**
111111
* If `true`, the limit will use
112-
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
112+
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
113113
* it will use
114-
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
114+
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
115115
*/
116116
strict: boolean;
117117
ripemd160: { hash: Ripemd160['hash'] };
@@ -140,9 +140,9 @@ export const opSha1ChipLimits =
140140
sha1: { hash: Sha1['hash'] };
141141
/**
142142
* If `true`, the limit will use
143-
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
143+
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
144144
* it will use
145-
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
145+
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
146146
*/
147147
strict: boolean;
148148
} = { sha1: internalSha1, strict: true },
@@ -172,9 +172,9 @@ export const opSha256ChipLimits =
172172
};
173173
/**
174174
* If `true`, the limit will use
175-
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
175+
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
176176
* it will use
177-
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
177+
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
178178
*/
179179
strict: boolean;
180180
} = { sha256: internalSha256, strict: true },
@@ -204,9 +204,9 @@ export const opHash160ChipLimits =
204204
ripemd160: { hash: Ripemd160['hash'] };
205205
/**
206206
* If `true`, the limit will use
207-
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
207+
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
208208
* it will use
209-
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
209+
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
210210
*/
211211
strict: boolean;
212212
} = { ripemd160: internalRipemd160, sha256: internalSha256, strict: true },
@@ -237,9 +237,9 @@ export const opHash256ChipLimits =
237237
};
238238
/**
239239
* If `true`, the limit will use
240-
* {@link ConsensusBch2025.standardHashDigestIterationsPerByte}, otherwise
240+
* {@link ConsensusBch2025.hashDigestIterationsPerByteStandard}, otherwise
241241
* it will use
242-
* {@link ConsensusBch2025.nonstandardHashDigestIterationsPerByte}.
242+
* {@link ConsensusBch2025.hashDigestIterationsPerByteNonstandard}.
243243
*/
244244
strict: boolean;
245245
} = { sha256: internalSha256, strict: true },

0 commit comments

Comments
 (0)