From 78175fe624aaf1169123a89340aa458f3d7259cd Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 21 Aug 2024 14:16:12 +0200 Subject: [PATCH 1/3] fix int64 mod when the input is negative and result = 0 --- src/lib/provable/int.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/provable/int.ts b/src/lib/provable/int.ts index bc4e741f91..e919b17a9e 100644 --- a/src/lib/provable/int.ts +++ b/src/lib/provable/int.ts @@ -1334,7 +1334,11 @@ class Int64 extends CircuitValue implements BalanceChange { let isNonNegative = this.magnitude .equals(UInt64.zero) .or(this.sgn.isPositive()); - rest = Provable.if(isNonNegative, rest, y_.value.sub(rest)); + rest = Provable.if( + isNonNegative.or(rest.equals(0)), + rest, + y_.value.sub(rest) + ); return new Int64(new UInt64(rest.value)); } From ac03ac549188a64f4708074adf30b4db1efbf0f0 Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 21 Aug 2024 14:18:06 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index baf5beaf6a..a6b14ffc8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased](https://github.com/o1-labs/o1js/compare/d6abf1d97...HEAD) +### Fixes + +- Fix behavior of `Int64.modV2()` when the input is negative and the remainder should be 0 https://github.com/o1-labs/o1js/pull/1797 + ## [1.6.0](https://github.com/o1-labs/o1js/compare/1ad7333e9e...d6abf1d97) - 2024-07-23 ### Added From ecac253a4002f51a107552fcefc5b2f2aec9dae4 Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 21 Aug 2024 14:32:31 +0200 Subject: [PATCH 3/3] int64 to bigint --- src/lib/provable/int.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/provable/int.ts b/src/lib/provable/int.ts index e919b17a9e..15c64c6249 100644 --- a/src/lib/provable/int.ts +++ b/src/lib/provable/int.ts @@ -1147,14 +1147,22 @@ class Int64 extends CircuitValue implements BalanceChange { return Int64.create(UInt64.from(obj.magnitude), Sign.fromValue(obj.sgn)); } + /** + * Turns the {@link Int64} into a {@link BigInt}. + */ + toBigint() { + let abs = this.magnitude.toBigInt(); + let sgn = this.sgn.isPositive().toBoolean() ? 1n : -1n; + return sgn * abs; + } + /** * Turns the {@link Int64} into a string. */ toString() { - let abs = this.magnitude.toString(); - let sgn = this.isPositive().toBoolean() || abs === '0' ? '' : '-'; - return sgn + abs; + return this.toBigint().toString(); } + isConstant() { return this.magnitude.value.isConstant() && this.sgn.isConstant(); }