@aztec/txe 2.1.0-rc.9 → 3.0.0-devnet.2

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 (71) hide show
  1. package/dest/bin/index.js +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +5 -2
  4. package/dest/oracle/interfaces.d.ts +54 -0
  5. package/dest/oracle/interfaces.d.ts.map +1 -0
  6. package/dest/oracle/interfaces.js +3 -0
  7. package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
  8. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.js +29 -31
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts +56 -0
  11. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
  12. package/dest/oracle/txe_oracle_top_level_context.js +423 -0
  13. package/dest/{txe_service/txe_service.d.ts → rpc_translator.d.ts} +34 -28
  14. package/dest/rpc_translator.d.ts.map +1 -0
  15. package/dest/{txe_service/txe_service.js → rpc_translator.js} +143 -115
  16. package/dest/state_machine/archiver.d.ts +5 -1
  17. package/dest/state_machine/archiver.d.ts.map +1 -1
  18. package/dest/state_machine/archiver.js +8 -1
  19. package/dest/state_machine/dummy_p2p_client.d.ts +1 -0
  20. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  21. package/dest/state_machine/dummy_p2p_client.js +3 -0
  22. package/dest/state_machine/global_variable_builder.d.ts +1 -14
  23. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  24. package/dest/state_machine/global_variable_builder.js +3 -22
  25. package/dest/state_machine/index.d.ts.map +1 -1
  26. package/dest/state_machine/index.js +4 -3
  27. package/dest/txe_session.d.ts +34 -44
  28. package/dest/txe_session.d.ts.map +1 -1
  29. package/dest/txe_session.js +197 -82
  30. package/dest/util/encoding.d.ts +1 -1
  31. package/dest/util/txe_contract_data_provider.d.ts +2 -1
  32. package/dest/util/txe_contract_data_provider.d.ts.map +1 -1
  33. package/dest/util/txe_contract_data_provider.js +1 -1
  34. package/dest/util/txe_public_contract_data_source.d.ts +4 -3
  35. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  36. package/dest/util/txe_public_contract_data_source.js +13 -11
  37. package/dest/utils/block_creation.d.ts +13 -0
  38. package/dest/utils/block_creation.d.ts.map +1 -0
  39. package/dest/utils/block_creation.js +24 -0
  40. package/dest/utils/tx_effect_creation.d.ts +5 -0
  41. package/dest/utils/tx_effect_creation.d.ts.map +1 -0
  42. package/dest/utils/tx_effect_creation.js +16 -0
  43. package/package.json +15 -15
  44. package/src/bin/index.ts +1 -1
  45. package/src/index.ts +5 -8
  46. package/src/oracle/interfaces.ts +83 -0
  47. package/src/oracle/txe_oracle_public_context.ts +36 -69
  48. package/src/oracle/txe_oracle_top_level_context.ts +658 -0
  49. package/src/{txe_service/txe_service.ts → rpc_translator.ts} +181 -115
  50. package/src/state_machine/archiver.ts +8 -2
  51. package/src/state_machine/dummy_p2p_client.ts +4 -0
  52. package/src/state_machine/global_variable_builder.ts +6 -41
  53. package/src/state_machine/index.ts +6 -4
  54. package/src/txe_session.ts +301 -90
  55. package/src/util/txe_contract_data_provider.ts +2 -1
  56. package/src/util/txe_public_contract_data_source.ts +13 -11
  57. package/src/utils/block_creation.ts +62 -0
  58. package/src/utils/tx_effect_creation.ts +37 -0
  59. package/dest/oracle/txe_oracle.d.ts +0 -124
  60. package/dest/oracle/txe_oracle.d.ts.map +0 -1
  61. package/dest/oracle/txe_oracle.js +0 -770
  62. package/dest/oracle/txe_typed_oracle.d.ts +0 -42
  63. package/dest/oracle/txe_typed_oracle.d.ts.map +0 -1
  64. package/dest/oracle/txe_typed_oracle.js +0 -83
  65. package/dest/txe_constants.d.ts +0 -2
  66. package/dest/txe_constants.d.ts.map +0 -1
  67. package/dest/txe_constants.js +0 -7
  68. package/dest/txe_service/txe_service.d.ts.map +0 -1
  69. package/src/oracle/txe_oracle.ts +0 -1287
  70. package/src/oracle/txe_typed_oracle.ts +0 -142
  71. package/src/txe_constants.ts +0 -9
