Skip to content

Commit 2a69a0d

Browse files
committed
fix: encode bigint values as bytes correctly without overflowing
1 parent 05a92d1 commit 2a69a0d

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

examples/auction/contract.algo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class Auction extends Contract {
8181
}
8282

8383
@abimethod({ allowActions: 'OptIn' })
84-
public optInToApplication(): void { }
84+
public optInToApplication(): void {}
8585

8686
public bid(payment: gtxn.PaymentTxn): void {
8787
/// Ensure auction hasn't ended

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
"vitest": "3.0.9"
6767
},
6868
"dependencies": {
69-
"@algorandfoundation/algorand-typescript": "1.0.0-alpha.47",
70-
"@algorandfoundation/puya-ts": "1.0.0-alpha.47",
69+
"@algorandfoundation/algorand-typescript": "1.0.0-alpha.49",
70+
"@algorandfoundation/puya-ts": "1.0.0-alpha.49",
7171
"elliptic": "^6.6.1",
7272
"js-sha256": "^0.11.0",
7373
"js-sha3": "^0.9.3",

src/encoders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const getEncoder = <T>(typeInfo: TypeInfo): fromBytes<T> => {
6363
}
6464

6565
export const toBytes = (val: unknown): bytes => {
66-
const uint64Val = asMaybeUint64Cls(val)
66+
const uint64Val = asMaybeUint64Cls(val, false)
6767
if (uint64Val !== undefined) {
6868
return uint64Val.toBytes().asAlgoTs()
6969
}

src/util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ export const asBytes = (val: StubBytesCompat | Uint8Array) => asBytesCls(val).as
4242

4343
export const asUint8Array = (val: StubBytesCompat | Uint8Array) => asBytesCls(val).asUint8Array()
4444

45-
export const asMaybeUint64Cls = (val: DeliberateAny) => {
45+
export const asMaybeUint64Cls = (val: DeliberateAny, throwsOverflow: boolean = true) => {
4646
try {
4747
return Uint64Cls.fromCompat(val)
4848
} catch (e) {
4949
if (e instanceof InternalError) {
5050
// swallow error and return undefined
51+
} else if (!throwsOverflow && e instanceof AvmError && e.message.includes('overflow')) {
52+
// swallow overflow error and return undefined
5153
} else {
5254
throw e
5355
}

0 commit comments

Comments
 (0)