@aztec/txe 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9

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.
Files changed (98) hide show
  1. package/dest/bin/index.d.ts +1 -1
  2. package/dest/bin/index.js +1 -1
  3. package/dest/constants.d.ts +3 -0
  4. package/dest/constants.d.ts.map +1 -0
  5. package/dest/constants.js +2 -0
  6. package/dest/index.d.ts +1 -1
  7. package/dest/index.d.ts.map +1 -1
  8. package/dest/index.js +90 -54
  9. package/dest/oracle/interfaces.d.ts +57 -0
  10. package/dest/oracle/interfaces.d.ts.map +1 -0
  11. package/dest/oracle/interfaces.js +3 -0
  12. package/dest/oracle/txe_oracle_public_context.d.ts +14 -14
  13. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_public_context.js +36 -40
  15. package/dest/oracle/txe_oracle_top_level_context.d.ts +65 -0
  16. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
  17. package/dest/oracle/txe_oracle_top_level_context.js +530 -0
  18. package/dest/rpc_translator.d.ts +252 -0
  19. package/dest/rpc_translator.d.ts.map +1 -0
  20. package/dest/{txe_service/txe_service.js → rpc_translator.js} +258 -156
  21. package/dest/state_machine/archiver.d.ts +21 -51
  22. package/dest/state_machine/archiver.d.ts.map +1 -1
  23. package/dest/state_machine/archiver.js +63 -94
  24. package/dest/state_machine/dummy_p2p_client.d.ts +20 -13
  25. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  26. package/dest/state_machine/dummy_p2p_client.js +41 -21
  27. package/dest/state_machine/global_variable_builder.d.ts +6 -17
  28. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  29. package/dest/state_machine/global_variable_builder.js +16 -23
  30. package/dest/state_machine/index.d.ts +7 -7
  31. package/dest/state_machine/index.d.ts.map +1 -1
  32. package/dest/state_machine/index.js +42 -24
  33. package/dest/state_machine/mock_epoch_cache.d.ts +14 -10
  34. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  35. package/dest/state_machine/mock_epoch_cache.js +21 -13
  36. package/dest/state_machine/synchronizer.d.ts +3 -2
  37. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  38. package/dest/state_machine/synchronizer.js +5 -4
  39. package/dest/txe_session.d.ts +44 -48
  40. package/dest/txe_session.d.ts.map +1 -1
  41. package/dest/txe_session.js +314 -98
  42. package/dest/util/encoding.d.ts +616 -17
  43. package/dest/util/encoding.d.ts.map +1 -1
  44. package/dest/util/encoding.js +1 -1
  45. package/dest/util/expected_failure_error.d.ts +1 -1
  46. package/dest/util/expected_failure_error.d.ts.map +1 -1
  47. package/dest/util/txe_account_store.d.ts +10 -0
  48. package/dest/util/txe_account_store.d.ts.map +1 -0
  49. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  50. package/dest/util/txe_public_contract_data_source.d.ts +9 -8
  51. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  52. package/dest/util/txe_public_contract_data_source.js +15 -30
  53. package/dest/utils/block_creation.d.ts +28 -0
  54. package/dest/utils/block_creation.d.ts.map +1 -0
  55. package/dest/utils/block_creation.js +58 -0
  56. package/dest/utils/tx_effect_creation.d.ts +5 -0
  57. package/dest/utils/tx_effect_creation.d.ts.map +1 -0
  58. package/dest/utils/tx_effect_creation.js +13 -0
  59. package/package.json +18 -17
  60. package/src/bin/index.ts +1 -1
  61. package/src/constants.ts +3 -0
  62. package/src/index.ts +102 -68
  63. package/src/oracle/interfaces.ts +86 -0
  64. package/src/oracle/txe_oracle_public_context.ts +40 -80
  65. package/src/oracle/txe_oracle_top_level_context.ts +756 -0
  66. package/src/{txe_service/txe_service.ts → rpc_translator.ts} +323 -161
  67. package/src/state_machine/archiver.ts +63 -117
  68. package/src/state_machine/dummy_p2p_client.ts +58 -28
  69. package/src/state_machine/global_variable_builder.ts +25 -42
  70. package/src/state_machine/index.ts +65 -24
  71. package/src/state_machine/mock_epoch_cache.ts +25 -20
  72. package/src/state_machine/synchronizer.ts +6 -5
  73. package/src/txe_session.ts +441 -121
  74. package/src/util/encoding.ts +1 -1
  75. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  76. package/src/util/txe_public_contract_data_source.ts +23 -46
  77. package/src/utils/block_creation.ts +97 -0
  78. package/src/utils/tx_effect_creation.ts +30 -0
  79. package/dest/oracle/txe_oracle.d.ts +0 -124
  80. package/dest/oracle/txe_oracle.d.ts.map +0 -1
  81. package/dest/oracle/txe_oracle.js +0 -770
  82. package/dest/oracle/txe_typed_oracle.d.ts +0 -42
  83. package/dest/oracle/txe_typed_oracle.d.ts.map +0 -1
  84. package/dest/oracle/txe_typed_oracle.js +0 -83
  85. package/dest/txe_constants.d.ts +0 -2
  86. package/dest/txe_constants.d.ts.map +0 -1
  87. package/dest/txe_constants.js +0 -7
  88. package/dest/txe_service/txe_service.d.ts +0 -231
  89. package/dest/txe_service/txe_service.d.ts.map +0 -1
  90. package/dest/util/txe_account_data_provider.d.ts +0 -10
  91. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  92. package/dest/util/txe_contract_data_provider.d.ts +0 -11
  93. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  94. package/dest/util/txe_contract_data_provider.js +0 -22
  95. package/src/oracle/txe_oracle.ts +0 -1287
  96. package/src/oracle/txe_typed_oracle.ts +0 -142
  97. package/src/txe_constants.ts +0 -9
  98. package/src/util/txe_contract_data_provider.ts +0 -35
