Skip to content

Commit 1b927ae

Browse files
committed
fix constants
1 parent c7c7154 commit 1b927ae

File tree

5 files changed

+107
-104
lines changed

5 files changed

+107
-104
lines changed

src/lib/mina/v1/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export namespace TransactionLimits {
1010
}
1111

1212
export namespace ZkappConstants {
13-
export const MAX_ZKAPP_STATE_FIELDS = 8 as const;
13+
export const MAX_ZKAPP_STATE_FIELDS = 32 as const;
1414
export const ACCOUNT_ACTION_STATE_BUFFER_SIZE = 5 as const;
1515
export const ACCOUNT_CREATION_FEE = 1000000000n as const;
1616
}

src/lib/mina/v1/mina-instance.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
/**
22
* This module holds the global Mina instance and its interface.
33
*/
4-
import { Field } from '../../provable/wrapped.js';
5-
import { UInt64, UInt32 } from '../../provable/int.js';
4+
import type { NetworkId } from '../../../mina-signer/src/types.js';
65
import { PublicKey } from '../../provable/crypto/signature.js';
6+
import { UInt32, UInt64 } from '../../provable/int.js';
7+
import { Field } from '../../provable/wrapped.js';
78
import type { EventActionFilterOptions } from '././../../mina/v1/graphql.js';
8-
import type { NetworkId } from '../../../mina-signer/src/types.js';
99
import type { Account } from './account.js';
10-
import type { NetworkValue } from './precondition.js';
10+
import { ZkappConstants } from './constants.js';
1111
import type * as Fetch from './fetch.js';
12-
import type { TransactionPromise, PendingTransactionPromise, Transaction } from './transaction.js';
12+
import type { NetworkValue } from './precondition.js';
13+
import type { PendingTransactionPromise, Transaction, TransactionPromise } from './transaction.js';
1314

1415
export {
15-
Mina,
16-
FeePayerSpec,
1716
ActionStates,
17+
FeePayerSpec,
18+
Mina,
1819
NetworkConstants,
19-
defaultNetworkConstants,
20-
activeInstance,
21-
setActiveInstance,
2220
ZkappStateLength,
21+
activeInstance,
2322
currentSlot,
23+
defaultNetworkConstants,
24+
fetchActions,
25+
fetchEvents,
2426
getAccount,
25-
hasAccount,
27+
getActions,
2628
getBalance,
27-
getNetworkId,
2829
getNetworkConstants,
30+
getNetworkId,
2931
getNetworkState,
30-
fetchEvents,
31-
fetchActions,
32-
getActions,
3332
getProofsEnabled,
33+
hasAccount,
34+
setActiveInstance,
3435
};
3536

3637
const defaultAccountCreationFee = 1_000_000_000;
@@ -40,7 +41,7 @@ const defaultNetworkConstants: NetworkConstants = {
4041
accountCreationFee: UInt64.from(defaultAccountCreationFee),
4142
};
4243

43-
const ZkappStateLength = 8;
44+
const ZkappStateLength = ZkappConstants.MAX_ZKAPP_STATE_FIELDS;
4445

