Skip to content

Commit

Permalink
O1js 0.18.0 upgrade (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
45930 authored Apr 14, 2024
1 parent 0dbd6f9 commit bc62a68
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 226 deletions.
16 changes: 8 additions & 8 deletions examples/smart_contract/election/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Election extends SmartContract {
@state(Ballot) ballot3 = State<Ballot>();
@state(Ballot) ballot4 = State<Ballot>();

init() {
async init() {
super.init();
this.ballot1.set(Ballot.fromBigInts([0n, 0n, 0n, 0n, 0n, 0n, 0n]));
this.ballot2.set(Ballot.fromBigInts([0n, 0n, 0n, 0n, 0n, 0n, 0n]));
Expand All @@ -18,9 +18,9 @@ export class Election extends SmartContract {
}

@method
castBallot1(vote: Ballot) {
async castBallot1(vote: Ballot) {
const unpackedVote = Ballot.unpack(vote.packed);
const ballot1 = this.ballot1.getAndAssertEquals();
const ballot1 = this.ballot1.getAndRequireEquals();
const unpackedBallot1 = Ballot.unpack(ballot1.packed);

let voteSum = UInt32.from(0);
Expand All @@ -33,9 +33,9 @@ export class Election extends SmartContract {
}

@method
castBallot2(vote: Ballot) {
async castBallot2(vote: Ballot) {
const unpackedVote = Ballot.unpack(vote.packed);
const ballot2 = this.ballot2.getAndAssertEquals();
const ballot2 = this.ballot2.getAndRequireEquals();
const unpackedBallot2 = Ballot.unpack(ballot2.packed);

let voteSum = UInt32.from(0);
Expand All @@ -50,7 +50,7 @@ export class Election extends SmartContract {
@method
castBallot3(vote: Ballot) {
const unpackedVote = Ballot.unpack(vote.packed);
const ballot3 = this.ballot3.getAndAssertEquals();
const ballot3 = this.ballot3.getAndRequireEquals();
const unpackedBallot3 = Ballot.unpack(ballot3.packed);

let voteSum = UInt32.from(0);
Expand All @@ -63,9 +63,9 @@ export class Election extends SmartContract {
}

@method
castBallot4(vote: Ballot) {
async castBallot4(vote: Ballot) {
const unpackedVote = Ballot.unpack(vote.packed);
const ballot4 = this.ballot4.getAndAssertEquals();
const ballot4 = this.ballot4.getAndRequireEquals();
const unpackedBallot4 = Ballot.unpack(ballot4.packed);

let voteSum = UInt32.from(0);
Expand Down
7 changes: 0 additions & 7 deletions examples/smart_contract/tokenState/README.md

This file was deleted.

62 changes: 0 additions & 62 deletions examples/smart_contract/tokenState/contract.ts

This file was deleted.

71 changes: 0 additions & 71 deletions examples/smart_contract/tokenState/run.ts

This file was deleted.

13 changes: 6 additions & 7 deletions examples/zk_program/age_gate/circuit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {
Field,
Experimental,
ZkProgram,
UInt32,
Provable,
Poseidon,
SelfProof,
Character,
Bool,
Empty,
} from 'o1js';
Expand Down Expand Up @@ -34,19 +32,20 @@ const isOlderThan = (reference: PackedString, toVerify: PackedString): Bool => {
return ver.greaterThan(ref);
};

export const AgeGateCircuit = Experimental.ZkProgram({
export const AgeGateCircuit = ZkProgram({
name: 'AgeGateCircuit',
publicOutput: PackedCounters,

methods: {
init: {
privateInputs: [],
method() {
async method() {
return PackedCounters.fromBigInts([0n, 0n]);
},
},
verifyAge: {
privateInputs: [SelfProof, PackedString],
method(
async method(
oldProof: SelfProof<Empty, PackedCounters>,
dateToVerify: PackedString
) {
Expand All @@ -72,4 +71,4 @@ export const AgeGateCircuit = Experimental.ZkProgram({
},
});

export const AgeGateCircuitProof = Experimental.ZkProgram.Proof(AgeGateCircuit);
export const AgeGateCircuitProof = ZkProgram.Proof(AgeGateCircuit);
28 changes: 6 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"typescript": "^4.7.2"
},
"peerDependencies": {
"o1js": "^0.16.2"
"o1js": "^0.18.0"
}
}
10 changes: 1 addition & 9 deletions src/lib/PackingPlant.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Field,
Struct,
Poseidon,
provable,
InferProvable,
Provable,
ProvableExtended,
} from 'o1js';
import { Field, Struct, provable, InferProvable, Provable } from 'o1js';

const MAX_BITS_PER_FIELD = 254n;

Expand Down
18 changes: 11 additions & 7 deletions src/lib/packed-types/PackedBool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ describe('PackedBool', () => {
packedBool.assertEquals(outsidePackedBool);
});
}).not.toThrow();
expect(() => {
Provable.runAndCheck(() => {
const fakePacked = outsidePackedBool.packed.add(32);
const packedBool = new PackedBool(fakePacked);
packedBool.assertEquals(outsidePackedBool);
});
}).toThrow();

// TODO: This test should not be in the "provable" block since it's not in the runAndCheck
// It seems like failures in the runAndCheck can't be tested for with #toThrow
try {
const fakePacked = outsidePackedBool.packed.add(32);
const packedBool = new PackedBool(fakePacked);
packedBool.assertEquals(outsidePackedBool);
fail('Expected to throw Field.assertEquals error');
} catch (e: any) {
expect(e.message).toContain('Field.assertEquals');
}
});
});
});
20 changes: 11 additions & 9 deletions src/lib/packed-types/PackedString.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ describe('PackedString', () => {
});
}).not.toThrow();

expect(() => {
Provable.runAndCheck(() => {
const fakePacked = [...outsideEthAddress.packed];
fakePacked[0] = fakePacked[0].add(1);
const myEthAddress = new EthAddressString(fakePacked);

myEthAddress.assertEquals(outsideEthAddress);
});
}).toThrow();
// TODO: This test should not be in the "provable" block since it's not in the runAndCheck
// It seems like failures in the runAndCheck can't be tested for with #toThrow
try {
const fakePacked = [...outsideEthAddress.packed];
fakePacked[0] = fakePacked[0].add(1);
const myEthAddress = new EthAddressString(fakePacked);
myEthAddress.assertEquals(outsideEthAddress);
fail('Expected to throw Field.assertEquals error');
} catch (e: any) {
expect(e.message).toContain('Field.assertEquals');
}
});
});
});
Loading

0 comments on commit bc62a68

Please sign in to comment.