@aztec/sequencer-client 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +84 -7
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +4 -3
- package/dest/index.d.ts +0 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/sequencer/sequencer.d.ts +6 -7
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +10 -11
- package/dest/tx_validator/aggregate_tx_validator.d.ts +7 -0
- package/dest/tx_validator/aggregate_tx_validator.d.ts.map +1 -0
- package/dest/tx_validator/aggregate_tx_validator.js +23 -0
- package/dest/tx_validator/double_spend_validator.d.ts +11 -0
- package/dest/tx_validator/double_spend_validator.d.ts.map +1 -0
- package/dest/tx_validator/double_spend_validator.js +50 -0
- package/dest/tx_validator/gas_validator.d.ts +12 -0
- package/dest/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/tx_validator/gas_validator.js +62 -0
- package/dest/tx_validator/metadata_validator.d.ts +8 -0
- package/dest/tx_validator/metadata_validator.d.ts.map +1 -0
- package/dest/tx_validator/metadata_validator.js +50 -0
- package/dest/tx_validator/phases_validator.d.ts +13 -0
- package/dest/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/tx_validator/phases_validator.js +73 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +13 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +21 -0
- package/package.json +14 -13
- package/src/client/sequencer-client.ts +2 -3
- package/src/config.ts +93 -7
- package/src/global_variable_builder/global_builder.ts +3 -2
- package/src/index.ts +0 -1
- package/src/sequencer/sequencer.ts +27 -20
- package/src/tx_validator/aggregate_tx_validator.ts +24 -0
- package/src/tx_validator/double_spend_validator.ts +65 -0
- package/src/tx_validator/gas_validator.ts +81 -0
- package/src/tx_validator/metadata_validator.ts +60 -0
- package/src/tx_validator/phases_validator.ts +101 -0
- package/src/tx_validator/tx_validator_factory.ts +37 -0
- package/dest/sequencer/abstract_phase_manager.d.ts +0 -77
- package/dest/sequencer/abstract_phase_manager.d.ts.map +0 -1
- package/dest/sequencer/abstract_phase_manager.js +0 -307
- package/dest/sequencer/app_logic_phase_manager.d.ts +0 -28
- package/dest/sequencer/app_logic_phase_manager.d.ts.map +0 -1
- package/dest/sequencer/app_logic_phase_manager.js +0 -41
- package/dest/sequencer/hints_builder.d.ts +0 -23
- package/dest/sequencer/hints_builder.d.ts.map +0 -1
- package/dest/sequencer/hints_builder.js +0 -62
- package/dest/sequencer/phase_manager_factory.d.ts +0 -18
- package/dest/sequencer/phase_manager_factory.d.ts.map +0 -1
- package/dest/sequencer/phase_manager_factory.js +0 -56
- package/dest/sequencer/public_processor.d.ts +0 -54
- package/dest/sequencer/public_processor.d.ts.map +0 -1
- package/dest/sequencer/public_processor.js +0 -142
- package/dest/sequencer/setup_phase_manager.d.ts +0 -28
- package/dest/sequencer/setup_phase_manager.d.ts.map +0 -1
- package/dest/sequencer/setup_phase_manager.js +0 -30
- package/dest/sequencer/tail_phase_manager.d.ts +0 -29
- package/dest/sequencer/tail_phase_manager.d.ts.map +0 -1
- package/dest/sequencer/tail_phase_manager.js +0 -52
- package/dest/sequencer/teardown_phase_manager.d.ts +0 -28
- package/dest/sequencer/teardown_phase_manager.d.ts.map +0 -1
- package/dest/sequencer/teardown_phase_manager.js +0 -30
- package/dest/sequencer/tx_validator.d.ts +0 -29
- package/dest/sequencer/tx_validator.d.ts.map +0 -1
- package/dest/sequencer/tx_validator.js +0 -174
- package/dest/sequencer/tx_validator_factory.d.ts +0 -12
- package/dest/sequencer/tx_validator_factory.d.ts.map +0 -1
- package/dest/sequencer/tx_validator_factory.js +0 -17
- package/dest/sequencer/utils.d.ts +0 -8
- package/dest/sequencer/utils.d.ts.map +0 -1
- package/dest/sequencer/utils.js +0 -29
- package/dest/simulator/index.d.ts +0 -31
- package/dest/simulator/index.d.ts.map +0 -1
- package/dest/simulator/index.js +0 -2
- package/dest/simulator/public_executor.d.ts +0 -79
- package/dest/simulator/public_executor.d.ts.map +0 -1
- package/dest/simulator/public_executor.js +0 -198
- package/dest/simulator/public_kernel.d.ts +0 -37
- package/dest/simulator/public_kernel.d.ts.map +0 -1
- package/dest/simulator/public_kernel.js +0 -97
- package/src/sequencer/abstract_phase_manager.ts +0 -549
- package/src/sequencer/app_logic_phase_manager.ts +0 -62
- package/src/sequencer/hints_builder.ts +0 -119
- package/src/sequencer/phase_manager_factory.ts +0 -126
- package/src/sequencer/public_processor.ts +0 -209
- package/src/sequencer/setup_phase_manager.ts +0 -50
- package/src/sequencer/tail_phase_manager.ts +0 -111
- package/src/sequencer/teardown_phase_manager.ts +0 -50
- package/src/sequencer/tx_validator.ts +0 -265
- package/src/sequencer/tx_validator_factory.ts +0 -32
- package/src/sequencer/utils.ts +0 -31
- package/src/simulator/index.ts +0 -36
- package/src/simulator/public_executor.ts +0 -267
- package/src/simulator/public_kernel.ts +0 -139
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { MerkleTreeId } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
type Fr,
|
|
4
|
-
MAX_NEW_NULLIFIERS_PER_TX,
|
|
5
|
-
type MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX,
|
|
6
|
-
type MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
7
|
-
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
8
|
-
MembershipWitness,
|
|
9
|
-
NULLIFIER_TREE_HEIGHT,
|
|
10
|
-
PUBLIC_DATA_TREE_HEIGHT,
|
|
11
|
-
type PublicDataRead,
|
|
12
|
-
PublicDataTreeLeafPreimage,
|
|
13
|
-
type ReadRequestContext,
|
|
14
|
-
type SideEffectLinkedToNoteHash,
|
|
15
|
-
buildNullifierNonExistentReadRequestHints,
|
|
16
|
-
buildNullifierReadRequestHints,
|
|
17
|
-
mergeAccumulatedData,
|
|
18
|
-
} from '@aztec/circuits.js';
|
|
19
|
-
import { makeTuple } from '@aztec/foundation/array';
|
|
20
|
-
import { type Tuple } from '@aztec/foundation/serialize';
|
|
21
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
22
|
-
|
|
23
|
-
export class HintsBuilder {
|
|
24
|
-
constructor(private db: MerkleTreeOperations) {}
|
|
25
|
-
|
|
26
|
-
getNullifierReadRequestHints(
|
|
27
|
-
nullifierReadRequests: Tuple<ReadRequestContext, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
|
|
28
|
-
nullifiersNonRevertible: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX>,
|
|
29
|
-
nullifiersRevertible: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX>,
|
|
30
|
-
) {
|
|
31
|
-
return buildNullifierReadRequestHints(
|
|
32
|
-
this,
|
|
33
|
-
nullifierReadRequests,
|
|
34
|
-
mergeAccumulatedData(MAX_NEW_NULLIFIERS_PER_TX, nullifiersNonRevertible, nullifiersRevertible),
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getNullifierNonExistentReadRequestHints(
|
|
39
|
-
nullifierNonExistentReadRequests: Tuple<ReadRequestContext, typeof MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX>,
|
|
40
|
-
nullifiersNonRevertible: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX>,
|
|
41
|
-
nullifiersRevertible: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX>,
|
|
42
|
-
) {
|
|
43
|
-
const pendingNullifiers = mergeAccumulatedData(
|
|
44
|
-
MAX_NEW_NULLIFIERS_PER_TX,
|
|
45
|
-
nullifiersNonRevertible,
|
|
46
|
-
nullifiersRevertible,
|
|
47
|
-
);
|
|
48
|
-
return buildNullifierNonExistentReadRequestHints(this, nullifierNonExistentReadRequests, pendingNullifiers);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async getNullifierMembershipWitness(nullifier: Fr) {
|
|
52
|
-
const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
|
|
53
|
-
if (index === undefined) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return this.getNullifierMembershipWitnessWithPreimage(index);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async getLowNullifierMembershipWitness(nullifier: Fr) {
|
|
61
|
-
const res = await this.db.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
62
|
-
if (res === undefined) {
|
|
63
|
-
throw new Error(`Cannot find the low leaf for nullifier ${nullifier.toBigInt()}.`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const { index, alreadyPresent } = res;
|
|
67
|
-
if (alreadyPresent) {
|
|
68
|
-
throw new Error(`Nullifier ${nullifier.toBigInt()} already exists in the tree.`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return this.getNullifierMembershipWitnessWithPreimage(index);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private async getNullifierMembershipWitnessWithPreimage(index: bigint) {
|
|
75
|
-
const siblingPath = await this.db.getSiblingPath<typeof NULLIFIER_TREE_HEIGHT>(MerkleTreeId.NULLIFIER_TREE, index);
|
|
76
|
-
const membershipWitness = new MembershipWitness(
|
|
77
|
-
NULLIFIER_TREE_HEIGHT,
|
|
78
|
-
index,
|
|
79
|
-
siblingPath.toTuple<typeof NULLIFIER_TREE_HEIGHT>(),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const leafPreimage = await this.db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
83
|
-
if (!leafPreimage) {
|
|
84
|
-
throw new Error(`Cannot find the leaf preimage at index ${index}.`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return { membershipWitness, leafPreimage };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async getPublicDataReadsInfo(publicDataReads: PublicDataRead[]) {
|
|
91
|
-
const newPublicDataReadsWitnesses: Tuple<
|
|
92
|
-
MembershipWitness<typeof PUBLIC_DATA_TREE_HEIGHT>,
|
|
93
|
-
typeof MAX_PUBLIC_DATA_READS_PER_TX
|
|
94
|
-
> = makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => MembershipWitness.empty(PUBLIC_DATA_TREE_HEIGHT, 0n));
|
|
95
|
-
|
|
96
|
-
const newPublicDataReadsPreimages: Tuple<PublicDataTreeLeafPreimage, typeof MAX_PUBLIC_DATA_READS_PER_TX> =
|
|
97
|
-
makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => PublicDataTreeLeafPreimage.empty());
|
|
98
|
-
|
|
99
|
-
for (const i in publicDataReads) {
|
|
100
|
-
const leafSlot = publicDataReads[i].leafSlot.value;
|
|
101
|
-
const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
102
|
-
if (!lowLeafResult) {
|
|
103
|
-
throw new Error(`Public data tree should have one initial leaf`);
|
|
104
|
-
}
|
|
105
|
-
const preimage = await this.db.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
106
|
-
const path = await this.db.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
107
|
-
newPublicDataReadsWitnesses[i] = new MembershipWitness(
|
|
108
|
-
PUBLIC_DATA_TREE_HEIGHT,
|
|
109
|
-
BigInt(lowLeafResult.index),
|
|
110
|
-
path.toTuple<typeof PUBLIC_DATA_TREE_HEIGHT>(),
|
|
111
|
-
);
|
|
112
|
-
newPublicDataReadsPreimages[i] = preimage! as PublicDataTreeLeafPreimage;
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
newPublicDataReadsWitnesses,
|
|
116
|
-
newPublicDataReadsPreimages,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { type Tx } from '@aztec/circuit-types';
|
|
2
|
-
import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
3
|
-
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
4
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
5
|
-
|
|
6
|
-
import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
7
|
-
import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
8
|
-
import { type AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
9
|
-
import { AppLogicPhaseManager } from './app_logic_phase_manager.js';
|
|
10
|
-
import { SetupPhaseManager } from './setup_phase_manager.js';
|
|
11
|
-
import { TailPhaseManager } from './tail_phase_manager.js';
|
|
12
|
-
import { TeardownPhaseManager } from './teardown_phase_manager.js';
|
|
13
|
-
|
|
14
|
-
export class PhaseDidNotChangeError extends Error {
|
|
15
|
-
constructor(phase: PublicKernelPhase) {
|
|
16
|
-
super(`Tried to advance the phase from [${phase}] when the circuit still needs [${phase}]`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class CannotTransitionToSetupError extends Error {
|
|
21
|
-
constructor() {
|
|
22
|
-
super('Cannot transition to setup phase');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class PhaseManagerFactory {
|
|
27
|
-
public static phaseFromTx(
|
|
28
|
-
tx: Tx,
|
|
29
|
-
db: MerkleTreeOperations,
|
|
30
|
-
publicExecutor: PublicExecutor,
|
|
31
|
-
publicKernel: PublicKernelCircuitSimulator,
|
|
32
|
-
globalVariables: GlobalVariables,
|
|
33
|
-
historicalHeader: Header,
|
|
34
|
-
publicContractsDB: ContractsDataSourcePublicDB,
|
|
35
|
-
publicStateDB: PublicStateDB,
|
|
36
|
-
): AbstractPhaseManager | undefined {
|
|
37
|
-
const data = tx.data.forPublic!;
|
|
38
|
-
if (data.needsSetup) {
|
|
39
|
-
return new SetupPhaseManager(
|
|
40
|
-
db,
|
|
41
|
-
publicExecutor,
|
|
42
|
-
publicKernel,
|
|
43
|
-
globalVariables,
|
|
44
|
-
historicalHeader,
|
|
45
|
-
publicContractsDB,
|
|
46
|
-
publicStateDB,
|
|
47
|
-
);
|
|
48
|
-
} else if (data.needsAppLogic) {
|
|
49
|
-
return new AppLogicPhaseManager(
|
|
50
|
-
db,
|
|
51
|
-
publicExecutor,
|
|
52
|
-
publicKernel,
|
|
53
|
-
globalVariables,
|
|
54
|
-
historicalHeader,
|
|
55
|
-
publicContractsDB,
|
|
56
|
-
publicStateDB,
|
|
57
|
-
);
|
|
58
|
-
} else if (data.needsTeardown) {
|
|
59
|
-
return new TeardownPhaseManager(
|
|
60
|
-
db,
|
|
61
|
-
publicExecutor,
|
|
62
|
-
publicKernel,
|
|
63
|
-
globalVariables,
|
|
64
|
-
historicalHeader,
|
|
65
|
-
publicContractsDB,
|
|
66
|
-
publicStateDB,
|
|
67
|
-
);
|
|
68
|
-
} else {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public static phaseFromOutput(
|
|
74
|
-
output: PublicKernelCircuitPublicInputs,
|
|
75
|
-
currentPhaseManager: AbstractPhaseManager,
|
|
76
|
-
db: MerkleTreeOperations,
|
|
77
|
-
publicExecutor: PublicExecutor,
|
|
78
|
-
publicKernel: PublicKernelCircuitSimulator,
|
|
79
|
-
globalVariables: GlobalVariables,
|
|
80
|
-
historicalHeader: Header,
|
|
81
|
-
publicContractsDB: ContractsDataSourcePublicDB,
|
|
82
|
-
publicStateDB: PublicStateDB,
|
|
83
|
-
): AbstractPhaseManager | undefined {
|
|
84
|
-
if (output.needsSetup) {
|
|
85
|
-
throw new CannotTransitionToSetupError();
|
|
86
|
-
} else if (output.needsAppLogic) {
|
|
87
|
-
if (currentPhaseManager.phase === PublicKernelPhase.APP_LOGIC) {
|
|
88
|
-
throw new PhaseDidNotChangeError(currentPhaseManager.phase);
|
|
89
|
-
}
|
|
90
|
-
return new AppLogicPhaseManager(
|
|
91
|
-
db,
|
|
92
|
-
publicExecutor,
|
|
93
|
-
publicKernel,
|
|
94
|
-
globalVariables,
|
|
95
|
-
historicalHeader,
|
|
96
|
-
publicContractsDB,
|
|
97
|
-
publicStateDB,
|
|
98
|
-
);
|
|
99
|
-
} else if (output.needsTeardown) {
|
|
100
|
-
if (currentPhaseManager.phase === PublicKernelPhase.TEARDOWN) {
|
|
101
|
-
throw new PhaseDidNotChangeError(currentPhaseManager.phase);
|
|
102
|
-
}
|
|
103
|
-
return new TeardownPhaseManager(
|
|
104
|
-
db,
|
|
105
|
-
publicExecutor,
|
|
106
|
-
publicKernel,
|
|
107
|
-
globalVariables,
|
|
108
|
-
historicalHeader,
|
|
109
|
-
publicContractsDB,
|
|
110
|
-
publicStateDB,
|
|
111
|
-
);
|
|
112
|
-
} else if (currentPhaseManager.phase !== PublicKernelPhase.TAIL) {
|
|
113
|
-
return new TailPhaseManager(
|
|
114
|
-
db,
|
|
115
|
-
publicExecutor,
|
|
116
|
-
publicKernel,
|
|
117
|
-
globalVariables,
|
|
118
|
-
historicalHeader,
|
|
119
|
-
publicContractsDB,
|
|
120
|
-
publicStateDB,
|
|
121
|
-
);
|
|
122
|
-
} else {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type BlockProver,
|
|
3
|
-
type FailedTx,
|
|
4
|
-
type ProcessedTx,
|
|
5
|
-
type SimulationError,
|
|
6
|
-
Tx,
|
|
7
|
-
makeEmptyProcessedTx,
|
|
8
|
-
makeProcessedTx,
|
|
9
|
-
toTxEffect,
|
|
10
|
-
validateProcessedTx,
|
|
11
|
-
} from '@aztec/circuit-types';
|
|
12
|
-
import { type TxSequencerProcessingStats } from '@aztec/circuit-types/stats';
|
|
13
|
-
import { type GlobalVariables, type Header, type KernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
14
|
-
import { type ProcessReturnValues } from '@aztec/foundation/abi';
|
|
15
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
16
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
17
|
-
import { PublicExecutor, type PublicStateDB, type SimulationProvider } from '@aztec/simulator';
|
|
18
|
-
import { type ContractDataSource } from '@aztec/types/contracts';
|
|
19
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
20
|
-
|
|
21
|
-
import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
22
|
-
import { ContractsDataSourcePublicDB, WorldStateDB, WorldStatePublicDB } from '../simulator/public_executor.js';
|
|
23
|
-
import { RealPublicKernelCircuitSimulator } from '../simulator/public_kernel.js';
|
|
24
|
-
import { type AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
25
|
-
import { PhaseManagerFactory } from './phase_manager_factory.js';
|
|
26
|
-
import { type TxValidator } from './tx_validator.js';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
30
|
-
*/
|
|
31
|
-
export class PublicProcessorFactory {
|
|
32
|
-
constructor(
|
|
33
|
-
private merkleTree: MerkleTreeOperations,
|
|
34
|
-
private contractDataSource: ContractDataSource,
|
|
35
|
-
private simulator: SimulationProvider,
|
|
36
|
-
) {}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Creates a new instance of a PublicProcessor.
|
|
40
|
-
* @param historicalHeader - The header of a block previous to the one in which the tx is included.
|
|
41
|
-
* @param globalVariables - The global variables for the block being processed.
|
|
42
|
-
* @param newContracts - Provides access to contract bytecode for public executions.
|
|
43
|
-
* @returns A new instance of a PublicProcessor.
|
|
44
|
-
*/
|
|
45
|
-
public async create(
|
|
46
|
-
historicalHeader: Header | undefined,
|
|
47
|
-
globalVariables: GlobalVariables,
|
|
48
|
-
): Promise<PublicProcessor> {
|
|
49
|
-
historicalHeader = historicalHeader ?? (await this.merkleTree.buildInitialHeader());
|
|
50
|
-
|
|
51
|
-
const publicContractsDB = new ContractsDataSourcePublicDB(this.contractDataSource);
|
|
52
|
-
const worldStatePublicDB = new WorldStatePublicDB(this.merkleTree);
|
|
53
|
-
const worldStateDB = new WorldStateDB(this.merkleTree);
|
|
54
|
-
const publicExecutor = new PublicExecutor(worldStatePublicDB, publicContractsDB, worldStateDB, historicalHeader);
|
|
55
|
-
return new PublicProcessor(
|
|
56
|
-
this.merkleTree,
|
|
57
|
-
publicExecutor,
|
|
58
|
-
new RealPublicKernelCircuitSimulator(this.simulator),
|
|
59
|
-
globalVariables,
|
|
60
|
-
historicalHeader,
|
|
61
|
-
publicContractsDB,
|
|
62
|
-
worldStatePublicDB,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Converts Txs lifted from the P2P module into ProcessedTx objects by executing
|
|
69
|
-
* any public function calls in them. Txs with private calls only are unaffected.
|
|
70
|
-
*/
|
|
71
|
-
export class PublicProcessor {
|
|
72
|
-
constructor(
|
|
73
|
-
protected db: MerkleTreeOperations,
|
|
74
|
-
protected publicExecutor: PublicExecutor,
|
|
75
|
-
protected publicKernel: PublicKernelCircuitSimulator,
|
|
76
|
-
protected globalVariables: GlobalVariables,
|
|
77
|
-
protected historicalHeader: Header,
|
|
78
|
-
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
79
|
-
protected publicStateDB: PublicStateDB,
|
|
80
|
-
|
|
81
|
-
private log = createDebugLogger('aztec:sequencer:public-processor'),
|
|
82
|
-
) {}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
86
|
-
* @param txs - Txs to process.
|
|
87
|
-
* @returns The list of processed txs with their circuit simulation outputs.
|
|
88
|
-
*/
|
|
89
|
-
public async process(
|
|
90
|
-
txs: Tx[],
|
|
91
|
-
maxTransactions = txs.length,
|
|
92
|
-
blockProver?: BlockProver,
|
|
93
|
-
txValidator?: TxValidator,
|
|
94
|
-
): Promise<[ProcessedTx[], FailedTx[], ProcessReturnValues[]]> {
|
|
95
|
-
// The processor modifies the tx objects in place, so we need to clone them.
|
|
96
|
-
txs = txs.map(tx => Tx.clone(tx));
|
|
97
|
-
const result: ProcessedTx[] = [];
|
|
98
|
-
const failed: FailedTx[] = [];
|
|
99
|
-
const returns: ProcessReturnValues[] = [];
|
|
100
|
-
|
|
101
|
-
for (const tx of txs) {
|
|
102
|
-
// only process up to the limit of the block
|
|
103
|
-
if (result.length >= maxTransactions) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
const [processedTx, returnValues] = !tx.hasPublicCalls()
|
|
108
|
-
? [makeProcessedTx(tx, tx.data.toKernelCircuitPublicInputs(), tx.proof)]
|
|
109
|
-
: await this.processTxWithPublicCalls(tx);
|
|
110
|
-
validateProcessedTx(processedTx);
|
|
111
|
-
// Re-validate the transaction
|
|
112
|
-
if (txValidator) {
|
|
113
|
-
// Only accept processed transactions that are not double-spends,
|
|
114
|
-
// public functions emitting nullifiers would pass earlier check but fail here.
|
|
115
|
-
// Note that we're checking all nullifiers generated in the private execution twice,
|
|
116
|
-
// we could store the ones already checked and skip them here as an optimization.
|
|
117
|
-
const [_, invalid] = await txValidator.validateTxs([processedTx]);
|
|
118
|
-
if (invalid.length) {
|
|
119
|
-
throw new Error(`Transaction ${invalid[0].hash} invalid after processing public functions`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// if we were given a prover then send the transaction to it for proving
|
|
123
|
-
if (blockProver) {
|
|
124
|
-
await blockProver.addNewTx(processedTx);
|
|
125
|
-
}
|
|
126
|
-
result.push(processedTx);
|
|
127
|
-
returns.push(returnValues);
|
|
128
|
-
} catch (err: any) {
|
|
129
|
-
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
130
|
-
this.log.warn(`Failed to process tx ${tx.getTxHash()}: ${errorMessage}`);
|
|
131
|
-
|
|
132
|
-
failed.push({
|
|
133
|
-
tx,
|
|
134
|
-
error: err instanceof Error ? err : new Error(errorMessage),
|
|
135
|
-
});
|
|
136
|
-
returns.push([]);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return [result, failed, returns];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Makes an empty processed tx. Useful for padding a block to a power of two number of txs.
|
|
145
|
-
* @returns A processed tx with empty data.
|
|
146
|
-
*/
|
|
147
|
-
public makeEmptyProcessedTx(): ProcessedTx {
|
|
148
|
-
const { chainId, version } = this.globalVariables;
|
|
149
|
-
return makeEmptyProcessedTx(this.historicalHeader.clone(), chainId, version);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, ProcessReturnValues | undefined]> {
|
|
153
|
-
let returnValues: ProcessReturnValues = undefined;
|
|
154
|
-
let phase: AbstractPhaseManager | undefined = PhaseManagerFactory.phaseFromTx(
|
|
155
|
-
tx,
|
|
156
|
-
this.db,
|
|
157
|
-
this.publicExecutor,
|
|
158
|
-
this.publicKernel,
|
|
159
|
-
this.globalVariables,
|
|
160
|
-
this.historicalHeader,
|
|
161
|
-
this.publicContractsDB,
|
|
162
|
-
this.publicStateDB,
|
|
163
|
-
);
|
|
164
|
-
this.log.debug(`Beginning processing in phase ${phase?.phase} for tx ${tx.getTxHash()}`);
|
|
165
|
-
let proof = tx.proof;
|
|
166
|
-
let publicKernelPublicInput = tx.data.toPublicKernelCircuitPublicInputs();
|
|
167
|
-
let finalKernelOutput: KernelCircuitPublicInputs | undefined;
|
|
168
|
-
let revertReason: SimulationError | undefined;
|
|
169
|
-
const timer = new Timer();
|
|
170
|
-
while (phase) {
|
|
171
|
-
const output = await phase.handle(tx, publicKernelPublicInput, proof);
|
|
172
|
-
if (phase.phase === PublicKernelPhase.APP_LOGIC) {
|
|
173
|
-
returnValues = output.returnValues;
|
|
174
|
-
}
|
|
175
|
-
publicKernelPublicInput = output.publicKernelOutput;
|
|
176
|
-
finalKernelOutput = output.finalKernelOutput;
|
|
177
|
-
proof = output.publicKernelProof;
|
|
178
|
-
revertReason ??= output.revertReason;
|
|
179
|
-
phase = PhaseManagerFactory.phaseFromOutput(
|
|
180
|
-
publicKernelPublicInput,
|
|
181
|
-
phase,
|
|
182
|
-
this.db,
|
|
183
|
-
this.publicExecutor,
|
|
184
|
-
this.publicKernel,
|
|
185
|
-
this.globalVariables,
|
|
186
|
-
this.historicalHeader,
|
|
187
|
-
this.publicContractsDB,
|
|
188
|
-
this.publicStateDB,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (!finalKernelOutput) {
|
|
193
|
-
throw new Error('Final public kernel was not executed.');
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const processedTx = makeProcessedTx(tx, finalKernelOutput, proof, revertReason);
|
|
197
|
-
|
|
198
|
-
this.log.debug(`Processed public part of ${tx.getTxHash()}`, {
|
|
199
|
-
eventName: 'tx-sequencer-processing',
|
|
200
|
-
duration: timer.ms(),
|
|
201
|
-
effectsSize: toTxEffect(processedTx).toBuffer().length,
|
|
202
|
-
publicDataUpdateRequests:
|
|
203
|
-
processedTx.data.end.publicDataUpdateRequests.filter(x => !x.leafSlot.isZero()).length ?? 0,
|
|
204
|
-
...tx.getStats(),
|
|
205
|
-
} satisfies TxSequencerProcessingStats);
|
|
206
|
-
|
|
207
|
-
return [processedTx, returnValues];
|
|
208
|
-
}
|
|
209
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type Tx } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
type GlobalVariables,
|
|
4
|
-
type Header,
|
|
5
|
-
type Proof,
|
|
6
|
-
type PublicKernelCircuitPublicInputs,
|
|
7
|
-
} from '@aztec/circuits.js';
|
|
8
|
-
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
9
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
10
|
-
|
|
11
|
-
import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
12
|
-
import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
13
|
-
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The phase manager responsible for performing the fee preparation phase.
|
|
17
|
-
*/
|
|
18
|
-
export class SetupPhaseManager extends AbstractPhaseManager {
|
|
19
|
-
constructor(
|
|
20
|
-
protected db: MerkleTreeOperations,
|
|
21
|
-
protected publicExecutor: PublicExecutor,
|
|
22
|
-
protected publicKernel: PublicKernelCircuitSimulator,
|
|
23
|
-
protected globalVariables: GlobalVariables,
|
|
24
|
-
protected historicalHeader: Header,
|
|
25
|
-
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
26
|
-
protected publicStateDB: PublicStateDB,
|
|
27
|
-
public phase: PublicKernelPhase = PublicKernelPhase.SETUP,
|
|
28
|
-
) {
|
|
29
|
-
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
override async handle(
|
|
33
|
-
tx: Tx,
|
|
34
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
35
|
-
previousPublicKernelProof: Proof,
|
|
36
|
-
) {
|
|
37
|
-
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
38
|
-
const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
|
|
39
|
-
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
|
|
40
|
-
// the abstract phase manager throws if simulation gives error in a non-revertible phase
|
|
41
|
-
async err => {
|
|
42
|
-
await this.publicStateDB.rollbackToCommit();
|
|
43
|
-
throw err;
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
|
|
47
|
-
await this.publicStateDB.checkpoint();
|
|
48
|
-
return { publicKernelOutput, publicKernelProof, revertReason, returnValues: undefined };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { type Tx } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
type Fr,
|
|
4
|
-
type GlobalVariables,
|
|
5
|
-
type Header,
|
|
6
|
-
type KernelCircuitPublicInputs,
|
|
7
|
-
MAX_NEW_NOTE_HASHES_PER_TX,
|
|
8
|
-
type Proof,
|
|
9
|
-
type PublicKernelCircuitPublicInputs,
|
|
10
|
-
PublicKernelTailCircuitPrivateInputs,
|
|
11
|
-
type SideEffect,
|
|
12
|
-
makeEmptyProof,
|
|
13
|
-
mergeAccumulatedData,
|
|
14
|
-
sortByCounter,
|
|
15
|
-
} from '@aztec/circuits.js';
|
|
16
|
-
import { type Tuple } from '@aztec/foundation/serialize';
|
|
17
|
-
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
18
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
19
|
-
|
|
20
|
-
import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
21
|
-
import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
22
|
-
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
23
|
-
|
|
24
|
-
export class TailPhaseManager extends AbstractPhaseManager {
|
|
25
|
-
constructor(
|
|
26
|
-
protected db: MerkleTreeOperations,
|
|
27
|
-
protected publicExecutor: PublicExecutor,
|
|
28
|
-
protected publicKernel: PublicKernelCircuitSimulator,
|
|
29
|
-
protected globalVariables: GlobalVariables,
|
|
30
|
-
protected historicalHeader: Header,
|
|
31
|
-
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
32
|
-
protected publicStateDB: PublicStateDB,
|
|
33
|
-
public readonly phase: PublicKernelPhase = PublicKernelPhase.TAIL,
|
|
34
|
-
) {
|
|
35
|
-
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async handle(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs, previousPublicKernelProof: Proof) {
|
|
39
|
-
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
40
|
-
const [finalKernelOutput, publicKernelProof] = await this.runTailKernelCircuit(
|
|
41
|
-
previousPublicKernelOutput,
|
|
42
|
-
previousPublicKernelProof,
|
|
43
|
-
).catch(
|
|
44
|
-
// the abstract phase manager throws if simulation gives error in non-revertible phase
|
|
45
|
-
async err => {
|
|
46
|
-
await this.publicStateDB.rollbackToCommit();
|
|
47
|
-
throw err;
|
|
48
|
-
},
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
// commit the state updates from this transaction
|
|
52
|
-
await this.publicStateDB.commit();
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
publicKernelOutput: previousPublicKernelOutput,
|
|
56
|
-
finalKernelOutput,
|
|
57
|
-
publicKernelProof,
|
|
58
|
-
revertReason: undefined,
|
|
59
|
-
returnValues: undefined,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private async runTailKernelCircuit(
|
|
64
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
65
|
-
previousProof: Proof,
|
|
66
|
-
): Promise<[KernelCircuitPublicInputs, Proof]> {
|
|
67
|
-
const output = await this.simulate(previousOutput, previousProof);
|
|
68
|
-
|
|
69
|
-
// Temporary hack. Should sort them in the tail circuit.
|
|
70
|
-
const noteHashes = mergeAccumulatedData(
|
|
71
|
-
MAX_NEW_NOTE_HASHES_PER_TX,
|
|
72
|
-
previousOutput.endNonRevertibleData.newNoteHashes,
|
|
73
|
-
previousOutput.end.newNoteHashes,
|
|
74
|
-
);
|
|
75
|
-
output.end.newNoteHashes = this.sortNoteHashes<typeof MAX_NEW_NOTE_HASHES_PER_TX>(noteHashes);
|
|
76
|
-
|
|
77
|
-
return [output, makeEmptyProof()];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private async simulate(
|
|
81
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
82
|
-
previousProof: Proof,
|
|
83
|
-
): Promise<KernelCircuitPublicInputs> {
|
|
84
|
-
const previousKernel = this.getPreviousKernelData(previousOutput, previousProof);
|
|
85
|
-
|
|
86
|
-
const { validationRequests, endNonRevertibleData, end } = previousOutput;
|
|
87
|
-
const nullifierReadRequestHints = await this.hintsBuilder.getNullifierReadRequestHints(
|
|
88
|
-
validationRequests.nullifierReadRequests,
|
|
89
|
-
endNonRevertibleData.newNullifiers,
|
|
90
|
-
end.newNullifiers,
|
|
91
|
-
);
|
|
92
|
-
const nullifierNonExistentReadRequestHints = await this.hintsBuilder.getNullifierNonExistentReadRequestHints(
|
|
93
|
-
validationRequests.nullifierNonExistentReadRequests,
|
|
94
|
-
endNonRevertibleData.newNullifiers,
|
|
95
|
-
end.newNullifiers,
|
|
96
|
-
);
|
|
97
|
-
const inputs = new PublicKernelTailCircuitPrivateInputs(
|
|
98
|
-
previousKernel,
|
|
99
|
-
nullifierReadRequestHints,
|
|
100
|
-
nullifierNonExistentReadRequestHints,
|
|
101
|
-
);
|
|
102
|
-
return this.publicKernel.publicKernelCircuitTail(inputs);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private sortNoteHashes<N extends number>(noteHashes: Tuple<SideEffect, N>): Tuple<Fr, N> {
|
|
106
|
-
return sortByCounter(noteHashes.map(n => ({ ...n, counter: n.counter.toNumber() }))).map(n => n.value) as Tuple<
|
|
107
|
-
Fr,
|
|
108
|
-
N
|
|
109
|
-
>;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type Tx } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
type GlobalVariables,
|
|
4
|
-
type Header,
|
|
5
|
-
type Proof,
|
|
6
|
-
type PublicKernelCircuitPublicInputs,
|
|
7
|
-
} from '@aztec/circuits.js';
|
|
8
|
-
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
9
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
10
|
-
|
|
11
|
-
import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
12
|
-
import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
13
|
-
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The phase manager responsible for performing the fee preparation phase.
|
|
17
|
-
*/
|
|
18
|
-
export class TeardownPhaseManager extends AbstractPhaseManager {
|
|
19
|
-
constructor(
|
|
20
|
-
protected db: MerkleTreeOperations,
|
|
21
|
-
protected publicExecutor: PublicExecutor,
|
|
22
|
-
protected publicKernel: PublicKernelCircuitSimulator,
|
|
23
|
-
protected globalVariables: GlobalVariables,
|
|
24
|
-
protected historicalHeader: Header,
|
|
25
|
-
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
26
|
-
protected publicStateDB: PublicStateDB,
|
|
27
|
-
public phase: PublicKernelPhase = PublicKernelPhase.TEARDOWN,
|
|
28
|
-
) {
|
|
29
|
-
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
override async handle(
|
|
33
|
-
tx: Tx,
|
|
34
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
35
|
-
previousPublicKernelProof: Proof,
|
|
36
|
-
) {
|
|
37
|
-
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
38
|
-
const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
|
|
39
|
-
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
|
|
40
|
-
// the abstract phase manager throws if simulation gives error in a non-revertible phase
|
|
41
|
-
async err => {
|
|
42
|
-
await this.publicStateDB.rollbackToCommit();
|
|
43
|
-
throw err;
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
|
|
47
|
-
await this.publicStateDB.checkpoint();
|
|
48
|
-
return { publicKernelOutput, publicKernelProof, revertReason, returnValues: undefined };
|
|
49
|
-
}
|
|
50
|
-
}
|