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

add txnVersion to verification key permission #1208

Merged
merged 9 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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/bindings
94 changes: 47 additions & 47 deletions src/examples/regression_test.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/examples/zkapps/dex/upgradability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Permissions,
PrivateKey,
UInt64,
TransactionVersion,
} from 'snarkyjs';
import { createDex, TokenContract, addresses, keys, tokenIds } from './dex.js';
import { expect } from 'expect';
Expand Down Expand Up @@ -427,7 +428,10 @@ async function upgradeabilityTests({ withVesting }: { withVesting: boolean }) {
let update = AccountUpdate.createSigned(addresses.dex);
update.account.permissions.set({
...Permissions.initial(),
setVerificationKey: Permissions.impossible(),
setVerificationKey: {
auth: Permissions.impossible(),
txnVersion: TransactionVersion.current(),
},
});
});
await tx.prove();
Expand Down
6 changes: 5 additions & 1 deletion src/examples/zkapps/voting/dummyContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
method,
DeployArgs,
Permissions,
TransactionVersion,
} from 'snarkyjs';

export class DummyContract extends SmartContract {
Expand All @@ -18,7 +19,10 @@ export class DummyContract extends SmartContract {
editState: Permissions.proofOrSignature(),
editActionState: Permissions.proofOrSignature(),
setPermissions: Permissions.proofOrSignature(),
setVerificationKey: Permissions.proofOrSignature(),
setVerificationKey: {
auth: Permissions.signature(),
txnVersion: TransactionVersion.current(),
},
incrementNonce: Permissions.proofOrSignature(),
});
this.sum.set(Field(0));
Expand Down
6 changes: 5 additions & 1 deletion src/examples/zkapps/voting/membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
provablePure,
AccountUpdate,
Provable,
TransactionVersion,
} from 'snarkyjs';
import { Member } from './member.js';
import { ParticipantPreconditions } from './preconditions.js';
Expand Down Expand Up @@ -74,7 +75,10 @@ export class Membership_ extends SmartContract {
editState: Permissions.proofOrSignature(),
editActionState: Permissions.proofOrSignature(),
setPermissions: Permissions.proofOrSignature(),
setVerificationKey: Permissions.proofOrSignature(),
setVerificationKey: {
auth: Permissions.proofOrSignature(),
txnVersion: TransactionVersion.current(),
},
incrementNonce: Permissions.proofOrSignature(),
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/examples/zkapps/voting/voting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
provablePure,
AccountUpdate,
Provable,
TransactionVersion,
} from 'snarkyjs';

import { Member } from './member.js';
Expand Down Expand Up @@ -103,7 +104,10 @@ export class Voting_ extends SmartContract {
editState: Permissions.proofOrSignature(),
editActionState: Permissions.proofOrSignature(),
incrementNonce: Permissions.proofOrSignature(),
setVerificationKey: Permissions.none(),
setVerificationKey: {
auth: Permissions.none(),
txnVersion: TransactionVersion.current(),
},
setPermissions: Permissions.proofOrSignature(),
});
this.accumulatedVotes.set(Reducer.initialActionState);
Expand Down
7 changes: 6 additions & 1 deletion src/examples/zkapps/zkapp-self-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ import {
AccountUpdate,
Circuit,
Provable,
TransactionVersion,
UInt32,
} from 'snarkyjs';