4546
/**
4647
* Allows you to specify information about the fee payer account and the transaction.

src/lib/mina/v1/state.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { FlexibleProvablePure } from '../../provable/types/struct.js';
2-
import { AccountUpdate, TokenId } from './account-update.js';
31
import { PublicKey } from '../../provable/crypto/signature.js';
4-
import * as Mina from './mina.js';
5-
import { fetchAccount, networkConfig } from './fetch.js';
6-
import { SmartContract } from './zkapp.js';
7-
import { Account } from './account.js';
82
import { Provable } from '../../provable/provable.js';
9-
import { Field } from '../../provable/wrapped.js';
103
import {
114
ProvablePure,
125
ProvableType,
136
ProvableTypePure,
147
} from '../../provable/types/provable-intf.js';
8+
import { FlexibleProvablePure } from '../../provable/types/struct.js';
9+
import { Bool, Field } from '../../provable/wrapped.js';
10+
import { AccountUpdate, TokenId } from './account-update.js';
11+
import { Account } from './account.js';
12+
import { ZkappConstants } from './constants.js';
13+
import { fetchAccount, networkConfig } from './fetch.js';
14+
import * as Mina from './mina.js';
1515
import { ensureConsistentPrecondition } from './precondition.js';
16-
import { Bool } from '../../provable/wrapped.js';
16+
import { SmartContract } from './zkapp.js';
1717

1818
// external API
19-
export { State, state, declareState };
19+
export { State, declareState, state };
2020
// internal API
21-
export { assertStatePrecondition, cleanStatePrecondition, getLayout, InternalStateType };
21+
export { InternalStateType, assertStatePrecondition, cleanStatePrecondition, getLayout };
2222

2323
/**
2424
* Gettable and settable state that can be checked for equality.
@@ -399,9 +399,9 @@ function getLayout(scClass: typeof SmartContract) {
399399
layout.set(key, { offset, length });
400400
offset += length;
401401
});
402-
if (offset > 8) {
402+
if (offset > ZkappConstants.MAX_ZKAPP_STATE_FIELDS) {
403403
throw Error(
404-
`Found ${offset} on-chain state field elements on ${scClass.name}. Currently, only a total of 8 field elements of state are supported.`
404+
`Found ${offset} on-chain state field elements on ${scClass.name}. Currently, only a total of 32 field elements of state are supported.`
405405
);
406406
}
407407
}

src/lib/mina/v1/zkapp.ts

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
11
import 'reflect-metadata';
22
import { Gate, Pickles } from '../../../bindings.js';
3-
import { Field, Bool } from '../../provable/wrapped.js';
4-
import {
5-
AccountUpdate,
6-
Authorization,
7-
Body,
8-
Events,
9-
Permissions,
10-
TokenId,
11-
ZkappCommand,
12-
zkAppProver,
13-
ZkappPublicInput,
14-
LazyProof,
15-
AccountUpdateForest,
16-
AccountUpdateLayout,
17-
AccountUpdateTree,
18-
} from './account-update.js';
19-
import type { EventActionFilterOptions } from './graphql.js';
20-
import {
21-
cloneCircuitValue,
22-
FlexibleProvablePure,
23-
InferProvable,
24-
} from '../../provable/types/struct.js';
25-
import { Provable, getBlindingValue, memoizationContext } from '../../provable/provable.js';
263
import * as Encoding from '../../../bindings/lib/encoding.js';
4+
import { Cache } from '../../proof-system/cache.js';
5+
import { Proof, ProofClass } from '../../proof-system/proof.js';
6+
import { VerificationKey } from '../../proof-system/verification-key.js';
277
import {
28-
HashInput,
29-
Poseidon,
30-
hashConstant,
31-
isHashable,
32-
packToFields,
33-
} from '../../provable/crypto/poseidon.js';
34-
import { UInt32, UInt64 } from '../../provable/int.js';
35-
import * as Mina from './mina.js';
36-
import { assertPreconditionInvariants, cleanPreconditionsCache } from './precondition.js';
37-
import {
8+
Empty,
9+
MethodInterface,
3810
analyzeMethod,
3911
compileProgram,
4012
computeMaxProofsVerified,
41-
Empty,
42-
MethodInterface,
4313
sortMethodArguments,
4414
} from '../../proof-system/zkprogram.js';
45-
import { VerificationKey } from '../../proof-system/verification-key.js';
46-
import { Proof, ProofClass } from '../../proof-system/proof.js';
47-
import { PublicKey } from '../../provable/crypto/signature.js';
48-
import {
49-
InternalStateType,
50-
assertStatePrecondition,
51-
cleanStatePrecondition,
52-
getLayout,
53-
} from './state.js';
5415
import {
5516
inAnalyze,
5617
inCheckedComputation,
5718
inCompile,
5819
inProver,
5920
} from '../../provable/core/provable-context.js';
60-
import { Cache } from '../../proof-system/cache.js';
21+
import {
22+
HashInput,
23+
Poseidon,
24+
hashConstant,
25+
isHashable,
26+
packToFields,
27+
} from '../../provable/crypto/poseidon.js';
28+
import { PublicKey } from '../../provable/crypto/signature.js';
6129
import { assert } from '../../provable/gadgets/common.js';
62-
import { SmartContractBase } from './smart-contract-base.js';
30+
import { UInt32, UInt64 } from '../../provable/int.js';
31+
import { Provable, getBlindingValue, memoizationContext } from '../../provable/provable.js';
32+
import { provable } from '../../provable/types/provable-derivers.js';
33+
import { ProvablePure, ProvableType } from '../../provable/types/provable-intf.js';
34+
import {
35+
FlexibleProvablePure,
36+
InferProvable,
37+
cloneCircuitValue,
38+
} from '../../provable/types/struct.js';
39+
import { Bool, Field } from '../../provable/wrapped.js';
40+
import { assertPromise } from '../../util/assert.js';
41+
import {
42+
AccountUpdate,
43+
AccountUpdateForest,
44+
AccountUpdateLayout,
45+
AccountUpdateTree,
46+
Authorization,
47+
Body,
48+
Events,
49+
LazyProof,
50+
Permissions,
51+
TokenId,
52+
ZkappCommand,
53+
ZkappPublicInput,
54+
zkAppProver,
55+
} from './account-update.js';
56+
import { Reducer, getReducer } from './actions/reducer.js';
57+
import type { EventActionFilterOptions } from './graphql.js';
6358
import { ZkappStateLength } from './mina-instance.js';
59+
import * as Mina from './mina.js';
60+
import { assertPreconditionInvariants, cleanPreconditionsCache } from './precondition.js';
61+
import { SmartContractBase } from './smart-contract-base.js';
6462
import {
6563
SmartContractContext,
6664
accountUpdateLayout,
6765
smartContractContext,
6866
} from './smart-contract-context.js';
69-
import { assertPromise } from '../../util/assert.js';
70-
import { ProvablePure, ProvableType } from '../../provable/types/provable-intf.js';
71-
import { getReducer, Reducer } from './actions/reducer.js';
72-
import { provable } from '../../provable/types/provable-derivers.js';
67+
import {
68+
InternalStateType,
69+
assertStatePrecondition,
70+
cleanStatePrecondition,
71+
getLayout,
72+
} from './state.js';
7373

7474
// external API
75-
export { SmartContract, method, DeployArgs, declareMethods };
75+
export { DeployArgs, SmartContract, declareMethods, method };
7676

7777
const reservedPropNames = new Set(['_methods', '_']);
7878
type AsyncFunction = (...args: any) => Promise<any>;

src/lib/mina/v2/account-update.unit-test.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
import { AccountUpdate, Authorized, GenericData } from './account-update.js';
2-
import { AccountId, AccountTiming } from './account.js';
3-
import { AccountUpdateAuthorizationKind } from './authorization.js';
4-
import { TokenId, Update } from './core.js';
5-
import { Precondition } from './preconditions.js';
6-
import { GenericStatePreconditions, GenericStateUpdates } from './state.js';
7-
import { AccountUpdate as V1AccountUpdateImpl } from '../v1/account-update.js';
8-
import { VerificationKey } from '../../proof-system/verification-key.js';
9-
import { Bool } from '../../provable/bool.js';
10-
import { Field } from '../../provable/field.js';
11-
import { UInt32, UInt64, Int64, Sign } from '../../provable/int.js';
12-
import { PrivateKey } from '../../provable/crypto/signature.js';
1+
import { expect } from 'expect';
2+
import { jsLayout as layoutV1 } from '../../../bindings/mina-transaction/gen/v1/js-layout.js';
3+
import * as ValuesV1 from '../../../bindings/mina-transaction/gen/v1/transaction-bigint.js';
4+
import * as JsonV1 from '../../../bindings/mina-transaction/gen/v1/transaction-json.js';
5+
import * as TypesV1 from '../../../bindings/mina-transaction/gen/v1/transaction.js';
136
import {
147
Actions as V1Actions,
158
Events as V1Events,
169
Sign as V1Sign,
1710
TokenSymbol as V1TokenSymbol,
1811
ZkappUri as V1ZkappUri,
1912
} from '../../../bindings/mina-transaction/v1/transaction-leaves.js';
20-
import * as TypesV1 from '../../../bindings/mina-transaction/gen/v1/transaction.js';
21-
import * as ValuesV1 from '../../../bindings/mina-transaction/gen/v1/transaction-bigint.js';
22-
import * as JsonV1 from '../../../bindings/mina-transaction/gen/v1/transaction-json.js';
23-
import { jsLayout as layoutV1 } from '../../../bindings/mina-transaction/gen/v1/js-layout.js';
24-
import { expect } from 'expect';
13+
import { VerificationKey } from '../../proof-system/verification-key.js';
14+
import { Bool } from '../../provable/bool.js';
15+
import { PrivateKey } from '../../provable/crypto/signature.js';
16+
import { Field } from '../../provable/field.js';
17+
import { Int64, Sign, UInt32, UInt64 } from '../../provable/int.js';
18+
import { AccountUpdate as V1AccountUpdateImpl } from '../v1/account-update.js';
19+
import { AccountUpdate, Authorized, GenericData } from './account-update.js';
20+
import { AccountId, AccountTiming } from './account.js';
21+
import { AccountUpdateAuthorizationKind } from './authorization.js';
22+
import { TokenId, Update } from './core.js';
23+
import { Precondition } from './preconditions.js';
24+
import { GenericStatePreconditions, GenericStateUpdates } from './state.js';
2525

26+
import {
27+
Signature,
28+
signFieldElement,
29+
zkAppBodyPrefix,
30+
} from '../../../mina-signer/src/signature.js';
2631
import { ZkappConstants } from '../v1/constants.js';
2732
import {
2833
testV1V2ClassEquivalence,
2934
testV1V2ValueEquivalence,
3035
testV2Encoding,
3136
} from './test/utils.js';
32-
import {
33-
Signature,
34-
signFieldElement,
35-
zkAppBodyPrefix,
36-
} from '../../../mina-signer/src/signature.js';
3737

3838
import { Types } from '../../../bindings/mina-transaction/v1/types.js';
39-
import { packToFields, hashWithPrefix } from '../../../lib/provable/crypto/poseidon.js';
39+
import { hashWithPrefix, packToFields } from '../../../lib/provable/crypto/poseidon.js';
4040

4141
function testHashEquality(v1: TypesV1.AccountUpdate, v2: Authorized) {
4242
expect(TypesV1.AccountUpdate.toInput(v1)).toEqual(v2.toInput());
@@ -401,7 +401,9 @@ const v2AccountUpdate: Authorized = new Authorized(
401401
pushEvents: events,
402402
pushActions: actions,
403403
setState: new GenericStateUpdates(
404-
new Array(ZkappConstants.MAX_ZKAPP_STATE_FIELDS).fill(Update.set(new Field(8)))
404+
new Array(ZkappConstants.MAX_ZKAPP_STATE_FIELDS).fill(
405+
Update.set(new Field(ZkappConstants.MAX_ZKAPP_STATE_FIELDS))
406+
)
405407
),
406408
setDelegate: publicKey,
407409
setVerificationKey: verificationKey,

0 commit comments

Comments
 (0)