@@ -0,0 +1,86 @@
1
+ import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
+ import { CompleteAddress } from '@aztec/aztec.js/addresses';
3
+ import type { ContractInstanceWithAddress } from '@aztec/aztec.js/contracts';
4
+ import { TxHash } from '@aztec/aztec.js/tx';
5
+ import { BlockNumber } from '@aztec/foundation/branded-types';
6
+ import type { Fr } from '@aztec/foundation/curves/bn254';
7
+ import type { EventSelector, FunctionSelector } from '@aztec/stdlib/abi';
8
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
9
+ import type { UInt64 } from '@aztec/stdlib/types';
10
+
11
+ // These interfaces complement the ones defined in PXE, and combined with those contain the full list of oracles used by
12
+ // aztec-nr. In particular, these include the ones needed to run Brillig code associated to #[external("public")] functions that has
13
+ // not been transpiled (e.g. in the context of a Noir test) as well as the ones associated with managing the state of
14
+ // such a Noir test (deploying contracts, manipulating block time, making calls, etc) - the so called 'top level test
15
+ // context'.
16
+
17
+ /**
18
+ * Oracle methods associated with the execution of an Aztec #[external("public")] function.
19
+ *
20
+ * Note that real contracts have their Brillig calls to these be transpiled into opcodes, the oracles are only executed
21
+ * as such when running the original Brillig code, e.g. when invoking functions that interact with a PublicContext
22
+ * directly in a Noir test.
23
+ */
24
+ export interface IAvmExecutionOracle {
25
+ isAvm: true;
26
+
27
+ avmOpcodeAddress(): Promise<AztecAddress>;
28
+ avmOpcodeSender(): Promise<AztecAddress>;
29
+ avmOpcodeBlockNumber(): Promise<BlockNumber>;
30
+ avmOpcodeTimestamp(): Promise<bigint>;
31
+ avmOpcodeIsStaticCall(): Promise<boolean>;
32
+ avmOpcodeChainId(): Promise<Fr>;
33
+ avmOpcodeVersion(): Promise<Fr>;
34
+ avmOpcodeEmitNullifier(nullifier: Fr): Promise<void>;
35
+ avmOpcodeEmitNoteHash(noteHash: Fr): Promise<void>;
36
+ avmOpcodeNullifierExists(siloedNullifier: Fr): Promise<boolean>;
37
+ avmOpcodeStorageWrite(slot: Fr, value: Fr): Promise<void>;
38
+ avmOpcodeStorageRead(slot: Fr, contractAddress: AztecAddress): Promise<Fr>;
39
+ }
40
+
41
+ /**
42
+ * Oracle methods associated with the execution of an Aztec Noir test.
43
+ */
44
+ export interface ITxeExecutionOracle {
45
+ isTxe: true;
46
+
47
+ txeGetDefaultAddress(): AztecAddress;
48
+ txeGetNextBlockNumber(): Promise<BlockNumber>;
49
+ txeGetNextBlockTimestamp(): Promise<UInt64>;
50
+ txeAdvanceBlocksBy(blocks: number): Promise<void>;
51
+ txeAdvanceTimestampBy(duration: UInt64): void;
52
+ txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, foreignSecret: Fr): Promise<void>;
53
+ txeCreateAccount(secret: Fr): Promise<CompleteAddress>;
54
+ txeAddAccount(
55
+ artifact: ContractArtifact,
56
+ instance: ContractInstanceWithAddress,
57
+ secret: Fr,
58
+ ): Promise<CompleteAddress>;
59
+ txeAddAuthWitness(address: AztecAddress, messageHash: Fr): Promise<void>;
60
+ txeGetLastBlockTimestamp(): Promise<bigint>;
61
+ txeGetLastTxEffects(): Promise<{
62
+ txHash: TxHash;
63
+ noteHashes: Fr[];
64
+ nullifiers: Fr[];
65
+ }>;
66
+ txeGetPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress): Promise<Fr[][]>;
67
+ txePrivateCallNewFlow(
68
+ from: AztecAddress,
69
+ targetContractAddress: AztecAddress,
70
+ functionSelector: FunctionSelector,
71
+ args: Fr[],
72
+ argsHash: Fr,
73
+ isStaticCall: boolean,
74
+ ): Promise<Fr[]>;
75
+ txeExecuteUtilityFunction(
76
+ targetContractAddress: AztecAddress,
77
+ functionSelector: FunctionSelector,
78
+ args: Fr[],
79
+ ): Promise<Fr[]>;
80
+ txePublicCallNewFlow(
81
+ from: AztecAddress,
82
+ targetContractAddress: AztecAddress,
83
+ calldata: Fr[],
84
+ isStaticCall: boolean,
85
+ ): Promise<Fr[]>;
86
+ }
@@ -1,30 +1,24 @@
1
- import {
2
- MAX_NOTE_HASHES_PER_TX,
3
- MAX_NULLIFIERS_PER_TX,
4
- NULLIFIER_SUBTREE_HEIGHT,
5
- NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
6
- } from '@aztec/constants';
7
- import { padArrayEnd } from '@aztec/foundation/collection';
8
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
9
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
10
4
  import { PublicDataWrite } from '@aztec/stdlib/avm';
