Skip to content

Commit

Permalink
Merge pull request #1515 from o1-labs/feature/remove-deprecated-apis
Browse files Browse the repository at this point in the history
Remove all deprecated APIs
  • Loading branch information
mitschabaude authored Mar 26, 2024
2 parents a55491c + 5580994 commit 4767463
Show file tree
Hide file tree
Showing 59 changed files with 1,349 additions and 2,556 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Require the callback to `Mina.transaction()` to be async https://github.com/o1-labs/o1js/pull/1468
- Change `{SmartContract,ZkProgram}.analyzeMethods()` to be async https://github.com/o1-labs/o1js/pull/1450
- `Provable.runAndCheck()`, `Provable.constraintSystem()` and `{SmartContract,ZkProgram}.digest()` are also async now
- `Provable.runAndCheckSync()` added and immediately deprecated for a smoother upgrade path for tests
- **Remove deprecated APIs**
- Remove `CircuitValue`, `prop`, `arrayProp` and `matrixProp` https://github.com/o1-labs/o1js/pull/1507
- Remove `Mina.accountCreationFee()`, `Mina.BerkeleyQANet`, all APIs which accept private keys for feepayers, `Token`, `AccountUpdate.tokenSymbol`, `SmartContract.{token, setValue, setPermissions}`, "assert" methods for preconditions, `MerkleTee.calculateRootSlow()`, `Scalar.fromBigInt()`, `UInt64.lt()` and friends, deprecated static methods on `Group`, utility methods on `Circuit` like `Circuit.if()`, `Field.isZero()`, `isReady` and `shutdown()` https://github.com/o1-labs/o1js/pull/1515
- Remove `privateKey` from the accepted arguments of `SmartContract.deploy()` https://github.com/o1-labs/o1js/pull/1515
- Remove `this.sender` which unintuitively did not prove that its value was the actual sender of the transaction https://github.com/o1-labs/o1js/pull/1464 [@julio4](https://github.com/julio4)
Replaced by more explicit APIs:
- `this.sender.getUnconstrained()` which has the old behavior of `this.sender`, and returns an unconstrained value (which means that the prover can set it to any value they want)
Expand Down
10 changes: 1 addition & 9 deletions src/examples/circuit-string.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
isReady,
CircuitString,
SmartContract,
method,
Mina,
PrivateKey,
} from 'o1js';
import { CircuitString, SmartContract, method, Mina, PrivateKey } from 'o1js';
import * as assert from 'assert/strict';

// circuit which tests a couple of string features
Expand All @@ -19,7 +12,6 @@ class MyContract extends SmartContract {
}
}

await isReady;
let address = PrivateKey.random().toPublicKey();

console.log('compile...');
Expand Down
5 changes: 1 addition & 4 deletions src/examples/encoding-bijective.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Field, isReady, shutdown, Encoding } from 'o1js';
import { Field, Encoding } from 'o1js';

await isReady;
let n = 1000;

let { toBytes, fromBytes } = Encoding.Bijective.Fp;
Expand All @@ -21,8 +20,6 @@ let bytesEqual = arrayEqual([...bytes], [...newBytes]);
if (!bytesEqual) throw Error('roundtrip bytes -> fields -> bytes failed');
else console.log('bytes -> fields -> bytes: ok');

shutdown();

function arrayEqual<T>(a: T[], b: T[], isEqual?: (a: T, b: T) => boolean) {
if (isEqual === undefined) isEqual = (a, b) => a === b;
if (a.length !== b.length) return false;
Expand Down
11 changes: 1 addition & 10 deletions src/examples/encryption.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
Encryption,
Encoding,
PrivateKey,
isReady,
Circuit,
Provable,
} from 'o1js';

await isReady;
import { Encryption, Encoding, PrivateKey, Provable } from 'o1js';

// generate keys
let privateKey = PrivateKey.random();
Expand Down
5 changes: 0 additions & 5 deletions src/examples/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {
fetchAccount,
isReady,
setGraphqlEndpoints,
shutdown,
fetchLastBlock,
PublicKey,
Types,
} from 'o1js';

