Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes static one/zero/-1 from Field #524

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/examples/api_exploration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ console.assert(x0.equals(x1).toBoolean());

// When initializing with booleans, true corresponds to the field element 1, and false corresponds to 0
const b = new Field(true);
console.assert(b.equals(Field.one).toBoolean());
console.assert(b.equals(Field(1)).toBoolean());

/* You can perform arithmetic operations on field elements.
The arithmetic methods can take any "fieldy" values as inputs:
Expand Down
8 changes: 4 additions & 4 deletions src/examples/constraint_system.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Field, Circuit, Poseidon } from 'snarkyjs';

let hash = Poseidon.hash([Field.one, Field.minusOne]);
let hash = Poseidon.hash([Field(1), Field(-1)]);

let { rows, digest } = Circuit.constraintSystem(() => {
let x = Circuit.witness(Field, () => Field.one);
let y = Circuit.witness(Field, () => Field.minusOne);
x.add(y).assertEquals(Field.zero);
let x = Circuit.witness(Field, () => Field(1));
let y = Circuit.witness(Field, () => Field(-1));
x.add(y).assertEquals(Field(0));
let z = Poseidon.hash([x, y]);
z.assertEquals(hash);
});
Expand Down
2 changes: 1 addition & 1 deletion src/examples/ex00_preimage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ await isReady;
console.log('generating keypair...');
const kp = Main.generateKeypair();

const preimage = Field.one;
const preimage = Field(1);
const hash = Poseidon.hash([preimage]);

console.log('prove...');
Expand Down
2 changes: 1 addition & 1 deletion src/examples/matrix_mul.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function matrixMul(x: Field[][], y: Field[][]): Field[][] {
for (let i = 0; i < n; i++) {
result[i] = [];
for (let j = 0; j < o; j++) {
result[i][j] = Field.zero;
result[i][j] = Field(0);
for (let k = 0; k < m; k++) {
result[i][j] = result[i][j].add(x[i][k].mul(y[k][j]));
}
Expand Down
6 changes: 3 additions & 3 deletions src/examples/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let MyProgram = Experimental.ZkProgram({
privateInputs: [],

method(publicInput: Field) {
publicInput.assertEquals(Field.zero);
publicInput.assertEquals(Field(0));
},
},

Expand All @@ -32,15 +32,15 @@ let { verificationKey } = await MyProgram.compile();
console.log('verification key', verificationKey.slice(0, 10) + '..');

console.log('proving base case...');
let proof = await MyProgram.baseCase(Field.zero);
let proof = await MyProgram.baseCase(Field(0));
proof = testJsonRoundtrip(proof);

console.log('verify...');
let ok = await verify(proof.toJSON(), verificationKey);
console.log('ok?', ok);

console.log('proving step 1...');
proof = await MyProgram.inductiveCase(Field.one, proof);
proof = await MyProgram.inductiveCase(Field(1), proof);
proof = testJsonRoundtrip(proof);

console.log('verify alternative...');
Expand Down
2 changes: 1 addition & 1 deletion src/examples/rollup/data_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Keyed {
const n = eltTyp.sizeInFields();
const xs = [];
for (var i = 0; i < n; ++i) {
xs.push(Field.zero);
xs.push(Field(0));
}
return eltTyp.fromFields(xs);
})();
Expand Down
2 changes: 1 addition & 1 deletion src/examples/rollup/merkle_stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class MerkleStack<A extends CircuitValue> {
this.values = { computed: false, f };
this.eltTyp = eltTyp;
// TODO
this.commitment = Field.zero;
this.commitment = Field(0);
}

getValues(): Array<[A, Field]> {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/dex/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TrivialCoin extends SmartContract implements Erc20 {
for (let i = 0; i < 8; i++) {
let state = this.self.update.appState[i];
state.isSome = Bool(true);
state.value = Field.zero;
state.value = Field(0);
}
// since this is the only method of this zkApp that resets the entire state, provedState: true implies
// that this function was run. Since it can be run only once, this implies it was run exactly once
Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/merkle_tree/merkle_zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Account extends CircuitValue {
}
}
// we need the initiate tree root in order to tell the contract about our off-chain storage
let initialCommitment: Field = Field.zero;
let initialCommitment: Field = Field(0);
/*
We want to write a smart contract that serves as a leaderboard,
but only has the commitment of the off-chain storage stored in an on-chain variable.
Expand Down
4 changes: 2 additions & 2 deletions src/examples/zkapps/reducer/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

await isReady;

const INCREMENT = Field.one;
const INCREMENT = Field(1);

class CounterZkapp extends SmartContract {
// the "reducer" field describes a type of action that we can dispatch, and reduce later
Expand Down Expand Up @@ -61,7 +61,7 @@ class CounterZkapp extends SmartContract {
}

const doProofs = true;
const initialCounter = Field.zero;
const initialCounter = Field(0);

let Local = Mina.LocalBlockchain();
Mina.setActiveInstance(Local);
Expand Down
4 changes: 2 additions & 2 deletions src/examples/zkapps/reducer/reducer_composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MaybeIncrement extends Struct({
isIncrement: Bool,
otherData: Field,
}) {}
const INCREMENT = { isIncrement: Bool(true), otherData: Field.zero };
const INCREMENT = { isIncrement: Bool(true), otherData: Field(0) };

class CounterZkapp extends SmartContract {
// the "reducer" field describes a type of action that we can dispatch, and reduce later
Expand Down Expand Up @@ -72,7 +72,7 @@ class CounterZkapp extends SmartContract {
}

const doProofs = true;
const initialCounter = Field.zero;
const initialCounter = Field(0);

let Local = Mina.LocalBlockchain();
Mina.setActiveInstance(Local);
Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/simple_and_counter_zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const doProofs = true;

await isReady;

const INCREMENT = Field.one;
const INCREMENT = Field(1);

let offchainStorage = {
pendingActions: [] as Field[][],
Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/simple_zkapp_with_proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NotSoSimpleZkapp extends SmartContract {

@method init(proof: TrivialProof) {
proof.verify();
this.x.set(Field.one);
this.x.set(Field(1));
}

@method update(
Expand Down
10 changes: 5 additions & 5 deletions src/examples/zkapps/voting/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ try {
0n,
Member.from(
PrivateKey.random().toPublicKey(),
Field.zero,
Field(0),
UInt64.from(150)
),
voterStore
Expand All @@ -127,7 +127,7 @@ try {
1n,
Member.from(
PrivateKey.random().toPublicKey(),
Field.zero,
Field(0),
UInt64.from(160)
),
voterStore
Expand All @@ -152,7 +152,7 @@ try {
2n,
Member.from(
PrivateKey.random().toPublicKey(),
Field.zero,
Field(0),
UInt64.from(170)
),
voterStore
Expand Down Expand Up @@ -191,7 +191,7 @@ try {
0n,
Member.from(
PrivateKey.random().toPublicKey(),
Field.zero,
Field(0),
UInt64.from(250)
),
candidateStore
Expand All @@ -215,7 +215,7 @@ try {
1n,
Member.from(
PrivateKey.random().toPublicKey(),
Field.zero,
Field(0),
UInt64.from(400)
),
candidateStore
Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/voting/dummyContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class DummyContract extends SmartContract {
setVerificationKey: Permissions.proofOrSignature(),
incrementNonce: Permissions.proofOrSignature(),
});
this.sum.set(Field.zero);
this.sum.set(Field(0));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/examples/zkapps/voting/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
export class MerkleWitness extends Experimental.MerkleWitness(8) {}
let w = {
isLeft: false,
sibling: Field.zero,
sibling: Field(0),
};
let dummyWitness = Array.from(Array(MerkleWitness.height - 1).keys()).map(
() => w
Expand Down Expand Up @@ -50,7 +50,7 @@ export class Member extends CircuitValue {
this.hashVoted = Bool(false);
this.accountId = accountId;
this.isCandidate = Bool(false);
this.votes = Field.zero;
this.votes = Field(0);

this.witness = new MerkleWitness(dummyWitness);
this.votesWitness = new MerkleWitness(dummyWitness);
Expand All @@ -75,7 +75,7 @@ export class Member extends CircuitValue {
}

static empty() {
return new Member(PublicKey.empty(), Field.zero, UInt64.zero, Field.zero);
return new Member(PublicKey.empty(), Field(0), UInt64.zero, Field(0));
}

static from(publicKey: PublicKey, tokenId: Field, balance: UInt64) {
Expand Down
Loading