package/dest/bin/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env -S node --no-warnings
2
- import { createLogger } from '@aztec/aztec.js';
2
+ import { createLogger } from '@aztec/aztec.js/log';
3
3
  import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
4
4
  import { createTXERpcServer } from '../index.js';
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AA8NpD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,iEAIhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AA6NpD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,iEAIhD"}
package/dest/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
- import { AztecAddress, Fr, PublicKeys, deriveKeys, getContractInstanceFromInstantiationParams, loadContractArtifact } from '@aztec/aztec.js';
2
+ import { loadContractArtifact } from '@aztec/aztec.js/abi';
3
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
4
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
5
+ import { Fr } from '@aztec/aztec.js/fields';
6
+ import { PublicKeys, deriveKeys } from '@aztec/aztec.js/keys';
3
7
  import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
4
8
  import { protocolContractNames } from '@aztec/protocol-contracts';
5
9
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
@@ -16,7 +20,6 @@ const sessions = new Map();
16
20
  * TXE typically has to load the same contract artifacts over and over again for multiple tests,
17
21
  * so we cache them here to avoid both loading them from disk repeatedly and computing their artifact hashes
18
22
  */ const TXEArtifactsCache = new Map();
19
- // TODO: why does the zod validation in the txe dispatcher not reject invalid function names?
20
23
  const TXEForeignCallInputSchema = z.object({
21
24
  // eslint-disable-next-line camelcase
22
25
  session_id: z.number().int().nonnegative(),
@@ -0,0 +1,54 @@
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 type { Fr } from '@aztec/foundation/fields';
6
+ import type { FunctionSelector } from '@aztec/stdlib/abi';
7
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
+ import type { UInt32, UInt64 } from '@aztec/stdlib/types';
9
+ /**
10
+ * Oracle methods associated with the execution of an Aztec #[external("public")] function.
11
+ *
12
+ * Note that real contracts have their Brillig calls to these be transpiled into opcodes, the oracles are only executed
13
+ * as such when running the original Brillig code, e.g. when invoking functions that interact with a PublicContext
14
+ * directly in a Noir test.
15
+ */
16
+ export interface IAvmExecutionOracle {
17
+ isAvm: true;
18
+ avmOpcodeAddress(): Promise<AztecAddress>;
19
+ avmOpcodeSender(): Promise<AztecAddress>;
20
+ avmOpcodeBlockNumber(): Promise<UInt32>;
21
+ avmOpcodeTimestamp(): Promise<bigint>;
22
+ avmOpcodeIsStaticCall(): Promise<boolean>;
23
+ avmOpcodeChainId(): Promise<Fr>;
24
+ avmOpcodeVersion(): Promise<Fr>;
25
+ avmOpcodeEmitNullifier(nullifier: Fr): Promise<void>;
26
+ avmOpcodeEmitNoteHash(noteHash: Fr): Promise<void>;
27
+ avmOpcodeNullifierExists(innerNullifier: Fr, targetAddress: AztecAddress): Promise<boolean>;
28
+ avmOpcodeStorageWrite(slot: Fr, value: Fr): Promise<void>;
29
+ avmOpcodeStorageRead(slot: Fr): Promise<Fr>;
30
+ }
31
+ /**
32
+ * Oracle methods associated with the execution of an Aztec Noir test.
33
+ */
34
+ export interface ITxeExecutionOracle {
35
+ isTxe: true;
36
+ txeGetNextBlockNumber(): Promise<number>;
37
+ txeGetNextBlockTimestamp(): Promise<UInt64>;
38
+ txeAdvanceBlocksBy(blocks: number): Promise<void>;
39
+ txeAdvanceTimestampBy(duration: UInt64): void;
40
+ txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, foreignSecret: Fr): Promise<void>;
41
+ txeCreateAccount(secret: Fr): Promise<CompleteAddress>;
42
+ txeAddAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr): Promise<CompleteAddress>;
43
+ txeAddAuthWitness(address: AztecAddress, messageHash: Fr): Promise<void>;
44
+ txeGetLastBlockTimestamp(): Promise<bigint>;
45
+ txeGetLastTxEffects(): Promise<{
46
+ txHash: TxHash;
47
+ noteHashes: Fr[];
48
+ nullifiers: Fr[];
49
+ }>;
50
+ txePrivateCallNewFlow(from: AztecAddress, targetContractAddress: AztecAddress, functionSelector: FunctionSelector, args: Fr[], argsHash: Fr, isStaticCall: boolean): Promise<Fr[]>;
51
+ txeSimulateUtilityFunction(targetContractAddress: AztecAddress, functionSelector: FunctionSelector, args: Fr[]): Promise<Fr[]>;
52
+ txePublicCallNewFlow(from: AztecAddress, targetContractAddress: AztecAddress, calldata: Fr[], isStaticCall: boolean): Promise<Fr[]>;
53
+ }
54
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/oracle/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAA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,EACnC,QAAQ,EAAE,EAAE,EAAE,EACd,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;CAClB"}
@@ -0,0 +1,3 @@
1
+ /**
2
+ * Oracle methods associated with the execution of an Aztec Noir test.
3
+ */ export { };
@@ -1,21 +1,23 @@
1
1
  import { Fr } from '@aztec/foundation/fields';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import { L2Block } from '@aztec/stdlib/block';