class Foo extends SmartContract {
init() {
super.init();
this.account.permissions.set({
...Permissions.default(),
setVerificationKey: Permissions.proof(),
setVerificationKey: {
auth: Permissions.proof(),
txnVersion: TransactionVersion.current(),
},
});
}

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export {
AccountUpdate,
Permissions,
ZkappPublicInput,
TransactionVersion,
} from './lib/account_update.js';

export type { TransactionStatus } from './lib/fetch.js';
Expand Down
40 changes: 32 additions & 8 deletions src/lib/account_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import {
} from '../bindings/mina-transaction/transaction-leaves.js';
import { TokenId as Base58TokenId } from './base58-encodings.js';
import { hashWithPrefix, packToFields } from './hash.js';
import { mocks, prefixes } from '../bindings/crypto/constants.js';
import {
mocks,
prefixes,
protocolVersions,
} from '../bindings/crypto/constants.js';
import { Context } from './global-context.js';
import { assert } from './errors.js';
import { MlArray } from './ml/base.js';
Expand All @@ -35,7 +39,7 @@ import { MlFieldConstArray } from './ml/fields.js';
import { transactionCommitments } from '../mina-signer/src/sign-zkapp-command.js';

// external API
export { AccountUpdate, Permissions, ZkappPublicInput };
export { AccountUpdate, Permissions, ZkappPublicInput, TransactionVersion };
// internal API
export {
smartContractContext,
Expand Down Expand Up @@ -63,6 +67,10 @@ export {

const ZkappStateLength = 8;

const TransactionVersion = {
current: () => UInt32.from(protocolVersions.txnVersion),
};

type SmartContractContext = {
this: SmartContract;
methodCallDepth: number;
Expand Down Expand Up @@ -199,7 +207,10 @@ interface Permissions extends Permissions_ {
* key associated with the circuit tied to this account. Effectively
* "upgradeability" of the smart contract.
*/
setVerificationKey: Permission;
setVerificationKey: {
auth: Permission;
txnVersion: UInt32;
};

/**
* The {@link Permission} corresponding to the ability to set the zkapp uri
Expand Down Expand Up @@ -265,7 +276,10 @@ let Permissions = {
receive: Permission.none(),
setDelegate: Permission.signature(),
setPermissions: Permission.signature(),
setVerificationKey: Permission.signature(),
setVerificationKey: {
auth: Permission.signature(),
txnVersion: TransactionVersion.current(),
},
setZkappUri: Permission.signature(),
editActionState: Permission.proof(),
setTokenSymbol: Permission.signature(),
Expand All @@ -281,7 +295,10 @@ let Permissions = {
receive: Permission.none(),
setDelegate: Permission.signature(),
setPermissions: Permission.signature(),
setVerificationKey: Permission.signature(),
setVerificationKey: {
auth: Permission.signature(),
txnVersion: TransactionVersion.current(),
},
setZkappUri: Permission.signature(),
editActionState: Permission.signature(),
setTokenSymbol: Permission.signature(),
Expand All @@ -298,7 +315,10 @@ let Permissions = {
access: Permission.none(),
setDelegate: Permission.none(),
setPermissions: Permission.none(),
setVerificationKey: Permission.none(),
setVerificationKey: {
auth: Permission.signature(),
txnVersion: TransactionVersion.current(),
},
setZkappUri: Permission.none(),
editActionState: Permission.none(),
setTokenSymbol: Permission.none(),
Expand All @@ -314,7 +334,10 @@ let Permissions = {
access: Permission.impossible(),
setDelegate: Permission.impossible(),
setPermissions: Permission.impossible(),
setVerificationKey: Permission.impossible(),
setVerificationKey: {
auth: Permission.signature(),
txnVersion: TransactionVersion.current(),
},
setZkappUri: Permission.impossible(),
editActionState: Permission.impossible(),
setTokenSymbol: Permission.impossible(),
Expand Down Expand Up @@ -350,7 +373,7 @@ let Permissions = {
return Object.fromEntries(
Object.entries(permissions).map(([k, v]) => [
k,
Permissions.fromString(v),
Permissions.fromString(typeof v === 'string' ? v : v.auth),
])
) as unknown as Permissions;
},
Expand Down Expand Up @@ -695,6 +718,7 @@ class AccountUpdate implements Types.AccountUpdate {
this,
isSelf
);

this.account = account;
this.network = network;
this.currentSlot = currentSlot;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ async function verifyAccountUpdate(
case 'delegate':
return perm.setDelegate;
case 'verificationKey':
return perm.setVerificationKey;
return perm.setVerificationKey.auth;
case 'permissions':
return perm.setPermissions;
case 'zkappUri':
Expand Down
5 changes: 4 additions & 1 deletion src/lib/mina/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ type FetchedAccount = {
receive: AuthRequired;
setDelegate: AuthRequired;
setPermissions: AuthRequired;
setVerificationKey: AuthRequired;
setVerificationKey: {
auth: AuthRequired;
txnVersion: string;
};
setZkappUri: AuthRequired;
editActionState: AuthRequired;
setTokenSymbol: AuthRequired;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/testing/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const Generators: Generators = {
null: constant(null),
string: base58(nat(50)), // TODO replace various strings, like signature, with parsed types
number: nat(3),
TransactionVersion: uint32,
};
let typeToBigintGenerator = new Map<Provable<any>, Random<any>>(
[TypeMap, PrimitiveMap, customTypes]
Expand Down Expand Up @@ -238,6 +239,7 @@ const JsonGenerators: JsonGenerators = {
null: constant(null),
string: base58(nat(50)),
number: nat(3),
TransactionVersion: json_.uint32,
};
let typeToJsonGenerator = new Map<Provable<any>, Random<any>>(
[TypeMap, PrimitiveMap, customTypes]
Expand Down
5 changes: 4 additions & 1 deletion src/mina-signer/src/test-vectors/accountUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ let accountUpdateExample: Json.AccountUpdate = {
receive: 'Proof',
setDelegate: 'Signature',
setPermissions: 'None',
setVerificationKey: 'None',
setVerificationKey: {
auth: 'None',
txnVersion: '3',
},
setZkappUri: 'Signature',
editActionState: 'Proof',
setTokenSymbol: 'Signature',
Expand Down
Loading