From cc0ff8212a5a0db721d5e3f24cc2000870473cba Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 12 Feb 2025 16:40:24 +0100 Subject: [PATCH] fix lint --- src/examples/zkapps/hashing/run.ts | 5 +- src/lib/provable/int.ts | 111 ++++++----------------------- 2 files changed, 24 insertions(+), 92 deletions(-) diff --git a/src/examples/zkapps/hashing/run.ts b/src/examples/zkapps/hashing/run.ts index 963ca19c66..0bdb848b9b 100644 --- a/src/examples/zkapps/hashing/run.ts +++ b/src/examples/zkapps/hashing/run.ts @@ -1,5 +1,5 @@ import { HashStorage } from './hash.js'; -import { Mina, PrivateKey, AccountUpdate, Bytes } from 'o1js'; +import { Mina, AccountUpdate, Bytes } from 'o1js'; let txn; let proofsEnabled = true; @@ -29,8 +29,7 @@ txn = await Mina.transaction(feePayer, async () => { }); await txn.sign([feePayer.key, contractAccount.key]).send(); -const initialState = - Mina.getAccount(contractAccount).zkapp?.appState?.[0].toString(); +const initialState = Mina.getAccount(contractAccount).zkapp?.appState?.[0].toString(); let currentState; console.log('Initial State', initialState); diff --git a/src/lib/provable/int.ts b/src/lib/provable/int.ts index db2f549e39..8546d32d4b 100644 --- a/src/lib/provable/int.ts +++ b/src/lib/provable/int.ts @@ -7,7 +7,6 @@ import { Provable } from './provable.js'; import * as RangeCheck from './gadgets/range-check.js'; import * as Bitwise from './gadgets/bitwise.js'; import { addMod32, addMod64 } from './gadgets/arithmetic.js'; -import type { Gadgets } from './gadgets/gadgets.js'; import { withMessage } from './field.js'; import { FieldVar } from './core/fieldvar.js'; import { CircuitValue, prop } from './types/circuit-value.js'; @@ -101,11 +100,7 @@ class UInt64 extends CircuitValue { */ toUInt32Clamped() { let max = (1n << 32n) - 1n; - let field = Provable.if( - this.greaterThan(UInt64.from(max)), - Field.from(max), - this.value - ); + let field = Provable.if(this.greaterThan(UInt64.from(max)), Field.from(max), this.value); return UInt32.Unsafe.fromField(field); } @@ -135,9 +130,7 @@ class UInt64 extends CircuitValue { if (!x.isConstant()) return x; let xBig = x.toBigInt(); if (xBig < 0n || xBig >= 1n << BigInt(this.NUM_BITS)) { - throw Error( - `UInt64: Expected number between 0 and 2^64 - 1, got ${xBig}` - ); + throw Error(`UInt64: Expected number between 0 and 2^64 - 1, got ${xBig}`); } return x; } @@ -186,10 +179,7 @@ class UInt64 extends CircuitValue { y_ = y_.seal(); - let q = Provable.witness( - Field, - () => new Field(x.toBigInt() / y_.toBigInt()) - ); + let q = Provable.witness(Field, () => new Field(x.toBigInt() / y_.toBigInt())); RangeCheck.rangeCheckN(UInt64.NUM_BITS, q); @@ -445,10 +435,7 @@ class UInt64 extends CircuitValue { assertLessThanOrEqual(y: UInt64, message?: string) { if (this.value.isConstant() && y.value.isConstant()) { let [x0, y0] = [this.value.toBigInt(), y.value.toBigInt()]; - return assert( - x0 <= y0, - message ?? `UInt64.assertLessThanOrEqual: expected ${x0} <= ${y0}` - ); + return assert(x0 <= y0, message ?? `UInt64.assertLessThanOrEqual: expected ${x0} <= ${y0}`); } assertLessThanOrEqualGeneric(this.value, y.value, (v) => RangeCheck.rangeCheckN(UInt64.NUM_BITS, v, message) @@ -474,10 +461,7 @@ class UInt64 extends CircuitValue { assertLessThan(y: UInt64, message?: string) { if (this.value.isConstant() && y.value.isConstant()) { let [x0, y0] = [this.value.toBigInt(), y.value.toBigInt()]; - return assert( - x0 < y0, - message ?? `UInt64.assertLessThan: expected ${x0} < ${y0}` - ); + return assert(x0 < y0, message ?? `UInt64.assertLessThan: expected ${x0} < ${y0}`); } assertLessThanGeneric(this.value, y.value, (v) => RangeCheck.rangeCheckN(UInt64.NUM_BITS, v, message) @@ -516,9 +500,7 @@ class UInt64 extends CircuitValue { return x.value.toBigInt(); } - static fromValue( - x: number | bigint | UInt64 - ): InstanceType { + static fromValue(x: number | bigint | UInt64): InstanceType { return UInt64.from(x) as any; } @@ -634,9 +616,7 @@ class UInt32 extends CircuitValue { if (!x.isConstant()) return x; let xBig = x.toBigInt(); if (xBig < 0n || xBig >= 1n << BigInt(this.NUM_BITS)) { - throw Error( - `UInt32: Expected number between 0 and 2^32 - 1, got ${xBig}` - ); + throw Error(`UInt32: Expected number between 0 and 2^32 - 1, got ${xBig}`); } return x; } @@ -686,10 +666,7 @@ class UInt32 extends CircuitValue { y_ = y_.seal(); - let q = Provable.witness( - Field, - () => new Field(x.toBigInt() / y_.toBigInt()) - ); + let q = Provable.witness(Field, () => new Field(x.toBigInt() / y_.toBigInt())); RangeCheck.rangeCheck32(q); @@ -943,10 +920,7 @@ class UInt32 extends CircuitValue { assertLessThanOrEqual(y: UInt32, message?: string) { if (this.value.isConstant() && y.value.isConstant()) { let [x0, y0] = [this.value.toBigInt(), y.value.toBigInt()]; - return assert( - x0 <= y0, - message ?? `UInt32.assertLessThanOrEqual: expected ${x0} <= ${y0}` - ); + return assert(x0 <= y0, message ?? `UInt32.assertLessThanOrEqual: expected ${x0} <= ${y0}`); } assertLessThanOrEqualGeneric(this.value, y.value, (v) => RangeCheck.rangeCheckN(UInt32.NUM_BITS, v, message) @@ -971,10 +945,7 @@ class UInt32 extends CircuitValue { assertLessThan(y: UInt32, message?: string) { if (this.value.isConstant() && y.value.isConstant()) { let [x0, y0] = [this.value.toBigInt(), y.value.toBigInt()]; - return assert( - x0 < y0, - message ?? `UInt32.assertLessThan: expected ${x0} < ${y0}` - ); + return assert(x0 < y0, message ?? `UInt32.assertLessThan: expected ${x0} < ${y0}`); } assertLessThanGeneric(this.value, y.value, (v) => RangeCheck.rangeCheckN(UInt32.NUM_BITS, v, message) @@ -1013,9 +984,7 @@ class UInt32 extends CircuitValue { return x.value.toBigInt(); } - static fromValue( - x: number | bigint | UInt32 - ): InstanceType { + static fromValue(x: number | bigint | UInt32): InstanceType { return UInt32.from(x) as any; } @@ -1073,9 +1042,7 @@ class Sign extends CircuitValue { if (x.neg().toString() === '1') return 'Negative'; throw Error(`Invalid Sign: ${x}`); } - static fromJSON( - x: 'Positive' | 'Negative' - ): InstanceType { + static fromJSON(x: 'Positive' | 'Negative'): InstanceType { return (x === 'Positive' ? new Sign(Field(1)) : new Sign(Field(-1))) as any; } neg() { @@ -1099,9 +1066,7 @@ class Sign extends CircuitValue { return x.value.toBigInt() as TypesBigint.Sign; } - static fromValue( - x: number | bigint | Sign - ): InstanceType { + static fromValue(x: number | bigint | Sign): InstanceType { if (x instanceof Sign) return x as any; return new Sign(Field(x)) as any; } @@ -1228,10 +1193,7 @@ class Int64 extends CircuitValue implements BalanceChange { }, }; - fromObject(obj: { - magnitude: UInt64 | number | string | bigint; - sgn: Sign | bigint; - }) { + fromObject(obj: { magnitude: UInt64 | number | string | bigint; sgn: Sign | bigint }) { return Int64.create(UInt64.from(obj.magnitude), Sign.fromValue(obj.sgn)); } @@ -1389,11 +1351,7 @@ class Int64 extends CircuitValue implements BalanceChange { let y_ = UInt64.from(y); let rest = this.magnitude.divMod(y_).rest.value; let isNonNegative = this.isNonNegative(); - rest = Provable.if( - isNonNegative.or(rest.equals(0)), - 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)); } @@ -1407,10 +1365,7 @@ class Int64 extends CircuitValue implements BalanceChange { /** * Asserts that two values are equal. */ - assertEquals( - y: Int64 | number | string | bigint | UInt64 | UInt32, - message?: string - ) { + assertEquals(y: Int64 | number | string | bigint | UInt64 | UInt32, message?: string) { let y_ = Int64.from(y); this.toField().assertEquals(y_.toField(), message); } @@ -1452,9 +1407,7 @@ class Int64 extends CircuitValue implements BalanceChange { // check unique representation of 0: we can't have magnitude = 0 and sgn = -1 // magnitude + sign != -1 (this check works because magnitude >= 0) - magnitude.value - .add(sgn.value) - .assertNotEquals(-1, 'Int64: 0 must have positive sign'); + magnitude.value.add(sgn.value).assertNotEquals(-1, 'Int64: 0 must have positive sign'); } } @@ -1637,12 +1590,7 @@ class UInt8 extends Struct({ if (this.value.isConstant() && y_.value.isConstant()) { return Bool(this.toBigInt() <= y_.toBigInt()); } - return lessThanOrEqualGeneric( - this.value, - y_.value, - 1n << 8n, - RangeCheck.rangeCheck8 - ); + return lessThanOrEqualGeneric(this.value, y_.value, 1n << 8n, RangeCheck.rangeCheck8); } /** @@ -1659,12 +1607,7 @@ class UInt8 extends Struct({ if (this.value.isConstant() && y_.value.isConstant()) { return Bool(this.toBigInt() < y_.toBigInt()); } - return lessThanGeneric( - this.value, - y_.value, - 1n << 8n, - RangeCheck.rangeCheck8 - ); + return lessThanGeneric(this.value, y_.value, 1n << 8n, RangeCheck.rangeCheck8); } /** @@ -1679,10 +1622,7 @@ class UInt8 extends Struct({ let y_ = UInt8.from(y); if (this.value.isConstant() && y_.value.isConstant()) { let [x0, y0] = [this.value.toBigInt(), y_.value.toBigInt()]; - return assert( - x0 < y0, - message ?? `UInt8.assertLessThan: expected ${x0} < ${y0}` - ); + return assert(x0 < y0, message ?? `UInt8.assertLessThan: expected ${x0} < ${y0}`); } try { // 2^16 < p - 2^8, so we satisfy the assumption of `assertLessThanGeneric` @@ -1704,18 +1644,11 @@ class UInt8 extends Struct({ let y_ = UInt8.from(y); if (this.value.isConstant() && y_.value.isConstant()) { let [x0, y0] = [this.value.toBigInt(), y_.value.toBigInt()]; - return assert( - x0 <= y0, - message ?? `UInt8.assertLessThanOrEqual: expected ${x0} <= ${y0}` - ); + return assert(x0 <= y0, message ?? `UInt8.assertLessThanOrEqual: expected ${x0} <= ${y0}`); } try { // 2^16 < p - 2^8, so we satisfy the assumption of `assertLessThanOrEqualGeneric` - assertLessThanOrEqualGeneric( - this.value, - y_.value, - RangeCheck.rangeCheck16 - ); + assertLessThanOrEqualGeneric(this.value, y_.value, RangeCheck.rangeCheck16); } catch (err) { throw withMessage(err, message); }