@aztec/simulator 0.82.2 → 0.82.3-nightly.20250330
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/README.md +6 -0
- package/dest/private/acvm/oracle/oracle.d.ts +2 -1
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +7 -4
- package/dest/private/acvm/oracle/typed_oracle.d.ts +3 -2
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/typed_oracle.js +3 -0
- package/dest/private/execution_data_provider.d.ts +12 -2
- package/dest/private/execution_data_provider.d.ts.map +1 -1
- package/dest/private/unconstrained_execution_oracle.d.ts +3 -1
- package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
- package/dest/private/unconstrained_execution_oracle.js +3 -0
- package/dest/public/avm/avm_contract_call_result.d.ts +4 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +9 -5
- package/dest/public/avm/avm_machine_state.d.ts +2 -0
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +2 -0
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +5 -6
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +0 -5
- package/dest/public/avm/fixtures/index.d.ts +1 -0
- package/dest/public/avm/fixtures/index.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.js +1 -1
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +3 -2
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/avm/fixtures/simple_contract_data_source.js +30 -6
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +2 -0
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +8 -10
- package/dest/public/avm/serialization/instruction_serialization.d.ts +5 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +25 -7
- package/dest/public/executor_metrics.d.ts +11 -3
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +40 -6
- package/dest/public/executor_metrics_interface.d.ts +10 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -6
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +39 -19
- package/dest/public/hinting_db_sources.d.ts +26 -3
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +102 -1
- package/dest/public/index.d.ts +1 -1
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +2 -3
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +26 -16
- package/dest/public/public_processor/public_processor.d.ts +4 -4
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +7 -28
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts +9 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.js +237 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts +7 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.js +109 -0
- package/dest/public/public_tx_simulator/index.d.ts +3 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +23 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +58 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +9 -7
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +16 -16
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +24 -64
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +19 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
- package/dest/public/test_executor_metrics.d.ts +43 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +158 -0
- package/package.json +14 -14
- package/src/private/acvm/oracle/oracle.ts +24 -3
- package/src/private/acvm/oracle/typed_oracle.ts +13 -2
- package/src/private/execution_data_provider.ts +25 -2
- package/src/private/unconstrained_execution_oracle.ts +20 -1
- package/src/public/avm/avm_contract_call_result.ts +15 -3
- package/src/public/avm/avm_machine_state.ts +5 -0
- package/src/public/avm/avm_simulator.ts +18 -7
- package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -7
- package/src/public/avm/fixtures/index.ts +1 -1
- package/src/public/avm/fixtures/simple_contract_data_source.ts +33 -6
- package/src/public/avm/opcodes/external_calls.ts +3 -0
- package/src/public/avm/opcodes/memory.ts +8 -10
- package/src/public/avm/serialization/instruction_serialization.ts +24 -9
- package/src/public/executor_metrics.ts +54 -6
- package/src/public/executor_metrics_interface.ts +15 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +74 -18
- package/src/public/hinting_db_sources.ts +184 -3
- package/src/public/index.ts +1 -1
- package/src/public/public_db_sources.ts +36 -23
- package/src/public/public_processor/public_processor.ts +8 -28
- package/src/public/public_tx_simulator/apps_tests/amm_test.ts +316 -0
- package/src/public/public_tx_simulator/apps_tests/token_test.ts +138 -0
- package/src/public/public_tx_simulator/index.ts +2 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +111 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +9 -13
- package/src/public/public_tx_simulator/public_tx_simulator.ts +31 -76
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +62 -0
- package/src/public/test_executor_metrics.ts +222 -0
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { AvmBytecodeCommitmentHint, AvmContractClassHint, AvmContractInstanceHint, AvmGetLeafPreimageHintNullifierTree, AvmGetLeafPreimageHintPublicDataTree, AvmGetLeafValueHint, AvmGetPreviousValueIndexHint, AvmGetSiblingPathHint } from '@aztec/stdlib/avm';
|
|
4
|
+
import { AppendOnlyTreeSnapshot, MerkleTreeId, getTreeName } from '@aztec/stdlib/trees';
|
|
5
|
+
import { strict as assert } from 'assert';
|
|
6
|
+
import { PublicTreesDB } from './public_db_sources.js';
|
|
2
7
|
/**
|
|
3
8
|
* A public contracts database that forwards requests and collects AVM hints.
|
|
4
9
|
*/ export class HintingPublicContractsDB {
|
|
@@ -34,3 +39,99 @@ import { AvmBytecodeCommitmentHint, AvmContractClassHint, AvmContractInstanceHin
|
|
|
34
39
|
return await this.db.getDebugFunctionName(contractAddress, selector);
|
|
35
40
|
}
|
|
36
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* A public trees database that forwards requests and collects AVM hints.
|
|
44
|
+
*/ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
45
|
+
hints;
|
|
46
|
+
static log = createLogger('HintingPublicTreesDB');
|
|
47
|
+
constructor(db, hints){
|
|
48
|
+
super(db), this.hints = hints;
|
|
49
|
+
}
|
|
50
|
+
// Getters.
|
|
51
|
+
async getSiblingPath(treeId, index) {
|
|
52
|
+
const path = await super.getSiblingPath(treeId, index);
|
|
53
|
+
const key = await this.getHintKey(treeId);
|
|
54
|
+
this.hints.getSiblingPathHints.push(new AvmGetSiblingPathHint(key, treeId, index, path.toFields()));
|
|
55
|
+
return Promise.resolve(path);
|
|
56
|
+
}
|
|
57
|
+
async getPreviousValueIndex(treeId, value) {
|
|
58
|
+
const result = await super.getPreviousValueIndex(treeId, value);
|
|
59
|
+
if (result === undefined) {
|
|
60
|
+
throw new Error(`getPreviousValueIndex(${getTreeName(treeId)}, ${value}}) returned undefined. Possible wrong tree setup or corrupted state.`);
|
|
61
|
+
}
|
|
62
|
+
const key = await this.getHintKey(treeId);
|
|
63
|
+
this.hints.getPreviousValueIndexHints.push(new AvmGetPreviousValueIndexHint(key, treeId, new Fr(value), result.index, result.alreadyPresent));
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
async getLeafPreimage(treeId, index) {
|
|
67
|
+
const preimage = await super.getLeafPreimage(treeId, index);
|
|
68
|
+
if (preimage) {
|
|
69
|
+
const key = await this.getHintKey(treeId);
|
|
70
|
+
switch(treeId){
|
|
71
|
+
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
72
|
+
this.hints.getLeafPreimageHintsPublicDataTree.push(new AvmGetLeafPreimageHintPublicDataTree(key, index, preimage.asLeaf(), preimage.getNextIndex(), new Fr(preimage.getNextKey())));
|
|
73
|
+
break;
|
|
74
|
+
case MerkleTreeId.NULLIFIER_TREE:
|
|
75
|
+
this.hints.getLeafPreimageHintsNullifierTree.push(new AvmGetLeafPreimageHintNullifierTree(key, index, preimage.asLeaf(), preimage.getNextIndex(), new Fr(preimage.getNextKey())));
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
// Use getLeafValue for the other trees.
|
|
79
|
+
throw new Error('getLeafPreimage only supported for PublicDataTree and NullifierTree!');
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return preimage;
|
|
84
|
+
}
|
|
85
|
+
async getLeafValue(treeId, index) {
|
|
86
|
+
// Use getLeafPreimage for PublicDataTree and NullifierTree.
|
|
87
|
+
assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
88
|
+
const value = await super.getLeafValue(treeId, index);
|
|
89
|
+
if (value) {
|
|
90
|
+
const key = await this.getHintKey(treeId);
|
|
91
|
+
// We can cast to Fr because we know the type of the tree.
|
|
92
|
+
this.hints.getLeafValueHints.push(new AvmGetLeafValueHint(key, treeId, index, value));
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
// State modification.
|
|
97
|
+
async sequentialInsert(treeId, leaves) {
|
|
98
|
+
HintingPublicTreesDB.log.debug('sequentialInsert not hinted yet!');
|
|
99
|
+
const beforeState = await this.getHintKey(treeId);
|
|
100
|
+
const result = await super.sequentialInsert(treeId, leaves);
|
|
101
|
+
const afterState = await this.getHintKey(treeId);
|
|
102
|
+
HintingPublicTreesDB.log.debug(`Evolved tree state (${getTreeName(treeId)}): ${beforeState.root}, ${beforeState.nextAvailableLeafIndex} -> ${afterState.root}, ${afterState.nextAvailableLeafIndex}.`);
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
async revertCheckpoint() {
|
|
106
|
+
HintingPublicTreesDB.log.debug('revertCheckpoint not hinted yet!');
|
|
107
|
+
// TODO(fcarreiro): we probably want to hint on StateReference hash.
|
|
108
|
+
// WARNING: is this enough? we might actually need the number of the checkpoint or similar...
|
|
109
|
+
// We will need to keep a stack of checkpoints on the C++ side.
|
|
110
|
+
const beforeState = {
|
|
111
|
+
[MerkleTreeId.PUBLIC_DATA_TREE]: await this.getHintKey(MerkleTreeId.PUBLIC_DATA_TREE),
|
|
112
|
+
[MerkleTreeId.NULLIFIER_TREE]: await this.getHintKey(MerkleTreeId.NULLIFIER_TREE),
|
|
113
|
+
[MerkleTreeId.NOTE_HASH_TREE]: await this.getHintKey(MerkleTreeId.NOTE_HASH_TREE),
|
|
114
|
+
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.getHintKey(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
|
|
115
|
+
[MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE)
|
|
116
|
+
};
|
|
117
|
+
await super.revertCheckpoint();
|
|
118
|
+
const afterState = {
|
|
119
|
+
[MerkleTreeId.PUBLIC_DATA_TREE]: await this.getHintKey(MerkleTreeId.PUBLIC_DATA_TREE),
|
|
120
|
+
[MerkleTreeId.NULLIFIER_TREE]: await this.getHintKey(MerkleTreeId.NULLIFIER_TREE),
|
|
121
|
+
[MerkleTreeId.NOTE_HASH_TREE]: await this.getHintKey(MerkleTreeId.NOTE_HASH_TREE),
|
|
122
|
+
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.getHintKey(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
|
|
123
|
+
[MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE)
|
|
124
|
+
};
|
|
125
|
+
HintingPublicTreesDB.log.debug('Evolved tree state:');
|
|
126
|
+
for (const treeId of Object.keys(beforeState)){
|
|
127
|
+
const id = treeId;
|
|
128
|
+
const treeName = getTreeName(id);
|
|
129
|
+
HintingPublicTreesDB.log.debug(`${treeName}: ${beforeState[id].root}, ${beforeState[id].nextAvailableLeafIndex} -> ${afterState[id].root}, ${afterState[id].nextAvailableLeafIndex}.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Private methods.
|
|
133
|
+
async getHintKey(treeId) {
|
|
134
|
+
const treeInfo = await super.getTreeInfo(treeId);
|
|
135
|
+
return new AppendOnlyTreeSnapshot(Fr.fromBuffer(treeInfo.root), Number(treeInfo.size));
|
|
136
|
+
}
|
|
137
|
+
}
|
package/dest/public/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '../common/db_interfaces.js';
|
|
2
|
-
export * from './public_tx_simulator/
|
|
2
|
+
export * from './public_tx_simulator/index.js';
|
|
3
3
|
export * from './public_db_sources.js';
|
|
4
4
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
5
5
|
export { SideEffectTrace } from './side_effect_trace.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/public/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/public/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AACjG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAC"}
|
package/dest/public/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '../common/db_interfaces.js';
|
|
2
|
-
export * from './public_tx_simulator/
|
|
2
|
+
export * from './public_tx_simulator/index.js';
|
|
3
3
|
export * from './public_db_sources.js';
|
|
4
4
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
5
5
|
export { SideEffectTrace } from './side_effect_trace.js';
|
|
@@ -5,7 +5,7 @@ import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/tre
|
|
|
5
5
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
import { type ContractClassPublic, type ContractDataSource, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
8
|
-
import type { BatchInsertionResult, IndexedTreeId, MerkleTreeLeafType,
|
|
8
|
+
import type { BatchInsertionResult, IndexedTreeId, MerkleTreeLeafType, MerkleTreeWriteOperations, SequentialInsertionResult, TreeInfo } from '@aztec/stdlib/interfaces/server';
|
|
9
9
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
10
10
|
import type { BlockHeader, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
11
11
|
import type { PublicContractsDBInterface, PublicStateDBInterface } from '../common/db_interfaces.js';
|
|
@@ -126,7 +126,7 @@ declare class ForwardMerkleTree implements MerkleTreeWriteOperations {
|
|
|
126
126
|
* A class that provides access to the merkle trees, and other helper methods.
|
|
127
127
|
*/
|
|
128
128
|
export declare class PublicTreesDB extends ForwardMerkleTree implements PublicStateDBInterface {
|
|
129
|
-
db
|
|
129
|
+
private readonly db;
|
|
130
130
|
private logger;
|
|
131
131
|
constructor(db: MerkleTreeWriteOperations);
|
|
132
132
|
/**
|
|
@@ -148,6 +148,5 @@ export declare class PublicTreesDB extends ForwardMerkleTree implements PublicSt
|
|
|
148
148
|
getNoteHash(leafIndex: bigint): Promise<Fr | undefined>;
|
|
149
149
|
getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
|
|
150
150
|
}
|
|
151
|
-
export declare function readPublicState(db: MerkleTreeReadOperations, contract: AztecAddress, slot: Fr): Promise<Fr>;
|
|
152
151
|
export {};
|
|
153
152
|
//# sourceMappingURL=public_db_sources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/public_db_sources.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAEjC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"public_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/public_db_sources.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAEjC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,QAAQ,EACT,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAmC,MAAM,qBAAqB,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGrG;;;;;GAKG;AACH,qBAAa,iBAAkB,YAA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3E,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAc9D,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAcvD,iBAAiB,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAmB3E"}
|
|
@@ -260,7 +260,16 @@ import { TxContractCache } from './tx_contract_cache.js';
|
|
|
260
260
|
* @param slot - Slot to read in the contract storage.
|
|
261
261
|
* @returns The current value in the storage slot.
|
|
262
262
|
*/ async storageRead(contract, slot) {
|
|
263
|
-
|
|
263
|
+
const leafSlot = (await computePublicDataTreeLeafSlot(contract, slot)).toBigInt();
|
|
264
|
+
const lowLeafResult = await this.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
265
|
+
if (!lowLeafResult) {
|
|
266
|
+
throw new Error('Low leaf not found');
|
|
267
|
+
}
|
|
268
|
+
// TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
|
|
269
|
+
await this.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
270
|
+
// Unconditionally fetching the preimage for the hints. Move it to the hinting layer?
|
|
271
|
+
const preimage = await this.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
272
|
+
return lowLeafResult.alreadyPresent ? preimage.value : Fr.ZERO;
|
|
264
273
|
}
|
|
265
274
|
/**
|
|
266
275
|
* Records a write to public storage.
|
|
@@ -271,13 +280,15 @@ import { TxContractCache } from './tx_contract_cache.js';
|
|
|
271
280
|
*/ async storageWrite(contract, slot, newValue) {
|
|
272
281
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
273
282
|
const publicDataWrite = new PublicDataWrite(leafSlot, newValue);
|
|
274
|
-
await this.
|
|
283
|
+
await this.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
|
|
275
284
|
publicDataWrite.toBuffer()
|
|
276
285
|
]);
|
|
277
286
|
}
|
|
278
287
|
async getL1ToL2LeafValue(leafIndex) {
|
|
279
288
|
const timer = new Timer();
|
|
280
|
-
const leafValue = await this.
|
|
289
|
+
const leafValue = await this.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
|
|
290
|
+
// TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
|
|
291
|
+
await this.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
|
|
281
292
|
this.logger.debug(`[DB] Fetched L1 to L2 message leaf value`, {
|
|
282
293
|
eventName: 'public-db-access',
|
|
283
294
|
duration: timer.ms(),
|
|
@@ -287,7 +298,9 @@ import { TxContractCache } from './tx_contract_cache.js';
|
|
|
287
298
|
}
|
|
288
299
|
async getNoteHash(leafIndex) {
|
|
289
300
|
const timer = new Timer();
|
|
290
|
-
const leafValue = await this.
|
|
301
|
+
const leafValue = await this.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
302
|
+
// TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
|
|
303
|
+
await this.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
291
304
|
this.logger.debug(`[DB] Fetched note hash leaf value`, {
|
|
292
305
|
eventName: 'public-db-access',
|
|
293
306
|
duration: timer.ms(),
|
|
@@ -297,9 +310,15 @@ import { TxContractCache } from './tx_contract_cache.js';
|
|
|
297
310
|
}
|
|
298
311
|
async getNullifierIndex(nullifier) {
|
|
299
312
|
const timer = new Timer();
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
313
|
+
const lowLeafResult = await this.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
314
|
+
if (!lowLeafResult) {
|
|
315
|
+
throw new Error('Low leaf not found');
|
|
316
|
+
}
|
|
317
|
+
// TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
|
|
318
|
+
await this.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, lowLeafResult.index);
|
|
319
|
+
// TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
|
|
320
|
+
await this.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, lowLeafResult.index);
|
|
321
|
+
const index = lowLeafResult.alreadyPresent ? lowLeafResult.index : undefined;
|
|
303
322
|
this.logger.debug(`[DB] Fetched nullifier index`, {
|
|
304
323
|
eventName: 'public-db-access',
|
|
305
324
|
duration: timer.ms(),
|
|
@@ -308,12 +327,3 @@ import { TxContractCache } from './tx_contract_cache.js';
|
|
|
308
327
|
return index;
|
|
309
328
|
}
|
|
310
329
|
}
|
|
311
|
-
export async function readPublicState(db, contract, slot) {
|
|
312
|
-
const leafSlot = (await computePublicDataTreeLeafSlot(contract, slot)).toBigInt();
|
|
313
|
-
const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
314
|
-
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
315
|
-
return Fr.ZERO;
|
|
316
|
-
}
|
|
317
|
-
const preimage = await db.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
318
|
-
return preimage.value;
|
|
319
|
-
}
|
|
@@ -7,7 +7,7 @@ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server'
|
|
|
7
7
|
import { type FailedTx, GlobalVariables, NestedProcessReturnValues, type ProcessedTx, Tx, type TxValidator } from '@aztec/stdlib/tx';
|
|
8
8
|
import { type TelemetryClient, type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
9
9
|
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
10
|
-
import { PublicTxSimulator } from '../public_tx_simulator/
|
|
10
|
+
import { type PublicTxSimulator } from '../public_tx_simulator/index.js';
|
|
11
11
|
/**
|
|
12
12
|
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
13
13
|
*/
|
|
@@ -43,7 +43,8 @@ export declare class PublicProcessor implements Traceable {
|
|
|
43
43
|
/**
|
|
44
44
|
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
45
45
|
* @param txs - Txs to process.
|
|
46
|
-
* @param
|
|
46
|
+
* @param limits - Limits for processing the txs.
|
|
47
|
+
* @param validator - Pre-process validator and nullifier cache to use for processing the txs.
|
|
47
48
|
* @returns The list of processed txs with their circuit simulation outputs.
|
|
48
49
|
*/
|
|
49
50
|
process(txs: Iterable<Tx> | AsyncIterable<Tx>, limits?: {
|
|
@@ -51,9 +52,8 @@ export declare class PublicProcessor implements Traceable {
|
|
|
51
52
|
maxBlockSize?: number;
|
|
52
53
|
maxBlockGas?: Gas;
|
|
53
54
|
deadline?: Date;
|
|
54
|
-
},
|
|
55
|
+
}, validator?: {
|
|
55
56
|
preprocessValidator?: TxValidator<Tx>;
|
|
56
|
-
postprocessValidator?: TxValidator<ProcessedTx>;
|
|
57
57
|
nullifierCache?: {
|
|
58
58
|
addNullifiers: (nullifiers: Buffer[]) => void;
|
|
59
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EACL,KAAK,QAAQ,EACb,eAAe,EACf,yBAAyB,EACzB,KAAK,WAAW,EAChB,EAAE,EAEF,KAAK,WAAW,EAGjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EACL,KAAK,QAAQ,EACb,eAAe,EACf,yBAAyB,EACzB,KAAK,WAAW,EAChB,EAAE,EAEF,KAAK,WAAW,EAGjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,KAAK,iBAAiB,EAA8B,MAAM,iCAAiC,CAAC;AAGrG;;GAEG;AACH,qBAAa,sBAAsB;IAE/B,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,eAAe;gBAFf,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC;IAGjE;;;;;;OAMG;IACI,MAAM,CACX,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,GAC1B,eAAe;IAsBlB,SAAS,CAAC,uBAAuB,CAC/B,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,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wB;CA8CvC"}
|
|
@@ -19,7 +19,7 @@ import { NestedProcessReturnValues, Tx, TxExecutionPhase, makeProcessedTxFromPri
|
|
|
19
19
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
20
20
|
import { ForkCheckpoint } from '@aztec/world-state/native';
|
|
21
21
|
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
22
|
-
import {
|
|
22
|
+
import { TelemetryPublicTxSimulator } from '../public_tx_simulator/index.js';
|
|
23
23
|
import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
24
24
|
/**
|
|
25
25
|
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
@@ -45,7 +45,7 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
|
45
45
|
return new PublicProcessor(globalVariables, treesDB, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient);
|
|
46
46
|
}
|
|
47
47
|
createPublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient) {
|
|
48
|
-
return new
|
|
48
|
+
return new TelemetryPublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
class PublicProcessorTimeoutError extends Error {
|
|
@@ -80,11 +80,12 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
80
80
|
/**
|
|
81
81
|
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
82
82
|
* @param txs - Txs to process.
|
|
83
|
-
* @param
|
|
83
|
+
* @param limits - Limits for processing the txs.
|
|
84
|
+
* @param validator - Pre-process validator and nullifier cache to use for processing the txs.
|
|
84
85
|
* @returns The list of processed txs with their circuit simulation outputs.
|
|
85
|
-
*/ async process(txs, limits = {},
|
|
86
|
+
*/ async process(txs, limits = {}, validator = {}) {
|
|
86
87
|
const { maxTransactions, maxBlockSize, deadline, maxBlockGas } = limits;
|
|
87
|
-
const { preprocessValidator,
|
|
88
|
+
const { preprocessValidator, nullifierCache } = validator;
|
|
88
89
|
const result = [];
|
|
89
90
|
const failed = [];
|
|
90
91
|
const timer = new Timer();
|
|
@@ -169,28 +170,6 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
169
170
|
await checkpoint.revert();
|
|
170
171
|
continue;
|
|
171
172
|
}
|
|
172
|
-
// Re-validate the transaction
|
|
173
|
-
if (postprocessValidator) {
|
|
174
|
-
// Only accept processed transactions that are not double-spends,
|
|
175
|
-
// public functions emitting nullifiers would pass earlier check but fail here.
|
|
176
|
-
// Note that we're checking all nullifiers generated in the private execution twice,
|
|
177
|
-
// we could store the ones already checked and skip them here as an optimization.
|
|
178
|
-
// TODO(palla/txs): Can we get into this case? AVM validates this. We should be able to remove it.
|
|
179
|
-
const result = await postprocessValidator.validateTx(processedTx);
|
|
180
|
-
if (result.result !== 'valid') {
|
|
181
|
-
const reason = result.reason.join(', ');
|
|
182
|
-
this.log.error(`Rejecting tx ${processedTx.hash} after processing: ${reason}.`);
|
|
183
|
-
failed.push({
|
|
184
|
-
tx,
|
|
185
|
-
error: new Error(`Tx failed post-process validation: ${reason}`)
|
|
186
|
-
});
|
|
187
|
-
// Need to revert the checkpoint here and don't go any further
|
|
188
|
-
await checkpoint.revert();
|
|
189
|
-
continue;
|
|
190
|
-
} else {
|
|
191
|
-
this.log.trace(`Tx ${txHash.toString()} is valid post processing.`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
173
|
if (!tx.hasPublicCalls()) {
|
|
195
174
|
// If there are no public calls, perform all tree insertions for side effects from private
|
|
196
175
|
// When there are public calls, the PublicTxSimulator & AVM handle tree insertions.
|
|
@@ -347,7 +326,7 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
347
326
|
if (phase.reverted) {
|
|
348
327
|
this.metrics.recordRevertedPhase(phase.phase);
|
|
349
328
|
} else {
|
|
350
|
-
this.metrics.recordPhaseDuration(phase.phase, phase.durationMs);
|
|
329
|
+
this.metrics.recordPhaseDuration(phase.phase, phase.durationMs ?? 0);
|
|
351
330
|
}
|
|
352
331
|
});
|
|
353
332
|
const siloedContractClassLogs = await tx.filterContractClassLogs(tx.data.getNonEmptyContractClassLogsHashes(), true);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { PublicTxSimulationTester } from '../../fixtures/public_tx_simulation_tester.js';
|
|
3
|
+
/**
|
|
4
|
+
* THIS TEST IS BRITTLE! If it breaks, don't try fixing it.
|
|
5
|
+
* `.skip` it or literally just delete it and notify AVM team.
|
|
6
|
+
* You do NOT need permission to remove this test!
|
|
7
|
+
*/
|
|
8
|
+
export declare function ammTest(tester: PublicTxSimulationTester, logger: Logger): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=amm_test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amm_test.d.ts","sourceRoot":"","sources":["../../../../src/public/public_tx_simulator/apps_tests/amm_test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAIzF;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,iBAoG7E"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { AMMContractArtifact } from '@aztec/noir-contracts.js/AMM';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { deployToken } from './token_test.js';
|
|
5
|
+
const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
|
|
6
|
+
/**
|
|
7
|
+
* THIS TEST IS BRITTLE! If it breaks, don't try fixing it.
|
|
8
|
+
* `.skip` it or literally just delete it and notify AVM team.
|
|
9
|
+
* You do NOT need permission to remove this test!
|
|
10
|
+
*/ export async function ammTest(tester, logger) {
|
|
11
|
+
const startTime = performance.now();
|
|
12
|
+
const admin = AztecAddress.fromNumber(42);
|
|
13
|
+
const sender = AztecAddress.fromNumber(111);
|
|
14
|
+
logger.debug(`Deploying tokens`);
|
|
15
|
+
const token0 = await deployToken(tester, admin, /*seed=*/ 0);
|
|
16
|
+
const token1 = await deployToken(tester, admin, /*seed=*/ 1);
|
|
17
|
+
const liquidityToken = await deployToken(tester, admin, /*seed=*/ 2);
|
|
18
|
+
logger.debug(`Deploying AMM`);
|
|
19
|
+
const constructorArgs = [
|
|
20
|
+
token0,
|
|
21
|
+
token1,
|
|
22
|
+
liquidityToken
|
|
23
|
+
];
|
|
24
|
+
const amm = await tester.registerAndDeployContract(constructorArgs, /*deployer=*/ admin, AMMContractArtifact, /*skipNullifierInsertion=*/ false, /*seed=*/ 3);
|
|
25
|
+
const ammConstructorResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'constructor', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
26
|
+
{
|
|
27
|
+
fnName: 'constructor',
|
|
28
|
+
args: constructorArgs,
|
|
29
|
+
address: amm.address
|
|
30
|
+
}
|
|
31
|
+
]);
|
|
32
|
+
expect(ammConstructorResult.revertCode.isOK()).toBe(true);
|
|
33
|
+
logger.debug(`Setting AMM as minter for liquidity token`);
|
|
34
|
+
// set the AMM as the minter for the liquidity token
|
|
35
|
+
const setMinterResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'set_minter', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
36
|
+
{
|
|
37
|
+
fnName: 'set_minter',
|
|
38
|
+
args: [
|
|
39
|
+
/*minter=*/ amm,
|
|
40
|
+
/*approve=*/ true
|
|
41
|
+
],
|
|
42
|
+
address: liquidityToken.address
|
|
43
|
+
}
|
|
44
|
+
]);
|
|
45
|
+
expect(setMinterResult.revertCode.isOK()).toBe(true);
|
|
46
|
+
logger.debug(`Adding liquidity`);
|
|
47
|
+
const amount0Max = INITIAL_TOKEN_BALANCE * 6n / 10n;
|
|
48
|
+
const amount0Min = INITIAL_TOKEN_BALANCE * 4n / 10n;
|
|
49
|
+
const amount1Max = INITIAL_TOKEN_BALANCE * 5n / 10n;
|
|
50
|
+
const amount1Min = INITIAL_TOKEN_BALANCE * 4n / 10n;
|
|
51
|
+
const addLiquidityResult = await addLiquidity(tester, sender, /*amm=*/ amm, /*token0=*/ token0, /*token1=*/ token1, /*liquidityToken=*/ liquidityToken, /*amount0Max=*/ amount0Max, /*amount1Max=*/ amount1Max, /*amount0Min=*/ amount0Min, /*amount1Min=*/ amount1Min);
|
|
52
|
+
expect(addLiquidityResult.revertCode.isOK()).toBe(true);
|
|
53
|
+
logger.debug(`Swapping tokens`);
|
|
54
|
+
const swapResult = await swapExactTokensForTokens(tester, sender, /*amm=*/ amm, /*tokenIn=*/ token0, /*tokenOut=*/ token1, /*amountIn=*/ amount0Min / 10n, /*amountOutMin=*/ amount1Min / 100n);
|
|
55
|
+
expect(swapResult.revertCode.isOK()).toBe(true);
|
|
56
|
+
logger.debug(`Removing liquidity`);
|
|
57
|
+
const removeLiquidityResult = await removeLiquidity(tester, sender, /*amm=*/ amm, /*token0=*/ token0, /*token1=*/ token1, /*liquidityToken=*/ liquidityToken, /*liquidity=*/ 100n, /*amount0Min=*/ 1n, /*amount1Min=*/ 1n);
|
|
58
|
+
expect(removeLiquidityResult.revertCode.isOK()).toBe(true);
|
|
59
|
+
const endTime = performance.now();
|
|
60
|
+
logger.info(`AMM public tx simulator test took ${endTime - startTime}ms\n`);
|
|
61
|
+
}
|
|
62
|
+
async function addLiquidity(tester, sender, amm, token0, token1, liquidityToken, amount0Max, amount1Max, amount0Min, amount1Min, _nonce) {
|
|
63
|
+
const refundToken0PartialNote = {
|
|
64
|
+
commitment: new Fr(42)
|
|
65
|
+
};
|
|
66
|
+
const refundToken1PartialNote = {
|
|
67
|
+
commitment: new Fr(66)
|
|
68
|
+
};
|
|
69
|
+
const liquidityPartialNote = {
|
|
70
|
+
commitment: new Fr(99)
|
|
71
|
+
};
|
|
72
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'add_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
73
|
+
// token0.transfer_to_public enqueues a call to _increase_public_balance
|
|
74
|
+
{
|
|
75
|
+
sender: token0.address,
|
|
76
|
+
fnName: '_increase_public_balance',
|
|
77
|
+
args: [
|
|
78
|
+
/*to=*/ amm.address,
|
|
79
|
+
/*amount=*/ amount0Max
|
|
80
|
+
],
|
|
81
|
+
address: token0.address
|
|
82
|
+
},
|
|
83
|
+
// token0.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
84
|
+
{
|
|
85
|
+
sender: token0.address,
|
|
86
|
+
fnName: '_store_balances_set_partial_note',
|
|
87
|
+
args: [
|
|
88
|
+
refundToken0PartialNote
|
|
89
|
+
],
|
|
90
|
+
address: token0.address
|
|
91
|
+
},
|
|
92
|
+
// token1.transfer_to_public enqueues a call to _increase_public_balance
|
|
93
|
+
{
|
|
94
|
+
sender: token1.address,
|
|
95
|
+
fnName: '_increase_public_balance',
|
|
96
|
+
args: [
|
|
97
|
+
/*to=*/ amm.address,
|
|
98
|
+
/*amount=*/ amount1Max
|
|
99
|
+
],
|
|
100
|
+
address: token1.address
|
|
101
|
+
},
|
|
102
|
+
// token1.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
103
|
+
{
|
|
104
|
+
sender: token1.address,
|
|
105
|
+
fnName: '_store_balances_set_partial_note',
|
|
106
|
+
args: [
|
|
107
|
+
refundToken1PartialNote
|
|
108
|
+
],
|
|
109
|
+
address: token1.address
|
|
110
|
+
},
|
|
111
|
+
// liquidityToken.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
112
|
+
{
|
|
113
|
+
sender: liquidityToken.address,
|
|
114
|
+
fnName: '_store_balances_set_partial_note',
|
|
115
|
+
args: [
|
|
116
|
+
liquidityPartialNote
|
|
117
|
+
],
|
|
118
|
+
address: liquidityToken.address
|
|
119
|
+
},
|
|
120
|
+
// amm.add_liquidity enqueues a call to _add_liquidity
|
|
121
|
+
{
|
|
122
|
+
sender: amm.address,
|
|
123
|
+
fnName: '_add_liquidity',
|
|
124
|
+
args: [
|
|
125
|
+
/*config=*/ {
|
|
126
|
+
token0: token0.address,
|
|
127
|
+
token1: token1.address,
|
|
128
|
+
// eslint-disable-next-line camelcase
|
|
129
|
+
liquidity_token: liquidityToken.address
|
|
130
|
+
},
|
|
131
|
+
refundToken0PartialNote,
|
|
132
|
+
refundToken1PartialNote,
|
|
133
|
+
liquidityPartialNote,
|
|
134
|
+
amount0Max,
|
|
135
|
+
amount1Max,
|
|
136
|
+
amount0Min,
|
|
137
|
+
amount1Min
|
|
138
|
+
],
|
|
139
|
+
address: amm.address
|
|
140
|
+
}
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
async function swapExactTokensForTokens(tester, sender, amm, tokenIn, tokenOut, amountIn, amountOutMin, _nonce) {
|
|
144
|
+
const tokenOutPartialNote = {
|
|
145
|
+
commitment: new Fr(66)
|
|
146
|
+
};
|
|
147
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'swap_exact_tokens_for_tokens', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
148
|
+
// tokenIn.transfer_to_public enqueues a call to _increase_public_balance
|
|
149
|
+
{
|
|
150
|
+
sender: tokenIn.address,
|
|
151
|
+
fnName: '_increase_public_balance',
|
|
152
|
+
args: [
|
|
153
|
+
/*to=*/ amm.address,
|
|
154
|
+
/*amount=*/ amountIn
|
|
155
|
+
],
|
|
156
|
+
address: tokenIn.address
|
|
157
|
+
},
|
|
158
|
+
// tokenOut.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
159
|
+
{
|
|
160
|
+
sender: tokenOut.address,
|
|
161
|
+
fnName: '_store_balances_set_partial_note',
|
|
162
|
+
args: [
|
|
163
|
+
tokenOutPartialNote
|
|
164
|
+
],
|
|
165
|
+
address: tokenOut.address
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
sender: amm.address,
|
|
169
|
+
fnName: '_swap_exact_tokens_for_tokens',
|
|
170
|
+
args: [
|
|
171
|
+
tokenIn.address,
|
|
172
|
+
tokenOut.address,
|
|
173
|
+
amountIn,
|
|
174
|
+
amountOutMin,
|
|
175
|
+
tokenOutPartialNote
|
|
176
|
+
],
|
|
177
|
+
address: amm.address
|
|
178
|
+
}
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
async function removeLiquidity(tester, sender, amm, token0, token1, liquidityToken, liquidity, amount0Min, amount1Min, _nonce) {
|
|
182
|
+
const token0PartialNote = {
|
|
183
|
+
commitment: new Fr(111)
|
|
184
|
+
};
|
|
185
|
+
const token1PartialNote = {
|
|
186
|
+
commitment: new Fr(222)
|
|
187
|
+
};
|
|
188
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'remove_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
189
|
+
// liquidityToken.transfer_to_public enqueues a call to _increase_public_balance
|
|
190
|
+
{
|
|
191
|
+
sender: liquidityToken.address,
|
|
192
|
+
fnName: '_increase_public_balance',
|
|
193
|
+
args: [
|
|
194
|
+
/*to=*/ amm.address,
|
|
195
|
+
/*amount=*/ liquidity
|
|
196
|
+
],
|
|
197
|
+
address: liquidityToken.address
|
|
198
|
+
},
|
|
199
|
+
// token0.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
200
|
+
{
|
|
201
|
+
sender: token0.address,
|
|
202
|
+
fnName: '_store_balances_set_partial_note',
|
|
203
|
+
args: [
|
|
204
|
+
token0PartialNote
|
|
205
|
+
],
|
|
206
|
+
address: token0.address
|
|
207
|
+
},
|
|
208
|
+
// token1.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
209
|
+
{
|
|
210
|
+
sender: token1.address,
|
|
211
|
+
fnName: '_store_balances_set_partial_note',
|
|
212
|
+
args: [
|
|
213
|
+
token1PartialNote
|
|
214
|
+
],
|
|
215
|
+
address: token1.address
|
|
216
|
+
},
|
|
217
|
+
// amm.remove_liquidity enqueues a call to _remove_liquidity
|
|
218
|
+
{
|
|
219
|
+
sender: amm.address,
|
|
220
|
+
fnName: '_remove_liquidity',
|
|
221
|
+
args: [
|
|
222
|
+
/*config=*/ {
|
|
223
|
+
token0: token0.address,
|
|
224
|
+
token1: token1.address,
|
|
225
|
+
// eslint-disable-next-line camelcase
|
|
226
|
+
liquidity_token: liquidityToken.address
|
|
227
|
+
},
|
|
228
|
+
liquidity,
|
|
229
|
+
token0PartialNote,
|
|
230
|
+
token1PartialNote,
|
|
231
|
+
amount0Min,
|
|
232
|
+
amount1Min
|
|
233
|
+
],
|
|
234
|
+
address: amm.address
|
|
235
|
+
}
|
|
236
|
+
]);
|
|
237
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
4
|
+
import { PublicTxSimulationTester } from '../../fixtures/public_tx_simulation_tester.js';
|
|
5
|
+
export declare function tokenTest(tester: PublicTxSimulationTester, logger: Logger): Promise<void>;
|
|
6
|
+
export declare function deployToken(tester: PublicTxSimulationTester, admin: AztecAddress, seed?: number): Promise<ContractInstanceWithAddress>;
|
|
7
|
+
//# sourceMappingURL=token_test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token_test.d.ts","sourceRoot":"","sources":["../../../../src/public/public_tx_simulator/apps_tests/token_test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAEzF,wBAAsB,SAAS,CAAC,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,iBA4E/E;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,wBAAwB,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,SAAI,wCAwBhG"}
|