await isReady;
setGraphqlEndpoints([
'https://proxy.berkeley.minaexplorer.com/graphql',
'https://berkeley.minascan.io/graphql',
Expand All @@ -25,5 +22,3 @@ console.log('account', Types.Account.toJSON(account!));

let block = await fetchLastBlock();
console.log('last block', JSON.stringify(block, null, 2));

await shutdown();
5 changes: 1 addition & 4 deletions src/examples/internals/advanced-provable-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ console.log(`an account update has ${AccountUpdate.sizeInFields()} fields`);
let address = PrivateKey.random().toPublicKey();
let accountUpdate = AccountUpdate.defaultAccountUpdate(address);
accountUpdate.body.callDepth = 5;
accountUpdate.lazyAuthorization = {
kind: 'lazy-signature',
privateKey: PrivateKey.random(),
};
accountUpdate.lazyAuthorization = { kind: 'lazy-signature' };

/**
* Every provable type can be disassembled into its provable/in-circuit part (fields)
Expand Down
7 changes: 4 additions & 3 deletions src/examples/nullifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
MerkleMapWitness,
Mina,
AccountUpdate,
Provable,
} from 'o1js';

class PayoutOnlyOnce extends SmartContract {
Expand All @@ -24,7 +25,7 @@ class PayoutOnlyOnce extends SmartContract {
// verify the nullifier
nullifier.verify([nullifierMessage]);

let nullifierWitness = Circuit.witness(MerkleMapWitness, () =>
let nullifierWitness = Provable.witness(MerkleMapWitness, () =>
NullifierTree.getWitness(nullifier.key())
);

Expand Down Expand Up @@ -75,13 +76,13 @@ console.log('deploy');
let tx = await Mina.transaction(sender, async () => {
let senderUpdate = AccountUpdate.fundNewAccount(sender);
senderUpdate.send({ to: zkappAddress, amount: initialBalance });
await zkapp.deploy({ zkappKey });
await zkapp.deploy();

zkapp.nullifierRoot.set(NullifierTree.getRoot());
zkapp.nullifierMessage.set(nullifierMessage);
});
await tx.prove();
await tx.sign([senderKey]).send();
await tx.sign([senderKey, zkappKey]).send();

console.log(`zkapp balance: ${zkapp.account.balance.get().div(1e9)} MINA`);

Expand Down
6 changes: 0 additions & 6 deletions src/examples/simple-zkapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import {
SmartContract,
Mina,
AccountUpdate,
isReady,
declareState,
declareMethods,
shutdown,
} from 'o1js';

await isReady;

class SimpleZkapp extends SmartContract {
constructor(address) {
super(address);
Expand Down Expand Up @@ -72,5 +68,3 @@ tx = await Mina.transaction(feePayer, () => zkapp.update(Field(3)));
await tx.prove();
await tx.sign([feePayerKey]).send();
console.log('final state: ' + zkapp.x.get());

shutdown();
4 changes: 2 additions & 2 deletions src/examples/simple-zkapp.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ console.log('deploy');
let tx = await Mina.transaction(sender, async () => {
let senderUpdate = AccountUpdate.fundNewAccount(sender);
senderUpdate.send({ to: zkappAddress, amount: initialBalance });
await zkapp.deploy({ zkappKey });
await zkapp.deploy();
});
await tx.prove();
await tx.sign([senderKey]).send();
await tx.sign([senderKey, zkappKey]).send();

console.log('initial state: ' + zkapp.x.get());
console.log(`initial balance: ${zkapp.account.balance.get().div(1e9)} MINA`);
Expand Down
4 changes: 0 additions & 4 deletions src/examples/zkapps/local-events-zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ import {
state,
State,
method,
UInt64,
PrivateKey,
SmartContract,
Mina,
AccountUpdate,
isReady,
UInt32,
PublicKey,
Struct,
} from 'o1js';

const doProofs = false;

await isReady;

class Event extends Struct({ pub: PublicKey, value: Field }) {}

class SimpleZkapp extends SmartContract {
Expand Down
6 changes: 3 additions & 3 deletions src/examples/zkapps/reducer/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ map.set(key, value);
map.get(key);
// contract
zkApp.deploy(); // ... deploy the zkapp
zkApp.set(key, value); // ... set a key-value pair
zkApp.get(key); // ... get a value by key
await zkApp.deploy(); // ... deploy the zkapp
await zkApp.set(key, value); // ... set a key-value pair
await zkApp.get(key); // ... get a value by key
```
*/

Expand Down
4 changes: 2 additions & 2 deletions src/examples/zkapps/simple-zkapp-with-proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ let zkapp = new NotSoSimpleZkapp(zkappAddress);
console.log('deploy');
let tx = await Mina.transaction(feePayer, async () => {
AccountUpdate.fundNewAccount(feePayer);
await zkapp.deploy({ zkappKey });
await zkapp.deploy();
});
await tx.prove();
await tx.sign([feePayerKey]).send();
await tx.sign([feePayerKey, zkappKey]).send();

console.log('initialize');
tx = await Mina.transaction(feePayer, async () => {
Expand Down
18 changes: 4 additions & 14 deletions src/examples/zkapps/voting/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ let initialRoot = voterStore.getRoot();
tx = await Mina.transaction(feePayer, async () => {
AccountUpdate.fundNewAccount(feePayer, 3);

contracts.voting.deploy({ zkappKey: votingKey });
await contracts.voting.deploy();
contracts.voting.committedVotes.set(votesStore.getRoot());
contracts.voting.accumulatedVotes.set(Reducer.initialActionState);

contracts.candidateContract.deploy({ zkappKey: candidateKey });
await contracts.candidateContract.deploy();
contracts.candidateContract.committedMembers.set(candidateStore.getRoot());
contracts.candidateContract.accumulatedMembers.set(
Reducer.initialActionState
);

contracts.voterContract.deploy({ zkappKey: voterKey });
await contracts.voterContract.deploy();
contracts.voterContract.committedMembers.set(voterStore.getRoot());
contracts.voterContract.accumulatedMembers.set(Reducer.initialActionState);
});
await tx.sign([feePayerKey]).send();
await tx.sign([feePayerKey, votingKey, candidateKey, voterKey]).send();

let m: Member = Member.empty();
// lets register three voters
Expand All @@ -93,7 +93,6 @@ tx = await Mina.transaction(feePayer, async () => {
);

contracts.voting.voterRegistration(m);
if (!params.doProofs) contracts.voting.sign(votingKey);
});
await tx.prove();
await tx.sign([feePayerKey]).send();
Expand All @@ -113,8 +112,6 @@ tx = await Mina.transaction(feePayer, async () => {
);

contracts.voting.voterRegistration(m);

if (!params.doProofs) contracts.voting.sign(votingKey);
});
await tx.prove();
await tx.sign([feePayerKey]).send();
Expand All @@ -134,8 +131,6 @@ tx = await Mina.transaction(feePayer, async () => {
);

contracts.voting.voterRegistration(m);

if (!params.doProofs) contracts.voting.sign(votingKey);
});
await tx.prove();
await tx.sign([feePayerKey]).send();
Expand Down Expand Up @@ -169,7 +164,6 @@ tx = await Mina.transaction(feePayer, async () => {
);

contracts.voting.candidateRegistration(m);
if (!params.doProofs) contracts.voting.sign(votingKey);
});