4
4
  import { type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
5
5
  import { GlobalVariables } from '@aztec/stdlib/tx';
6
6
  import type { UInt32 } from '@aztec/stdlib/types';
7
- import { TXETypedOracle } from './txe_typed_oracle.js';
8
- export declare class TXEOraclePublicContext extends TXETypedOracle {
7
+ import type { IAvmExecutionOracle } from './interfaces.js';
8
+ export declare class TXEOraclePublicContext implements IAvmExecutionOracle {
9
9
  private contractAddress;
10
- private worldTrees;
10
+ private forkedWorldTrees;
11
11
  private txRequestHash;
12
12
  private globalVariables;
13
+ isAvm: true;
13
14
  private logger;
14
15
  private transientUniqueNoteHashes;
15
16
  private transientSiloedNullifiers;
16
17
  private publicDataWrites;
17
- constructor(contractAddress: AztecAddress, worldTrees: MerkleTreeWriteOperations, txRequestHash: Fr, globalVariables: GlobalVariables);
18
+ constructor(contractAddress: AztecAddress, forkedWorldTrees: MerkleTreeWriteOperations, txRequestHash: Fr, globalVariables: GlobalVariables);
18
19
  avmOpcodeAddress(): Promise<AztecAddress>;
20
+ avmOpcodeSender(): Promise<AztecAddress>;
19
21
  avmOpcodeBlockNumber(): Promise<UInt32>;
20
22
  avmOpcodeTimestamp(): Promise<bigint>;
21
23
  avmOpcodeIsStaticCall(): Promise<boolean>;
@@ -28,7 +30,5 @@ export declare class TXEOraclePublicContext extends TXETypedOracle {
28
30
  avmOpcodeStorageRead(slot: Fr): Promise<Fr>;
29
31
  close(): Promise<L2Block>;
30
32
  private makeTxEffect;
31
- private insertSideEffectIntoWorldTrees;
32
- private makeBlockHeader;
33
33
  }
34
34
  //# sourceMappingURL=txe_oracle_public_context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"txe_oracle_public_context.d.ts","sourceRoot":"","sources":["../../src/oracle/txe_oracle_public_context.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAQ,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAGL,KAAK,yBAAyB,EAG/B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAe,eAAe,EAAoB,MAAM,kBAAkB,CAAC;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,qBAAa,sBAAuB,SAAQ,cAAc;IAOtD,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,eAAe;IATzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,yBAAyB,CAAY;IAC7C,OAAO,CAAC,yBAAyB,CAAY;IAC7C,OAAO,CAAC,gBAAgB,CAAyB;gBAGvC,eAAe,EAAE,YAAY,EAC7B,UAAU,EAAE,yBAAyB,EACrC,aAAa,EAAE,EAAE,EACjB,eAAe,EAAE,eAAe;IAYjC,gBAAgB,IAAI,OAAO,CAAC,YAAY,CAAC;IAIzC,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC;IAIzC,gBAAgB,IAAI,OAAO,CAAC,EAAE,CAAC;IAI/B,gBAAgB,IAAI,OAAO,CAAC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AAY,EAC7B,gBAAgB,EAAE,yBAAyB,EAC3C,aAAa,EAAE,EAAE,EACjB,eAAe,EAAE,eAAe;IAW1C,gBAAgB,IAAI,OAAO,CAAC,YAAY,CAAC;IAIzC,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC;IAIxC,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC;IAIzC,gBAAgB,IAAI,OAAO,CAAC,EAAE,CAAC;IAI/B,gBAAgB,IAAI,OAAO,CAAC,EAAE,CAAC;IAIzB,sBAAsB,CAAC,SAAS,EAAE,EAAE;IAKpC,qBAAqB,CAAC,QAAQ,EAAE,EAAE;IAMlC,wBAAwB,CAAC,cAAc,EAAE,EAAE,EAAE,aAAa,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAW3F,qBAAqB,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE;IAYzC,oBAAoB,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;IAuB3C,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;IAwB/B,OAAO,CAAC,YAAY;CAarB"}
@@ -1,27 +1,34 @@
1
- import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
- import { padArrayEnd } from '@aztec/foundation/collection';
3
1
  import { Fr } from '@aztec/foundation/fields';
4
2
  import { createLogger } from '@aztec/foundation/log';
5
3
  import { PublicDataWrite } from '@aztec/stdlib/avm';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
5
  import { Body, L2Block } from '@aztec/stdlib/block';
7
6
  import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
8
- import { makeAppendOnlyTreeSnapshot, makeContentCommitment } from '@aztec/stdlib/testing';
9
- import { AppendOnlyTreeSnapshot, MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
10
- import { BlockHeader, TxEffect, TxHash } from '@aztec/stdlib/tx';
11
- import { TXETypedOracle } from './txe_typed_oracle.js';
12
- export class TXEOraclePublicContext extends TXETypedOracle {
7
+ import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
8
+ import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
9
+ import { TxEffect, TxHash } from '@aztec/stdlib/tx';
10
+ import { insertTxEffectIntoWorldTrees, makeTXEBlockHeader } from '../utils/block_creation.js';
11
+ export class TXEOraclePublicContext {
13
12
  contractAddress;
14
- worldTrees;
13
+ forkedWorldTrees;
15
14
  txRequestHash;
16
15
  globalVariables;
16
+ isAvm;
17
17
  logger;
18
18
  transientUniqueNoteHashes;
19
19
  transientSiloedNullifiers;
20
20
  publicDataWrites;
21
- constructor(contractAddress, worldTrees, txRequestHash, globalVariables){
22
- super(), this.contractAddress = contractAddress, this.worldTrees = worldTrees, this.txRequestHash = txRequestHash, this.globalVariables = globalVariables, this.transientUniqueNoteHashes = [], this.transientSiloedNullifiers = [], this.publicDataWrites = [];
21
+ constructor(contractAddress, forkedWorldTrees, txRequestHash, globalVariables){
22
+ this.contractAddress = contractAddress;
23
+ this.forkedWorldTrees = forkedWorldTrees;
24
+ this.txRequestHash = txRequestHash;
25
+ this.globalVariables = globalVariables;
26
+ this.isAvm = true;
27
+ this.transientUniqueNoteHashes = [];
28
+ this.transientSiloedNullifiers = [];
29
+ this.publicDataWrites = [];
23
30
  this.logger = createLogger('txe:public_context');
24
- this.logger.debug('Entering PublicContext', {
31
+ this.logger.debug('Entering Public Context', {
25
32
  contractAddress,
26
33
  blockNumber: globalVariables.blockNumber,
27
34
  timestamp: globalVariables.timestamp
@@ -30,6 +37,9 @@ export class TXEOraclePublicContext extends TXETypedOracle {
30
37
  avmOpcodeAddress() {
31
38
  return Promise.resolve(this.contractAddress);
32
39
  }
40
+ avmOpcodeSender() {
41
+ return Promise.resolve(AztecAddress.ZERO); // todo: change?
42
+ }
33
43
  avmOpcodeBlockNumber() {
34
44
  return Promise.resolve(this.globalVariables.blockNumber);
35
45
  }
@@ -56,7 +66,7 @@ export class TXEOraclePublicContext extends TXETypedOracle {
56
66
  }
57
67
  async avmOpcodeNullifierExists(innerNullifier, targetAddress) {
58
68
  const nullifier = await siloNullifier(targetAddress, innerNullifier);
59
- const treeIndex = (await this.worldTrees.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [
69
+ const treeIndex = (await this.forkedWorldTrees.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [
60
70
  nullifier.toBuffer()
61
71
  ]))[0];
62
72
  const transientIndex = this.transientSiloedNullifiers.find((n)=>n.equals(nullifier));
@@ -69,14 +79,14 @@ export class TXEOraclePublicContext extends TXETypedOracle {
69
79
  });
70
80
  const dataWrite = new PublicDataWrite(await computePublicDataTreeLeafSlot(this.contractAddress, slot), value);
71
81
  this.publicDataWrites.push(dataWrite);
72
- await this.worldTrees.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
82
+ await this.forkedWorldTrees.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
73
83
  new PublicDataTreeLeaf(dataWrite.leafSlot, dataWrite.value).toBuffer()
74
84
  ]);
75
85
  }
76
86
  async avmOpcodeStorageRead(slot) {
77
87
  const leafSlot = await computePublicDataTreeLeafSlot(this.contractAddress, slot);
78
- const lowLeafResult = await this.worldTrees.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
79
- const value = !lowLeafResult || !lowLeafResult.alreadyPresent ? Fr.ZERO : (await this.worldTrees.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index)).leaf.value;
88
+ const lowLeafResult = await this.forkedWorldTrees.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
89
+ const value = !lowLeafResult || !lowLeafResult.alreadyPresent ? Fr.ZERO : (await this.forkedWorldTrees.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index)).leaf.value;
80
90
  this.logger.debug('AVM storage read', {
81
91
  slot,
82
92
  value
@@ -84,15 +94,15 @@ export class TXEOraclePublicContext extends TXETypedOracle {
84
94
  return value;
85
95
  }
86
96
  async close() {
87
- this.logger.debug('Exiting PublicContext, building block with collected side effects', {
97
+ this.logger.debug('Exiting Public Context, building block with collected side effects', {
88
98
  blockNumber: this.globalVariables.blockNumber
89
99
  });
90
100
  const txEffect = this.makeTxEffect();
91
- await this.insertSideEffectIntoWorldTrees(txEffect);
92
- const block = new L2Block(makeAppendOnlyTreeSnapshot(this.globalVariables.blockNumber), await this.makeBlockHeader(), new Body([
101
+ await insertTxEffectIntoWorldTrees(txEffect, this.forkedWorldTrees);
102
+ const block = new L2Block(makeAppendOnlyTreeSnapshot(), await makeTXEBlockHeader(this.forkedWorldTrees, this.globalVariables), new Body([
93
103
  txEffect
94
104
  ]));
95
- await this.worldTrees.close();
105
+ await this.forkedWorldTrees.close();
96
106
  this.logger.debug('Exited PublicContext with built block', {
97
107
  blockNumber: block.number,
98
108
  txEffects: block.body.txEffects
@@ -111,16 +121,4 @@ export class TXEOraclePublicContext extends TXETypedOracle {
111
121
  txEffect.txHash = new TxHash(new Fr(this.globalVariables.blockNumber));
112
122
  return txEffect;
113
123
  }
114
- async insertSideEffectIntoWorldTrees(txEffect) {
115
- const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
116
- await this.worldTrees.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
117
- await this.worldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
118
- // We do not need to add public data writes because we apply them as we go.
119
- await this.worldTrees.batchInsert(MerkleTreeId.NULLIFIER_TREE, padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
120
- }
121
- async makeBlockHeader() {
122
- const stateReference = await this.worldTrees.getStateReference();
123
- const archiveInfo = await this.worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
124
- return new BlockHeader(new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)), makeContentCommitment(), stateReference, this.globalVariables, Fr.ZERO, Fr.ZERO);
125
- }
126
124
  }
@@ -0,0 +1,56 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import type { KeyStore } from '@aztec/key-store';
3
+ import { AddressDataProvider, PXEOracleInterface } from '@aztec/pxe/server';
4
+ import { type IMiscOracle } from '@aztec/pxe/simulator';
5
+ import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
6
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
7
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
8
+ import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
9
+ import { TxHash } from '@aztec/stdlib/tx';
10
+ import type { UInt64 } from '@aztec/stdlib/types';
11
+ import type { TXEStateMachine } from '../state_machine/index.js';
12
+ import type { TXEAccountDataProvider } from '../util/txe_account_data_provider.js';
13
+ import type { TXEContractDataProvider } from '../util/txe_contract_data_provider.js';
14
+ import type { ITxeExecutionOracle } from './interfaces.js';
15
+ export declare class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracle {
16
+ private stateMachine;
17
+ private contractDataProvider;
18
+ private keyStore;
19
+ private addressDataProvider;
20
+ private accountDataProvider;
21
+ private pxeOracleInterface;
22
+ private nextBlockTimestamp;
23
+ private version;
24
+ private chainId;
25
+ private authwits;
26
+ isMisc: true;
27
+ isTxe: true;
28
+ private logger;
29
+ constructor(stateMachine: TXEStateMachine, contractDataProvider: TXEContractDataProvider, keyStore: KeyStore, addressDataProvider: AddressDataProvider, accountDataProvider: TXEAccountDataProvider, pxeOracleInterface: PXEOracleInterface, nextBlockTimestamp: bigint, version: Fr, chainId: Fr, authwits: Map<string, AuthWitness>);
30
+ utilityAssertCompatibleOracleVersion(version: number): void;
31
+ utilityGetRandomField(): Fr;
32
+ utilityDebugLog(level: number, message: string, fields: Fr[]): void;
33
+ txeGetNextBlockNumber(): Promise<number>;
34
+ txeGetNextBlockTimestamp(): Promise<bigint>;
35
+ txeGetLastBlockTimestamp(): Promise<bigint>;
36
+ txeGetLastTxEffects(): Promise<{
37
+ txHash: TxHash;
38
+ noteHashes: Fr[];
39
+ nullifiers: Fr[];
40
+ }>;
41
+ txeAdvanceBlocksBy(blocks: number): Promise<void>;
42
+ txeAdvanceTimestampBy(duration: UInt64): void;
43
+ txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr): Promise<void>;
44
+ txeAddAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr): Promise<import("@aztec/stdlib/contract").CompleteAddress>;
45
+ txeCreateAccount(secret: Fr): Promise<import("@aztec/stdlib/contract").CompleteAddress>;
46
+ txeAddAuthWitness(address: AztecAddress, messageHash: Fr): Promise<void>;
47
+ mineBlock(options?: {
48
+ nullifiers?: Fr[];
49
+ }): Promise<void>;
50
+ txePrivateCallNewFlow(from: AztecAddress, targetContractAddress: AztecAddress | undefined, functionSelector: FunctionSelector | undefined, args: Fr[], argsHash?: Fr, isStaticCall?: boolean): Promise<Fr[]>;
51
+ txePublicCallNewFlow(from: AztecAddress, targetContractAddress: AztecAddress, calldata: Fr[], isStaticCall: boolean): Promise<Fr[]>;
52
+ txeSimulateUtilityFunction(targetContractAddress: AztecAddress, functionSelector: FunctionSelector, args: Fr[]): Promise<Fr[]>;
53
+ close(): [bigint, Map<string, AuthWitness>];
54
+ private getLastBlockNumber;
55
+ }
56
+ //# sourceMappingURL=txe_oracle_top_level_context.d.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