-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathprivate_kernel.ts
More file actions
174 lines (163 loc) · 5.04 KB
/
private_kernel.ts
File metadata and controls
174 lines (163 loc) · 5.04 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { Fr } from '@aztec/foundation/fields';
import { Tuple } from '@aztec/foundation/serialize';
import {
CONTRACT_TREE_HEIGHT,
FUNCTION_TREE_HEIGHT,
MAX_NEW_NULLIFIERS_PER_TX,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,
MAX_READ_REQUESTS_PER_CALL,
MAX_READ_REQUESTS_PER_TX,
} from '../../cbind/constants.gen.js';
import { FieldsOf } from '../../utils/jsUtils.js';
import { serializeToBuffer } from '../../utils/serialize.js';
import { PrivateCallStackItem } from '../call_stack_item.js';
import { MembershipWitness } from '../membership_witness.js';
import { Proof } from '../proof.js';
import { ReadRequestMembershipWitness } from '../read_request_membership_witness.js';
import { TxRequest } from '../tx_request.js';
import { VerificationKey } from '../verification_key.js';
import { PreviousKernelData } from './previous_kernel_data.js';
/**
* Private call data.
* @see circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp
*/
export class PrivateCallData {
constructor(
/**
* The call stack item currently being processed.
*/
public callStackItem: PrivateCallStackItem,
/**
* Other private call stack items to be processed.
*/
public privateCallStackPreimages: Tuple<PrivateCallStackItem, typeof MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL>,
/**
* The proof of the execution of this private call.
*/
public proof: Proof,
/**
* The verification key for the function being invoked.
*/
public vk: VerificationKey,
/**
* The membership witness for the function leaf corresponding to the function being invoked.
*/
public functionLeafMembershipWitness: MembershipWitness<typeof FUNCTION_TREE_HEIGHT>,
/**
* The membership witness for the contract leaf corresponding to the contract on which the function is being
* invoked.
*/
public contractLeafMembershipWitness: MembershipWitness<typeof CONTRACT_TREE_HEIGHT>,
/**
* The membership witnesses for read requests created by the function being invoked.
*/
public readRequestMembershipWitnesses: Tuple<ReadRequestMembershipWitness, typeof MAX_READ_REQUESTS_PER_CALL>,
/**
* The address of the portal contract corresponding to the contract on which the function is being invoked.
*/
public portalContractAddress: Fr,
/**
* The hash of the ACIR of the function being invoked.
*/
public acirHash: Fr,
) {}
/**
* Serialize into a field array. Low-level utility.
* @param fields - Object with fields.
* @returns The array.
*/
static getFields(fields: FieldsOf<PrivateCallData>) {
return [
// NOTE: Must have same order as CPP.
fields.callStackItem,
fields.privateCallStackPreimages,
fields.proof,
fields.vk,
fields.functionLeafMembershipWitness,
fields.contractLeafMembershipWitness,
fields.readRequestMembershipWitnesses,
fields.portalContractAddress,
fields.acirHash,
] as const;
}
static from(fields: FieldsOf<PrivateCallData>): PrivateCallData {
return new PrivateCallData(...PrivateCallData.getFields(fields));
}
/**
* Serialize this as a buffer.
* @returns The buffer.
*/
toBuffer(): Buffer {
return serializeToBuffer(...PrivateCallData.getFields(this));
}
}
/**
* Input to the private kernel circuit - initial call.
*/
export class PrivateKernelInputsInit {
constructor(
/**
* The transaction request which led to the creation of these inputs.
*/
public txRequest: TxRequest,
/**
* Private calldata corresponding to this iteration of the kernel.
*/
public privateCall: PrivateCallData,
) {}
/**
* Serialize this as a buffer.
* @returns The buffer.
*/
toBuffer() {
return serializeToBuffer(this.txRequest, this.privateCall);
}
}
/**
* Input to the private kernel circuit - Inner call.
*/
export class PrivateKernelInputsInner {
constructor(
/**
* The previous kernel data (dummy if this is the first kernel).
*/
public previousKernel: PreviousKernelData,
/**
* Private calldata corresponding to this iteration of the kernel.
*/
public privateCall: PrivateCallData,
) {}
/**
* Serialize this as a buffer.
* @returns The buffer.
*/
toBuffer() {
return serializeToBuffer(this.previousKernel, this.privateCall);
}
}
/**
* Input to the private kernel circuit - Final ordering call.
*/
export class PrivateKernelInputsOrdering {
constructor(
/**
* The previous kernel data
*/
public previousKernel: PreviousKernelData,
/**
* Contains hints for the transient read requests to localize corresponding commitments.
*/
public readCommitmentHints: Tuple<Fr, typeof MAX_READ_REQUESTS_PER_TX>,
/**
* Contains hints for the transient nullifiers to localize corresponding commitments.
*/
public nullifierCommitmentHints: Tuple<Fr, typeof MAX_NEW_NULLIFIERS_PER_TX>,
) {}
/**
* Serialize this as a buffer.
* @returns The buffer.
*/
toBuffer() {
return serializeToBuffer(this.previousKernel, this.readCommitmentHints);
}
}