await tx.prove();
Expand All @@ -189,7 +183,6 @@ tx = await Mina.transaction(feePayer, async () => {
);

contracts.voting.candidateRegistration(m);
if (!params.doProofs) contracts.voting.sign(votingKey);
});

await tx.prove();
Expand Down Expand Up @@ -232,7 +225,6 @@ console.log(

tx = await Mina.transaction(feePayer, async () => {
contracts.voting.approveRegistrations();
if (!params.doProofs) contracts.voting.sign(votingKey);
});

await tx.prove();
Expand Down Expand Up @@ -268,7 +260,6 @@ tx = await Mina.transaction(feePayer, async () => {
c.votesWitness = new MyMerkleWitness(votesStore.getWitness(0n));
// we are voting for candidate c, 0n, with voter 2n
contracts.voting.vote(c, voterStore.get(2n)!);
if (!params.doProofs) contracts.voting.sign(votingKey);
});

await tx.prove();
Expand All @@ -288,7 +279,6 @@ console.log(
*/
tx = await Mina.transaction(feePayer, async () => {
contracts.voting.countVotes();
if (!params.doProofs) contracts.voting.sign(votingKey);
});

await tx.prove();
Expand Down
24 changes: 14 additions & 10 deletions src/examples/zkapps/voting/deploy-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { Membership_ } from './membership.js';
import { Voting_ } from './voting.js';

class InvalidContract extends SmartContract {
async deploy(args: DeployArgs) {
await super.deploy(args);
async deploy() {
await super.deploy();
this.account.permissions.set({
...Permissions.default(),
editState: Permissions.none(),
Expand Down Expand Up @@ -66,19 +66,21 @@ export async function deployContracts(
let tx = await Mina.transaction(feePayer, async () => {
AccountUpdate.fundNewAccount(feePayer, 3);

await voting.deploy({ zkappKey: params.votingKey });
await voting.deploy();
voting.committedVotes.set(votesRoot);
voting.accumulatedVotes.set(Reducer.initialActionState);

await candidateContract.deploy({ zkappKey: params.candidateKey });
await candidateContract.deploy();
candidateContract.committedMembers.set(candidateRoot);
candidateContract.accumulatedMembers.set(Reducer.initialActionState);

await voterContract.deploy({ zkappKey: params.voterKey });
await voterContract.deploy();
voterContract.committedMembers.set(voterRoot);
voterContract.accumulatedMembers.set(Reducer.initialActionState);
});
await tx.sign([feePayerKey]).send();
await tx
.sign([feePayerKey, params.votingKey, params.candidateKey, params.voterKey])
.send();

console.log('successfully deployed contracts');
return {
Expand Down Expand Up @@ -130,7 +132,7 @@ export async function deployInvalidContracts(
let tx = await Mina.transaction(feePayer, async () => {
AccountUpdate.fundNewAccount(feePayer, 3);

await voting.deploy({ zkappKey: params.votingKey });
await voting.deploy();
voting.committedVotes.set(votesRoot);
voting.accumulatedVotes.set(Reducer.initialActionState);

Expand All @@ -140,19 +142,21 @@ export async function deployInvalidContracts(
params.candidateKey.toPublicKey()
);

await invalidCandidateContract.deploy({ zkappKey: params.candidateKey });
await invalidCandidateContract.deploy();

candidateContract = invalidCandidateContract as Membership_;

let invalidVoterContract = new InvalidContract(
params.voterKey.toPublicKey()
);

await invalidVoterContract.deploy({ zkappKey: params.voterKey });
await invalidVoterContract.deploy();

voterContract = invalidVoterContract as Membership_;
});
await tx.sign([feePayerKey]).send();
await tx
.sign([feePayerKey, params.votingKey, params.candidateKey, params.voterKey])
.send();

console.log('successfully deployed contracts');
return {
Expand Down
Loading

0 comments on commit 4767463

Please sign in to comment.