@aztec/simulator 3.0.0-nightly.20251104 → 3.0.0-nightly.20251106
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/public/contracts_db_checkpoint.d.ts +16 -0
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
- package/dest/public/contracts_db_checkpoint.js +30 -0
- package/dest/public/db_interfaces.d.ts +12 -0
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +2 -2
- package/dest/public/hinting_db_sources.d.ts +9 -1
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +64 -11
- package/dest/public/public_db_sources.d.ts +20 -60
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +64 -115
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +2 -2
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +7 -5
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +30 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +133 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +24 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +112 -13
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +2 -2
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +4 -4
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +10 -2
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -2
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +98 -104
- package/package.json +16 -16
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +15 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +2 -2
- package/src/public/hinting_db_sources.ts +104 -7
- package/src/public/public_db_sources.ts +80 -156
- package/src/public/public_processor/guarded_merkle_tree.ts +2 -2
- package/src/public/public_processor/public_processor.ts +8 -5
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +162 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +152 -14
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +4 -4
- package/src/public/public_tx_simulator/public_tx_context.ts +8 -0
- package/src/public/public_tx_simulator/public_tx_simulator.ts +121 -128
- package/dest/public/tx_contract_cache.d.ts +0 -41
- package/dest/public/tx_contract_cache.d.ts.map +0 -1
- package/dest/public/tx_contract_cache.js +0 -49
- package/src/public/tx_contract_cache.ts +0 -69
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
4
|
+
export declare class ContractsDbCheckpoint {
|
|
5
|
+
private instances;
|
|
6
|
+
private classes;
|
|
7
|
+
private bytecodeCommitments;
|
|
8
|
+
addInstance(address: AztecAddress, instance: ContractInstanceWithAddress): void;
|
|
9
|
+
addClass(classId: Fr, contractClass: ContractClassPublic): void;
|
|
10
|
+
addBytecodeCommitment(classId: Fr, commitment: Fr): void;
|
|
11
|
+
getInstance(address: AztecAddress): ContractInstanceWithAddress | undefined;
|
|
12
|
+
getClass(classId: Fr): ContractClassPublic | undefined;
|
|
13
|
+
getBytecodeCommitment(classId: Fr): Fr | undefined;
|
|
14
|
+
deepCopy(): ContractsDbCheckpoint;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=contracts_db_checkpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts_db_checkpoint.d.ts","sourceRoot":"","sources":["../../src/public/contracts_db_checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE/F,qBAAa,qBAAqB;IAChC,OAAO,CAAC,SAAS,CAAuD;IACxE,OAAO,CAAC,OAAO,CAA+C;IAC9D,OAAO,CAAC,mBAAmB,CAA8B;IAElD,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAI/E,QAAQ,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,mBAAmB,GAAG,IAAI;IAI/D,qBAAqB,CAAC,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,IAAI;IAIxD,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,2BAA2B,GAAG,SAAS;IAI3E,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,mBAAmB,GAAG,SAAS;IAItD,qBAAqB,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,GAAG,SAAS;IAIlD,QAAQ,IAAI,qBAAqB;CAOzC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class ContractsDbCheckpoint {
|
|
2
|
+
instances = new Map();
|
|
3
|
+
classes = new Map();
|
|
4
|
+
bytecodeCommitments = new Map();
|
|
5
|
+
addInstance(address, instance) {
|
|
6
|
+
this.instances.set(address.toString(), instance);
|
|
7
|
+
}
|
|
8
|
+
addClass(classId, contractClass) {
|
|
9
|
+
this.classes.set(classId.toString(), contractClass);
|
|
10
|
+
}
|
|
11
|
+
addBytecodeCommitment(classId, commitment) {
|
|
12
|
+
this.bytecodeCommitments.set(classId.toString(), commitment);
|
|
13
|
+
}
|
|
14
|
+
getInstance(address) {
|
|
15
|
+
return this.instances.get(address.toString());
|
|
16
|
+
}
|
|
17
|
+
getClass(classId) {
|
|
18
|
+
return this.classes.get(classId.toString());
|
|
19
|
+
}
|
|
20
|
+
getBytecodeCommitment(classId) {
|
|
21
|
+
return this.bytecodeCommitments.get(classId.toString());
|
|
22
|
+
}
|
|
23
|
+
deepCopy() {
|
|
24
|
+
const copy = new ContractsDbCheckpoint();
|
|
25
|
+
this.instances.forEach((value, key)=>copy.instances.set(key, value));
|
|
26
|
+
this.classes.forEach((value, key)=>copy.classes.set(key, value));
|
|
27
|
+
this.bytecodeCommitments.forEach((value, key)=>copy.bytecodeCommitments.set(key, value));
|
|
28
|
+
return copy;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -52,5 +52,17 @@ export interface PublicContractsDBInterface {
|
|
|
52
52
|
* @returns The name of the function or undefined if not found.
|
|
53
53
|
*/
|
|
54
54
|
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a checkpoint of the current contract state.
|
|
57
|
+
*/
|
|
58
|
+
createCheckpoint(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Commits the current checkpoint, merging its state with the parent.
|
|
61
|
+
*/
|
|
62
|
+
commitCheckpoint(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Reverts the current checkpoint, discarding its state.
|
|
65
|
+
*/
|
|
66
|
+
revertCheckpoint(): void;
|
|
55
67
|
}
|
|
56
68
|
//# sourceMappingURL=db_interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db_interfaces.d.ts","sourceRoot":"","sources":["../../src/public/db_interfaces.ts"],"names":[],"mappings":"AAAA,OAAO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{ GlobalVariables, PublicCallRequestWithCalldata } from '@aztec/stdlib/tx
|
|
|
7
7
|
import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
|
|
8
8
|
import { DEFAULT_BLOCK_NUMBER, DEFAULT_TIMESTAMP, getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/utils.js';
|
|
9
9
|
import { PublicContractsDB } from '../public_db_sources.js';
|
|
10
|
-
import {
|
|
10
|
+
import { MeasuredCppPublicTxSimulator } from '../public_tx_simulator/cpp_public_tx_simulator.js';
|
|
11
11
|
import { MeasuredPublicTxSimulator } from '../public_tx_simulator/measured_public_tx_simulator.js';
|
|
12
12
|
import { TestExecutorMetrics } from '../test_executor_metrics.js';
|
|
13
13
|
import { SimpleContractDataSource } from './simple_contract_data_source.js';
|
|
@@ -30,7 +30,7 @@ const DEFAULT_GAS_FEES = new GasFees(2, 3);
|
|
|
30
30
|
skipFeeEnforcement: false,
|
|
31
31
|
clientInitiatedSimulation: true
|
|
32
32
|
};
|
|
33
|
-
this.simulator = useCppSimulator ? new
|
|
33
|
+
this.simulator = useCppSimulator ? new MeasuredCppPublicTxSimulator(merkleTree, contractsDB, globals, this.metrics, config) : new MeasuredPublicTxSimulator(merkleTree, contractsDB, globals, this.metrics, config);
|
|
34
34
|
}
|
|
35
35
|
static async create(worldStateService, globals = defaultGlobals(), metrics = new TestExecutorMetrics(), useCppSimulator = false) {
|
|
36
36
|
const contractDataSource = new SimpleContractDataSource();
|
|
@@ -14,12 +14,20 @@ import type { PublicContractsDBInterface } from './db_interfaces.js';
|
|
|
14
14
|
export declare class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
15
15
|
private readonly db;
|
|
16
16
|
private hints;
|
|
17
|
-
private
|
|
17
|
+
private static readonly log;
|
|
18
|
+
private checkpointActionCounter;
|
|
19
|
+
private nextCheckpointId;
|
|
20
|
+
private checkpointStack;
|
|
18
21
|
constructor(db: PublicContractsDBInterface, hints: AvmExecutionHints);
|
|
19
22
|
getContractInstance(address: AztecAddress, timestamp: UInt64): Promise<ContractInstanceWithAddress | undefined>;
|
|
20
23
|
getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined>;
|
|
21
24
|
getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
|
|
22
25
|
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
26
|
+
createCheckpoint(): void;
|
|
27
|
+
commitCheckpoint(): void;
|
|
28
|
+
revertCheckpoint(): void;
|
|
29
|
+
private getHintKey;
|
|
30
|
+
private getCurrentCheckpointId;
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
25
33
|
* A low-level merkle DB that collects hints.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hinting_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/hinting_db_sources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"hinting_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/hinting_db_sources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAWL,KAAK,iBAAiB,EASvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAEL,KAAK,oBAA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vD,MAAM,EAAE,EAAE,EACV,MAAM,EAAE,kBAAkB,CAAC,EAAE,CAAC,EAAE,EAChC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAIrB,6BAA6B,CAAC,EAAE,SAAS,YAAY,EAChE,MAAM,EAAE,EAAE,EACV,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;CAGnC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sha256Trunc } from '@aztec/foundation/crypto';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { AvmAppendLeavesHint, AvmBytecodeCommitmentHint, AvmCommitCheckpointHint, AvmContractClassHint, AvmContractInstanceHint, AvmCreateCheckpointHint, AvmGetLeafPreimageHintNullifierTree, AvmGetLeafPreimageHintPublicDataTree, AvmGetLeafValueHint, AvmGetPreviousValueIndexHint, AvmGetSiblingPathHint, AvmRevertCheckpointHint, AvmSequentialInsertHintNullifierTree, AvmSequentialInsertHintPublicDataTree } from '@aztec/stdlib/avm';
|
|
4
|
+
import { AvmAppendLeavesHint, AvmBytecodeCommitmentHint, AvmCommitCheckpointHint, AvmContractClassHint, AvmContractDBCommitCheckpointHint, AvmContractDBCreateCheckpointHint, AvmContractDBRevertCheckpointHint, AvmContractInstanceHint, AvmCreateCheckpointHint, AvmDebugFunctionNameHint, AvmGetLeafPreimageHintNullifierTree, AvmGetLeafPreimageHintPublicDataTree, AvmGetLeafValueHint, AvmGetPreviousValueIndexHint, AvmGetSiblingPathHint, AvmRevertCheckpointHint, AvmSequentialInsertHintNullifierTree, AvmSequentialInsertHintPublicDataTree } from '@aztec/stdlib/avm';
|
|
5
5
|
import { AppendOnlyTreeSnapshot, MerkleTreeId, NullifierLeaf, PublicDataTreeLeaf, getTreeName, merkleTreeIds } from '@aztec/stdlib/trees';
|
|
6
6
|
import { TreeSnapshots } from '@aztec/stdlib/tx';
|
|
7
7
|
import { strict as assert } from 'assert';
|
|
@@ -10,38 +10,91 @@ import { strict as assert } from 'assert';
|
|
|
10
10
|
*/ export class HintingPublicContractsDB {
|
|
11
11
|
db;
|
|
12
12
|
hints;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
static log = createLogger('simulator:hinting-public-contracts-db');
|
|
14
|
+
checkpointActionCounter;
|
|
15
|
+
nextCheckpointId;
|
|
16
|
+
checkpointStack;
|
|
15
17
|
constructor(db, hints){
|
|
16
18
|
this.db = db;
|
|
17
19
|
this.hints = hints;
|
|
18
|
-
this.
|
|
20
|
+
this.checkpointActionCounter = 0;
|
|
21
|
+
this.nextCheckpointId = 1;
|
|
22
|
+
this.checkpointStack = [
|
|
23
|
+
0
|
|
24
|
+
];
|
|
19
25
|
}
|
|
20
26
|
async getContractInstance(address, timestamp) {
|
|
21
27
|
const instance = await this.db.getContractInstance(address, timestamp);
|
|
22
28
|
if (instance) {
|
|
23
|
-
|
|
24
|
-
this.hints.contractInstances.push(new AvmContractInstanceHint(instance.address, instance.salt, instance.deployer, instance.currentContractClassId, instance.originalContractClassId, instance.initializationHash, instance.publicKeys));
|
|
29
|
+
const hintKey = this.getHintKey();
|
|
30
|
+
this.hints.contractInstances.push(new AvmContractInstanceHint(hintKey, instance.address, instance.salt, instance.deployer, instance.currentContractClassId, instance.originalContractClassId, instance.initializationHash, instance.publicKeys));
|
|
31
|
+
HintingPublicContractsDB.log.trace(`[getContractInstance:${hintKey}] Added contract instance ${instance.address.toString()} to hints.`);
|
|
25
32
|
}
|
|
26
33
|
return instance;
|
|
27
34
|
}
|
|
28
35
|
async getContractClass(contractClassId) {
|
|
29
36
|
const contractClass = await this.db.getContractClass(contractClassId);
|
|
30
|
-
if (contractClass
|
|
31
|
-
this.
|
|
32
|
-
this.hints.contractClasses.push(new AvmContractClassHint(contractClass.id, contractClass.artifactHash, contractClass.privateFunctionsRoot, contractClass.packedBytecode));
|
|
37
|
+
if (contractClass) {
|
|
38
|
+
const hintKey = this.getHintKey();
|
|
39
|
+
this.hints.contractClasses.push(new AvmContractClassHint(hintKey, contractClass.id, contractClass.artifactHash, contractClass.privateFunctionsRoot, contractClass.packedBytecode));
|
|
40
|
+
HintingPublicContractsDB.log.trace(`[getContractClass:${hintKey}] Added contract class ${contractClassId.toString()} to hints.`);
|
|
33
41
|
}
|
|
34
42
|
return contractClass;
|
|
35
43
|
}
|
|
36
44
|
async getBytecodeCommitment(contractClassId) {
|
|
37
45
|
const commitment = await this.db.getBytecodeCommitment(contractClassId);
|
|
38
46
|
if (commitment) {
|
|
39
|
-
this.
|
|
47
|
+
const hintKey = this.getHintKey();
|
|
48
|
+
this.hints.bytecodeCommitments.push(new AvmBytecodeCommitmentHint(hintKey, contractClassId, commitment));
|
|
49
|
+
HintingPublicContractsDB.log.trace(`[getBytecodeCommitment:${hintKey}] Added bytecode commitment ${commitment.toString()} to hints for contract class ${contractClassId.toString()}.`);
|
|
40
50
|
}
|
|
41
51
|
return commitment;
|
|
42
52
|
}
|
|
43
53
|
async getDebugFunctionName(contractAddress, selector) {
|
|
44
|
-
|
|
54
|
+
const name = await this.db.getDebugFunctionName(contractAddress, selector);
|
|
55
|
+
if (name) {
|
|
56
|
+
HintingPublicContractsDB.log.debug(`[getDebugFunctionName] Adding debug function name ${name} to hints for contract ${contractAddress.toString()} and selector ${selector.toString()}.`);
|
|
57
|
+
// We hint selector as a field to make things way simpler in C++.
|
|
58
|
+
this.hints.debugFunctionNames.push(new AvmDebugFunctionNameHint(contractAddress, selector.toField(), name));
|
|
59
|
+
}
|
|
60
|
+
return name;
|
|
61
|
+
}
|
|
62
|
+
createCheckpoint() {
|
|
63
|
+
const hintKey = this.getHintKey();
|
|
64
|
+
this.checkpointActionCounter++;
|
|
65
|
+
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
66
|
+
this.db.createCheckpoint();
|
|
67
|
+
const newCheckpointId = this.nextCheckpointId++;
|
|
68
|
+
this.checkpointStack.push(newCheckpointId);
|
|
69
|
+
this.hints.contractDBCreateCheckpointHints.push(new AvmContractDBCreateCheckpointHint(hintKey, oldCheckpointId, newCheckpointId));
|
|
70
|
+
HintingPublicContractsDB.log.trace(`[createCheckpoint:${hintKey}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId}.`);
|
|
71
|
+
}
|
|
72
|
+
commitCheckpoint() {
|
|
73
|
+
const hintKey = this.getHintKey();
|
|
74
|
+
this.checkpointActionCounter++;
|
|
75
|
+
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
76
|
+
this.db.commitCheckpoint();
|
|
77
|
+
this.checkpointStack.pop();
|
|
78
|
+
const newCheckpointId = this.getCurrentCheckpointId();
|
|
79
|
+
this.hints.contractDBCommitCheckpointHints.push(new AvmContractDBCommitCheckpointHint(hintKey, oldCheckpointId, newCheckpointId));
|
|
80
|
+
HintingPublicContractsDB.log.trace(`[commitCheckpoint:${hintKey}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId}.`);
|
|
81
|
+
}
|
|
82
|
+
revertCheckpoint() {
|
|
83
|
+
const hintKey = this.getHintKey();
|
|
84
|
+
this.checkpointActionCounter++;
|
|
85
|
+
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
86
|
+
this.db.revertCheckpoint();
|
|
87
|
+
this.checkpointStack.pop();
|
|
88
|
+
const newCheckpointId = this.getCurrentCheckpointId();
|
|
89
|
+
this.hints.contractDBRevertCheckpointHints.push(new AvmContractDBRevertCheckpointHint(hintKey, oldCheckpointId, newCheckpointId));
|
|
90
|
+
HintingPublicContractsDB.log.trace(`[revertCheckpoint:${hintKey}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId}.`);
|
|
91
|
+
}
|
|
92
|
+
// Private methods.
|
|
93
|
+
getHintKey() {
|
|
94
|
+
return this.checkpointActionCounter;
|
|
95
|
+
}
|
|
96
|
+
getCurrentCheckpointId() {
|
|
97
|
+
return this.checkpointStack[this.checkpointStack.length - 1];
|
|
45
98
|
}
|
|
46
99
|
}
|
|
47
100
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import { type ContractClassPublic, type ContractDataSource, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
4
|
+
import { type ContractClassPublic, type ContractDataSource, type ContractDeploymentData, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
5
5
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
6
6
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
7
7
|
import { TreeSnapshots, type Tx } from '@aztec/stdlib/tx';
|
|
@@ -9,84 +9,44 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
9
9
|
import type { PublicContractsDBInterface, PublicStateDBInterface } from './db_interfaces.js';
|
|
10
10
|
/**
|
|
11
11
|
* Implements the PublicContractsDBInterface using a ContractDataSource.
|
|
12
|
-
*
|
|
13
|
-
* Separates block-level contract information (from processed/included txs) from the
|
|
14
|
-
* current tx's contract information (which may be cleared on tx revert/death).
|
|
12
|
+
* Uses a stack-based checkpoint model for managing contract state.
|
|
15
13
|
*/
|
|
16
14
|
export declare class PublicContractsDB implements PublicContractsDBInterface {
|
|
17
15
|
private dataSource;
|
|
18
|
-
private
|
|
19
|
-
private currentTxRevertibleCache;
|
|
20
|
-
private blockCache;
|
|
16
|
+
private contractStateStack;
|
|
21
17
|
private bytecodeCommitmentCache;
|
|
22
18
|
private log;
|
|
23
19
|
constructor(dataSource: ContractDataSource);
|
|
24
|
-
|
|
25
|
-
* Add new contracts from a transaction
|
|
26
|
-
* @param tx - The transaction to add contracts from.
|
|
27
|
-
*/
|
|
20
|
+
addContracts(contractDeploymentData: ContractDeploymentData): Promise<void>;
|
|
28
21
|
addNewContracts(tx: Tx): Promise<void>;
|
|
29
22
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
addNewNonRevertibleContracts(tx: Tx): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Add revertible contracts from a transaction
|
|
36
|
-
* @param tx - The transaction to add revertible contracts from.
|
|
37
|
-
*/
|
|
38
|
-
addNewRevertibleContracts(tx: Tx): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Add non-revertible contract classes from a transaction
|
|
41
|
-
* For private-only txs, this will be all contract classes (found in tx.data.forPublic)
|
|
42
|
-
* @param tx - The transaction to add non-revertible contract classes from.
|
|
43
|
-
*/
|
|
44
|
-
private addNonRevertibleContractClasses;
|
|
45
|
-
/**
|
|
46
|
-
* Add revertible contract classes from a transaction
|
|
47
|
-
* None for private-only txs.
|
|
48
|
-
* @param tx - The transaction to add revertible contract classes from.
|
|
49
|
-
*/
|
|
50
|
-
private addRevertibleContractClasses;
|
|
51
|
-
/**
|
|
52
|
-
* Add non-revertible contract instances from a transaction
|
|
53
|
-
* For private-only txs, this will be all contract instances (found in tx.data.forRollup)
|
|
54
|
-
* @param tx - The transaction to add non-revertible contract instances from.
|
|
55
|
-
*/
|
|
56
|
-
private addNonRevertibleContractInstances;
|
|
57
|
-
/**
|
|
58
|
-
* Add revertible contract instances from a transaction
|
|
59
|
-
* None for private-only txs.
|
|
60
|
-
* @param tx - The transaction to add revertible contract instances from.
|
|
61
|
-
*/
|
|
62
|
-
private addRevertibleContractInstances;
|
|
63
|
-
/**
|
|
64
|
-
* Given a tx's siloed contract class logs, add the contract classes to the cache
|
|
65
|
-
* @param siloedContractClassLogs - Contract class logs to process
|
|
66
|
-
* @param cache - The cache to store the contract classes in
|
|
67
|
-
* @param cacheType - Type of cache (for logging)
|
|
23
|
+
* Creates a new checkpoint, copying the current state for upcoming modifications,
|
|
24
|
+
* and enabling rollbacks to current state in case of a revert.
|
|
68
25
|
*/
|
|
69
|
-
|
|
26
|
+
createCheckpoint(): void;
|
|
70
27
|
/**
|
|
71
|
-
*
|
|
72
|
-
* @param contractInstanceLogs - Contract instance logs to process
|
|
73
|
-
* @param cache - The cache to store the contract instances in
|
|
74
|
-
* @param cacheType - Type of cache (for logging)
|
|
28
|
+
* Commits the current checkpoint, accepting its state latest.
|
|
75
29
|
*/
|
|
76
|
-
|
|
30
|
+
commitCheckpoint(): void;
|
|
77
31
|
/**
|
|
78
|
-
*
|
|
32
|
+
* Commits the current checkpoint, not erroring if there is no checkpoint
|
|
33
|
+
* to commit. This is useful to do a sanity commit at the end of tx execution,
|
|
34
|
+
* doing nothing if the checkpoint was already reverted, but truly committing
|
|
35
|
+
* otherwise.
|
|
79
36
|
*/
|
|
80
|
-
|
|
37
|
+
commitCheckpointOkIfNone(): void;
|
|
81
38
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
39
|
+
* Reverts the current checkpoint, discarding its state and rolling back
|
|
40
|
+
* to the state as of the latest checkpoint.
|
|
84
41
|
*/
|
|
85
|
-
|
|
42
|
+
revertCheckpoint(): void;
|
|
43
|
+
private getCurrentState;
|
|
86
44
|
getContractInstance(address: AztecAddress, timestamp: UInt64): Promise<ContractInstanceWithAddress | undefined>;
|
|
87
45
|
getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined>;
|
|
88
46
|
getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
|
|
89
47
|
getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
48
|
+
private addContractClassesFromEvents;
|
|
49
|
+
private addContractInstancesFromEvents;
|
|
90
50
|
}
|
|
91
51
|
/**
|
|
92
52
|
* A high-level class that provides access to the merkle trees.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/public_db_sources.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAK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,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAWlD,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCpE,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;CASxD"}
|
|
@@ -5,143 +5,79 @@ import { Timer } from '@aztec/foundation/timer';
|
|
|
5
5
|
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
6
6
|
import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
7
7
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
8
|
-
import { computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
8
|
+
import { AllContractDeploymentData, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
9
9
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
10
10
|
import { MerkleTreeId, NullifierLeaf, PublicDataTreeLeaf, getTreeName } from '@aztec/stdlib/trees';
|
|
11
11
|
import { TreeSnapshots } from '@aztec/stdlib/tx';
|
|
12
12
|
import { strict as assert } from 'assert';
|
|
13
|
+
import { ContractsDbCheckpoint } from './contracts_db_checkpoint.js';
|
|
13
14
|
import { L1ToL2MessageIndexOutOfRangeError, NoteHashIndexOutOfRangeError } from './side_effect_errors.js';
|
|
14
|
-
import { TxContractCache } from './tx_contract_cache.js';
|
|
15
15
|
/**
|
|
16
16
|
* Implements the PublicContractsDBInterface using a ContractDataSource.
|
|
17
|
-
*
|
|
18
|
-
* Separates block-level contract information (from processed/included txs) from the
|
|
19
|
-
* current tx's contract information (which may be cleared on tx revert/death).
|
|
17
|
+
* Uses a stack-based checkpoint model for managing contract state.
|
|
20
18
|
*/ export class PublicContractsDB {
|
|
21
19
|
dataSource;
|
|
22
|
-
|
|
23
|
-
// Tx-level cache:
|
|
24
|
-
// - The current tx's new contract information is cached
|
|
25
|
-
// in currentTxNonRevertibleCache and currentTxRevertibleCache.
|
|
26
|
-
// Block-level cache:
|
|
27
|
-
// - Contract information from earlier in the block, usable by later txs.
|
|
28
|
-
// When a tx succeeds, that tx's caches are merged into the block cache and cleared.
|
|
29
|
-
currentTxNonRevertibleCache;
|
|
30
|
-
currentTxRevertibleCache;
|
|
31
|
-
blockCache;
|
|
32
|
-
// Separate flat cache for bytecode commitments.
|
|
20
|
+
contractStateStack;
|
|
33
21
|
bytecodeCommitmentCache;
|
|
34
22
|
log;
|
|
35
23
|
constructor(dataSource){
|
|
36
24
|
this.dataSource = dataSource;
|
|
37
|
-
this.
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
this.contractStateStack = [
|
|
26
|
+
new ContractsDbCheckpoint()
|
|
27
|
+
];
|
|
40
28
|
this.bytecodeCommitmentCache = new Map();
|
|
41
29
|
this.log = createLogger('simulator:contracts-data-source');
|
|
42
30
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
await this.addNonRevertibleContractClasses(tx);
|
|
48
|
-
await this.addRevertibleContractClasses(tx);
|
|
49
|
-
this.addNonRevertibleContractInstances(tx);
|
|
50
|
-
this.addRevertibleContractInstances(tx);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Add non revertible contracts from a transaction
|
|
54
|
-
* @param tx - The transaction to add non revertible contracts from.
|
|
55
|
-
*/ async addNewNonRevertibleContracts(tx) {
|
|
56
|
-
await this.addNonRevertibleContractClasses(tx);
|
|
57
|
-
this.addNonRevertibleContractInstances(tx);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Add revertible contracts from a transaction
|
|
61
|
-
* @param tx - The transaction to add revertible contracts from.
|
|
62
|
-
*/ async addNewRevertibleContracts(tx) {
|
|
63
|
-
await this.addRevertibleContractClasses(tx);
|
|
64
|
-
this.addRevertibleContractInstances(tx);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Add non-revertible contract classes from a transaction
|
|
68
|
-
* For private-only txs, this will be all contract classes (found in tx.data.forPublic)
|
|
69
|
-
* @param tx - The transaction to add non-revertible contract classes from.
|
|
70
|
-
*/ async addNonRevertibleContractClasses(tx) {
|
|
71
|
-
const siloedContractClassLogs = tx.data.forPublic ? tx.getSplitContractClassLogs(false) : tx.getContractClassLogs();
|
|
72
|
-
await this.addContractClassesFromLogs(siloedContractClassLogs, this.currentTxNonRevertibleCache, 'non-revertible');
|
|
31
|
+
async addContracts(contractDeploymentData) {
|
|
32
|
+
const currentState = this.getCurrentState();
|
|
33
|
+
await this.addContractClassesFromEvents(ContractClassPublishedEvent.extractContractClassEvents(contractDeploymentData.getContractClassLogs()), currentState);
|
|
34
|
+
this.addContractInstancesFromEvents(ContractInstancePublishedEvent.extractContractInstanceEvents(contractDeploymentData.getPrivateLogs()), currentState);
|
|
73
35
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*/ async addRevertibleContractClasses(tx) {
|
|
79
|
-
const siloedContractClassLogs = tx.data.forPublic ? tx.getSplitContractClassLogs(true) : [];
|
|
80
|
-
await this.addContractClassesFromLogs(siloedContractClassLogs, this.currentTxRevertibleCache, 'revertible');
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Add non-revertible contract instances from a transaction
|
|
84
|
-
* For private-only txs, this will be all contract instances (found in tx.data.forRollup)
|
|
85
|
-
* @param tx - The transaction to add non-revertible contract instances from.
|
|
86
|
-
*/ addNonRevertibleContractInstances(tx) {
|
|
87
|
-
const contractInstanceLogs = tx.data.forPublic ? tx.data.forPublic.nonRevertibleAccumulatedData.privateLogs.filter((l)=>!l.isEmpty()) : tx.data.forRollup.end.privateLogs.filter((l)=>!l.isEmpty());
|
|
88
|
-
this.addContractInstancesFromLogs(contractInstanceLogs, this.currentTxNonRevertibleCache, 'non-revertible');
|
|
36
|
+
async addNewContracts(tx) {
|
|
37
|
+
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
38
|
+
await this.addContracts(contractDeploymentData.getNonRevertibleContractDeploymentData());
|
|
39
|
+
await this.addContracts(contractDeploymentData.getRevertibleContractDeploymentData());
|
|
89
40
|
}
|
|
90
41
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
this.
|
|
42
|
+
* Creates a new checkpoint, copying the current state for upcoming modifications,
|
|
43
|
+
* and enabling rollbacks to current state in case of a revert.
|
|
44
|
+
*/ createCheckpoint() {
|
|
45
|
+
const currentState = this.getCurrentState();
|
|
46
|
+
const newState = currentState.deepCopy();
|
|
47
|
+
this.contractStateStack.push(newState);
|
|
97
48
|
}
|
|
98
49
|
/**
|
|
99
|
-
*
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
await Promise.all(contractClassEvents.map(async (event)=>{
|
|
107
|
-
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract's ${cacheType} tx cache`);
|
|
108
|
-
const contractClass = await event.toContractClassPublic();
|
|
109
|
-
cache.addClass(event.contractClassId, contractClass);
|
|
110
|
-
}));
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Given a tx's contract instance logs, add the contract instances to the cache
|
|
114
|
-
* @param contractInstanceLogs - Contract instance logs to process
|
|
115
|
-
* @param cache - The cache to store the contract instances in
|
|
116
|
-
* @param cacheType - Type of cache (for logging)
|
|
117
|
-
*/ addContractInstancesFromLogs(contractInstanceLogs, cache, cacheType) {
|
|
118
|
-
const contractInstanceEvents = contractInstanceLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log));
|
|
119
|
-
// Cache contract instances
|
|
120
|
-
contractInstanceEvents.forEach((e)=>{
|
|
121
|
-
this.log.debug(`Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to ${cacheType} tx contract cache`);
|
|
122
|
-
cache.addInstance(e.address, e.toContractInstance());
|
|
123
|
-
});
|
|
50
|
+
* Commits the current checkpoint, accepting its state latest.
|
|
51
|
+
*/ commitCheckpoint() {
|
|
52
|
+
if (this.contractStateStack.length <= 1) {
|
|
53
|
+
throw new Error('No checkpoint to commit');
|
|
54
|
+
}
|
|
55
|
+
const topState = this.contractStateStack.pop();
|
|
56
|
+
this.contractStateStack[this.contractStateStack.length - 1] = topState;
|
|
124
57
|
}
|
|
125
58
|
/**
|
|
126
|
-
*
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
59
|
+
* Commits the current checkpoint, not erroring if there is no checkpoint
|
|
60
|
+
* to commit. This is useful to do a sanity commit at the end of tx execution,
|
|
61
|
+
* doing nothing if the checkpoint was already reverted, but truly committing
|
|
62
|
+
* otherwise.
|
|
63
|
+
*/ commitCheckpointOkIfNone() {
|
|
64
|
+
if (this.contractStateStack.length <= 1) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const topState = this.contractStateStack.pop();
|
|
68
|
+
this.contractStateStack[this.contractStateStack.length - 1] = topState;
|
|
131
69
|
}
|
|
132
70
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!onlyNonRevertibles) {
|
|
139
|
-
// Merge revertible tx cache into block cache
|
|
140
|
-
this.blockCache.mergeFrom(this.currentTxRevertibleCache);
|
|
71
|
+
* Reverts the current checkpoint, discarding its state and rolling back
|
|
72
|
+
* to the state as of the latest checkpoint.
|
|
73
|
+
*/ revertCheckpoint() {
|
|
74
|
+
if (this.contractStateStack.length <= 1) {
|
|
75
|
+
throw new Error('No checkpoint to revert');
|
|
141
76
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
77
|
+
this.contractStateStack.pop();
|
|
78
|
+
}
|
|
79
|
+
getCurrentState() {
|
|
80
|
+
return this.contractStateStack[this.contractStateStack.length - 1];
|
|
145
81
|
}
|
|
146
82
|
// TODO(fcarreiro/alvaro): This method currently needs a blockNumber. Since this class
|
|
147
83
|
// is only ever used for a given block, it should be possible to construct it with the
|
|
@@ -153,12 +89,12 @@ import { TxContractCache } from './tx_contract_cache.js';
|
|
|
153
89
|
// Note: Block number got changed to timestamp so this comment ^ is outdated. Keeping
|
|
154
90
|
// the comment as is as I am not part of the AVM cabal.
|
|
155
91
|
async getContractInstance(address, timestamp) {
|
|
156
|
-
|
|
157
|
-
return
|
|
92
|
+
const currentState = this.getCurrentState();
|
|
93
|
+
return currentState.getInstance(address) ?? await this.dataSource.getContract(address, timestamp);
|
|
158
94
|
}
|
|
159
95
|
async getContractClass(contractClassId) {
|
|
160
|
-
|
|
161
|
-
return
|
|
96
|
+
const currentState = this.getCurrentState();
|
|
97
|
+
return currentState.getClass(contractClassId) ?? await this.dataSource.getContractClass(contractClassId);
|
|
162
98
|
}
|
|
163
99
|
async getBytecodeCommitment(contractClassId) {
|
|
164
100
|
// Try and retrieve from cache
|
|
@@ -185,6 +121,19 @@ import { TxContractCache } from './tx_contract_cache.js';
|
|
|
185
121
|
async getDebugFunctionName(address, selector) {
|
|
186
122
|
return await this.dataSource.getDebugFunctionName(address, selector);
|
|
187
123
|
}
|
|
124
|
+
async addContractClassesFromEvents(contractClassEvents, state) {
|
|
125
|
+
await Promise.all(contractClassEvents.map(async (event)=>{
|
|
126
|
+
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
|
|
127
|
+
const contractClass = await event.toContractClassPublic();
|
|
128
|
+
state.addClass(event.contractClassId, contractClass);
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
addContractInstancesFromEvents(contractInstanceEvents, state) {
|
|
132
|
+
contractInstanceEvents.forEach((e)=>{
|
|
133
|
+
this.log.debug(`Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to contract state`);
|
|
134
|
+
state.addInstance(e.address, e.toContractInstance());
|
|
135
|
+
});
|
|
136
|
+
}
|
|
188
137
|
}
|
|
189
138
|
/**
|
|
190
139
|
* A high-level class that provides access to the merkle trees.
|