Skip to content

Commit

Permalink
Fix off-by-one edge case bug when > 255 outputs in a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed Oct 25, 2023
1 parent 9234b8b commit 839d87a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/cashscript/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
LockingBytecodeType,
encodeTransactionOutput,
isHex,
bigIntToCompactSize,
} from '@bitauth/libauth';
import {
encodeInt,
Expand Down Expand Up @@ -148,7 +149,7 @@ export function getTxSizeWithoutInputs(outputs: Output[]): number {
let size = VERSION_SIZE + LOCKTIME_SIZE;
size += outputs.reduce((acc, output) => acc + getOutputSize(output), 0);
// Add tx-out count (accounting for a potential change output)
size += encodeInt(BigInt(outputs.length + 1)).byteLength;
size += bigIntToCompactSize(BigInt(outputs.length + 1)).byteLength;

return size;
}
Expand Down

1 comment on commit 839d87a

@vercel
Copy link

@vercel vercel bot commented on 839d87a Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.