11
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
12
- import { Body, L2Block } from '@aztec/stdlib/block';
5
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import type { L2Block } from '@aztec/stdlib/block';
13
7
  import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
14
- import { makeAppendOnlyTreeSnapshot, makeContentCommitment } from '@aztec/stdlib/testing';
15
8
  import {
16
- AppendOnlyTreeSnapshot,
17
9
  MerkleTreeId,
18
10
  type MerkleTreeWriteOperations,
19
11
  PublicDataTreeLeaf,
20
12
  PublicDataTreeLeafPreimage,
21
13
  } from '@aztec/stdlib/trees';
22
- import { BlockHeader, GlobalVariables, TxEffect, TxHash } from '@aztec/stdlib/tx';
23
- import type { UInt32 } from '@aztec/stdlib/types';
14
+ import { GlobalVariables, TxEffect, TxHash } from '@aztec/stdlib/tx';
15
+
16
+ import { insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
17
+ import type { IAvmExecutionOracle } from './interfaces.js';
24
18
 
25
- import { TXETypedOracle } from './txe_typed_oracle.js';
19
+ export class TXEOraclePublicContext implements IAvmExecutionOracle {
20
+ isAvm = true as const;
26
21
 
27
- export class TXEOraclePublicContext extends TXETypedOracle {
28
22
  private logger: Logger;
29
23
  private transientUniqueNoteHashes: Fr[] = [];
30
24
  private transientSiloedNullifiers: Fr[] = [];
@@ -32,80 +26,83 @@ export class TXEOraclePublicContext extends TXETypedOracle {
32
26
 
33
27
  constructor(
34
28
  private contractAddress: AztecAddress,
35
- private worldTrees: MerkleTreeWriteOperations,
29
+ private forkedWorldTrees: MerkleTreeWriteOperations,
36
30
  private txRequestHash: Fr,
37
31
  private globalVariables: GlobalVariables,
38
32
  ) {
39
- super();
40
33
  this.logger = createLogger('txe:public_context');
41
34
 
42
- this.logger.debug('Entering PublicContext', {
35
+ this.logger.debug('Entering Public Context', {
43
36
  contractAddress,
44
37
  blockNumber: globalVariables.blockNumber,
45
38
  timestamp: globalVariables.timestamp,
46
39
  });
47
40
  }
48
41
 
49
- override avmOpcodeAddress(): Promise<AztecAddress> {
42
+ avmOpcodeAddress(): Promise<AztecAddress> {
50
43
  return Promise.resolve(this.contractAddress);
51
44
  }
52
45
 
53
- override avmOpcodeBlockNumber(): Promise<UInt32> {
46
+ avmOpcodeSender(): Promise<AztecAddress> {
47
+ return Promise.resolve(AztecAddress.ZERO); // todo: change?
48
+ }
49
+
50
+ avmOpcodeBlockNumber(): Promise<BlockNumber> {
54
51
  return Promise.resolve(this.globalVariables.blockNumber);
55
52
  }
56
53
 
57
- override avmOpcodeTimestamp(): Promise<bigint> {
54
+ avmOpcodeTimestamp(): Promise<bigint> {
58
55
  return Promise.resolve(this.globalVariables.timestamp);
59
56
  }
60
57
 
61
- override avmOpcodeIsStaticCall(): Promise<boolean> {
58
+ avmOpcodeIsStaticCall(): Promise<boolean> {
62
59
  return Promise.resolve(false);
63
60
  }
64
61
 
65
- override avmOpcodeChainId(): Promise<Fr> {
62
+ avmOpcodeChainId(): Promise<Fr> {
66
63
  return Promise.resolve(this.globalVariables.chainId);
67
64
  }
68
65
 
69
- override avmOpcodeVersion(): Promise<Fr> {
66
+ avmOpcodeVersion(): Promise<Fr> {
70
67
  return Promise.resolve(this.globalVariables.version);
71
68
  }
72
69
 
73
- override async avmOpcodeEmitNullifier(nullifier: Fr) {
70
+ async avmOpcodeEmitNullifier(nullifier: Fr) {
74
71
  const siloedNullifier = await siloNullifier(this.contractAddress, nullifier);
75
72
  this.transientSiloedNullifiers.push(siloedNullifier);
76
73
  }
77
74
 
78
- override async avmOpcodeEmitNoteHash(noteHash: Fr) {
75
+ async avmOpcodeEmitNoteHash(noteHash: Fr) {
79
76
  const siloedNoteHash = await siloNoteHash(this.contractAddress, noteHash);
80
77
  // TODO: make the note hash unique - they are only siloed right now
81
78
  this.transientUniqueNoteHashes.push(siloedNoteHash);
82
79
  }
83
80
 
84
- override async avmOpcodeNullifierExists(innerNullifier: Fr, targetAddress: AztecAddress): Promise<boolean> {
85
- const nullifier = await siloNullifier(targetAddress, innerNullifier!);
86
-
87
- const treeIndex = (await this.worldTrees.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]))[0];
88
- const transientIndex = this.transientSiloedNullifiers.find(n => n.equals(nullifier));
81
+ async avmOpcodeNullifierExists(siloedNullifier: Fr): Promise<boolean> {
82
+ const treeIndex = (
83
+ await this.forkedWorldTrees.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [siloedNullifier.toBuffer()])
84
+ )[0];
85
+ const transientIndex = this.transientSiloedNullifiers.find(n => n.equals(siloedNullifier));
89
86
 
90
87
  return treeIndex !== undefined || transientIndex !== undefined;
91
88
  }
92
89
 
93
- override async avmOpcodeStorageWrite(slot: Fr, value: Fr) {
90
+ async avmOpcodeStorageWrite(slot: Fr, value: Fr) {
94
91
  this.logger.debug('AVM storage write', { slot, value });
95
92
 
96
93
  const dataWrite = new PublicDataWrite(await computePublicDataTreeLeafSlot(this.contractAddress, slot), value);
97
94
 
98
95
  this.publicDataWrites.push(dataWrite);
99
96
 
100
- await this.worldTrees.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
97
+ await this.forkedWorldTrees.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
101
98
  new PublicDataTreeLeaf(dataWrite.leafSlot, dataWrite.value).toBuffer(),
102
99
  ]);
103
100
  }
104
101
 
105
- override async avmOpcodeStorageRead(slot: Fr): Promise<Fr> {
106
- const leafSlot = await computePublicDataTreeLeafSlot(this.contractAddress, slot);
102
+ async avmOpcodeStorageRead(slot: Fr, contractAddress: AztecAddress): Promise<Fr> {
103
+ const leafSlot = await computePublicDataTreeLeafSlot(contractAddress, slot);
107
104
 
108
- const lowLeafResult = await this.worldTrees.getPreviousValueIndex(
105
+ const lowLeafResult = await this.forkedWorldTrees.getPreviousValueIndex(
109
106
  MerkleTreeId.PUBLIC_DATA_TREE,
110
107
  leafSlot.toBigInt(),
111
108
  );
@@ -114,32 +111,28 @@ export class TXEOraclePublicContext extends TXETypedOracle {
114
111
  !lowLeafResult || !lowLeafResult.alreadyPresent
115
112
  ? Fr.ZERO
116
113
  : (
117
- (await this.worldTrees.getLeafPreimage(
114
+ (await this.forkedWorldTrees.getLeafPreimage(
118
115
  MerkleTreeId.PUBLIC_DATA_TREE,
119
116
  lowLeafResult.index,
120
117
  )) as PublicDataTreeLeafPreimage
121
118
  ).leaf.value;
122
119
 
123
- this.logger.debug('AVM storage read', { slot, value });
120
+ this.logger.debug('AVM storage read', { slot, contractAddress, value });
124
121
 
125
122
  return value;
126
123
  }
127
124
 
128
125
  async close(): Promise<L2Block> {
129
- this.logger.debug('Exiting PublicContext, building block with collected side effects', {
126
+ this.logger.debug('Exiting Public Context, building block with collected side effects', {
130
127
  blockNumber: this.globalVariables.blockNumber,
131
128
  });
132
129
 
133
130
  const txEffect = this.makeTxEffect();
134
- await this.insertSideEffectIntoWorldTrees(txEffect);
131
+ await insertTxEffectIntoWorldTrees(txEffect, this.forkedWorldTrees);
135
132
 
136
- const block = new L2Block(
137
- makeAppendOnlyTreeSnapshot(this.globalVariables.blockNumber),
138
- await this.makeBlockHeader(),
139
- new Body([txEffect]),
140
- );
133
+ const block = await makeTXEBlock(this.forkedWorldTrees, this.globalVariables, [txEffect]);
141
134
 
142
- await this.worldTrees.close();
135
+ await this.forkedWorldTrees.close();
143
136
 
144
137
  this.logger.debug('Exited PublicContext with built block', {
145
138
  blockNumber: block.number,
@@ -162,37 +155,4 @@ export class TXEOraclePublicContext extends TXETypedOracle {
162
155
 
163
156
  return txEffect;
164
157
  }
165
-
166
- private async insertSideEffectIntoWorldTrees(txEffect: TxEffect) {
167
- const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
168
-
169
- await this.worldTrees.appendLeaves(
170
- MerkleTreeId.NOTE_HASH_TREE,
171
- padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
172
- );
173
-
174
- await this.worldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
175
-
176
- // We do not need to add public data writes because we apply them as we go.
177
-
178
- await this.worldTrees.batchInsert(
179
- MerkleTreeId.NULLIFIER_TREE,
180
- padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(nullifier => nullifier.toBuffer()),
181
- NULLIFIER_SUBTREE_HEIGHT,
182
- );
183
- }
184
-
185
- private async makeBlockHeader(): Promise<BlockHeader> {
186
- const stateReference = await this.worldTrees.getStateReference();
187
- const archiveInfo = await this.worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
188
-
189
- return new BlockHeader(
190
- new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
191
- makeContentCommitment(),
192
- stateReference,
193
- this.globalVariables,
194
- Fr.ZERO,
195
- Fr.ZERO,
196
- );
197
- }
198
158
  }