-
Notifications
You must be signed in to change notification settings - Fork 19
/
CircuitConfig.ts
115 lines (106 loc) · 3.17 KB
/
CircuitConfig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
EPOCH_BITS,
NONCE_BITS,
ATTESTER_ID_BITS,
CHAIN_ID_BITS,
REVEAL_NONCE_BITS,
SNARK_SCALAR_FIELD,
REP_BITS,
ONE_BIT,
} from '@unirep/utils'
const defaultConfig = {
STATE_TREE_DEPTH: 17,
EPOCH_TREE_DEPTH: 17,
HISTORY_TREE_DEPTH: 17,
NUM_EPOCH_KEY_NONCE_PER_EPOCH: 3,
FIELD_COUNT: 6, // total number of fields
SUM_FIELD_COUNT: 4, // number of fields combined using addition
REPL_NONCE_BITS: 48,
}
/**
* Use the default circuit config like so:
* @example
* ```ts
* import { CircuitConfig } from '@unirep/circuits'
*
* const {
* STATE_TREE_DEPTH,
* EPOCH_TREE_DEPTH,
* HISTORY_TREE_DEPTH,
* NUM_EPOCH_KEY_NONCE_PER_EPOCH,
* FIELD_COUNT,
* SUM_FIELD_COUNT,
* REPL_NONCE_BITS,
* SNARK_SCALAR_FIELD,
* EPOCH_BITS,
* NONCE_BITS,
* ATTESTER_ID_BITS,
* CHAIN_ID_BITS,
* REVEAL_NONCE_BITS,
* REP_BITS,
* ONE_BIT
* } = CircuitConfig.default
```
* :::info
* See current deployment config: [testnet-deployment](https://developer.unirep.io/docs/testnet-deployment)
* :::
*/
export class CircuitConfig {
STATE_TREE_DEPTH: number
EPOCH_TREE_DEPTH: number
HISTORY_TREE_DEPTH: number
NUM_EPOCH_KEY_NONCE_PER_EPOCH: number
FIELD_COUNT: number
SUM_FIELD_COUNT: number
REPL_NONCE_BITS: number
SNARK_SCALAR_FIELD: string
MAX_SAFE_BITS: bigint = BigInt(253)
EPOCH_BITS: bigint = EPOCH_BITS
NONCE_BITS: bigint = NONCE_BITS
ATTESTER_ID_BITS: bigint = ATTESTER_ID_BITS
CHAIN_ID_BITS: bigint = CHAIN_ID_BITS
REVEAL_NONCE_BITS: bigint = REVEAL_NONCE_BITS
REP_BITS: bigint = REP_BITS
ONE_BIT: bigint = ONE_BIT
static get default() {
return new CircuitConfig(defaultConfig)
}
get contractConfig() {
return {
stateTreeDepth: this.STATE_TREE_DEPTH,
epochTreeDepth: this.EPOCH_TREE_DEPTH,
historyTreeDepth: this.HISTORY_TREE_DEPTH,
numEpochKeyNoncePerEpoch: this.NUM_EPOCH_KEY_NONCE_PER_EPOCH,
fieldCount: this.FIELD_COUNT,
sumFieldCount: this.SUM_FIELD_COUNT,
replNonceBits: this.REPL_NONCE_BITS,
replFieldBits: this.REPL_FIELD_BITS,
}
}
get REPL_FIELD_BITS() {
return Number(this.MAX_SAFE_BITS) - this.REPL_NONCE_BITS
}
constructor(
_config: {
STATE_TREE_DEPTH?: number
EPOCH_TREE_DEPTH?: number
HISTORY_TREE_DEPTH?: number
NUM_EPOCH_KEY_NONCE_PER_EPOCH?: number
FIELD_COUNT?: number
SUM_FIELD_COUNT?: number
REPL_NONCE_BITS?: number
} = {}
) {
const config = { ...defaultConfig, ..._config }
this.STATE_TREE_DEPTH = config.STATE_TREE_DEPTH
this.EPOCH_TREE_DEPTH = config.EPOCH_TREE_DEPTH
this.HISTORY_TREE_DEPTH = config.HISTORY_TREE_DEPTH
this.NUM_EPOCH_KEY_NONCE_PER_EPOCH =
config.NUM_EPOCH_KEY_NONCE_PER_EPOCH
this.FIELD_COUNT = config.FIELD_COUNT
this.SUM_FIELD_COUNT = config.SUM_FIELD_COUNT
this.REPL_NONCE_BITS = config.REPL_NONCE_BITS
this.SNARK_SCALAR_FIELD = SNARK_SCALAR_FIELD
}
}
export default new CircuitConfig(defaultConfig)