@aztec/txe 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c

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 (80) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +3 -2
  7. package/dest/oracle/interfaces.d.ts +10 -7
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +6 -6
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +7 -8
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -12
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +108 -71
  15. package/dest/rpc_translator.d.ts +24 -12
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +98 -42
  18. package/dest/state_machine/archiver.d.ts +21 -52
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +61 -94
  21. package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +16 -11
  24. package/dest/state_machine/global_variable_builder.d.ts +6 -5
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +13 -1
  27. package/dest/state_machine/index.d.ts +5 -5
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +31 -19
  30. package/dest/state_machine/mock_epoch_cache.d.ts +7 -6
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +10 -7
  33. package/dest/state_machine/synchronizer.d.ts +3 -2
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +5 -4
  36. package/dest/txe_session.d.ts +21 -13
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +94 -47
  39. package/dest/util/encoding.d.ts +618 -19
  40. package/dest/util/encoding.d.ts.map +1 -1
  41. package/dest/util/encoding.js +1 -1
  42. package/dest/util/txe_account_store.d.ts +10 -0
  43. package/dest/util/txe_account_store.d.ts.map +1 -0
  44. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  45. package/dest/util/txe_contract_store.d.ts +12 -0
  46. package/dest/util/txe_contract_store.d.ts.map +1 -0
  47. package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
  48. package/dest/util/txe_public_contract_data_source.d.ts +7 -6
  49. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  50. package/dest/util/txe_public_contract_data_source.js +11 -11
  51. package/dest/utils/block_creation.d.ts +21 -6
  52. package/dest/utils/block_creation.d.ts.map +1 -1
  53. package/dest/utils/block_creation.js +36 -4
  54. package/dest/utils/tx_effect_creation.d.ts +3 -3
  55. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  56. package/dest/utils/tx_effect_creation.js +4 -7
  57. package/package.json +18 -18
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +15 -12
  60. package/src/oracle/interfaces.ts +9 -6
  61. package/src/oracle/txe_oracle_public_context.ts +9 -14
  62. package/src/oracle/txe_oracle_top_level_context.ts +159 -98
  63. package/src/rpc_translator.ts +128 -50
  64. package/src/state_machine/archiver.ts +57 -114
  65. package/src/state_machine/dummy_p2p_client.ts +21 -14
  66. package/src/state_machine/global_variable_builder.ts +21 -4
  67. package/src/state_machine/index.ts +40 -17
  68. package/src/state_machine/mock_epoch_cache.ts +10 -11
  69. package/src/state_machine/synchronizer.ts +6 -5
  70. package/src/txe_session.ts +192 -81
  71. package/src/util/encoding.ts +1 -1
  72. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  73. package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
  74. package/src/util/txe_public_contract_data_source.ts +13 -12
  75. package/src/utils/block_creation.ts +47 -15
  76. package/src/utils/tx_effect_creation.ts +5 -12
  77. package/dest/util/txe_account_data_provider.d.ts +0 -10
  78. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  79. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  80. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
@@ -1,15 +1,15 @@
1
1
  import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
2
  import { Fr } from '@aztec/aztec.js/fields';
3
- import { ContractDataProvider } from '@aztec/pxe/server';
3
+ import { ContractStore } from '@aztec/pxe/server';
4
4
 
5
5
  export type ContractArtifactWithHash = ContractArtifact & { artifactHash: Fr };
6
6
 
7
7
  /*
8
- * A contract data provider that stores contract artifacts with their hashes. Since
8
+ * A contract store that stores contract artifacts with their hashes. Since
9
9
  * TXE typically deploys the same contract again and again for multiple tests, caching
10
10
  * the *very* expensive artifact hash computation improves testing speed significantly.
11
11
  */
12
- export class TXEContractDataProvider extends ContractDataProvider {
12
+ export class TXEContractStore extends ContractStore {
13
13
  #artifactHashes: Map<string, Buffer> = new Map();
14
14
 
15
15
  public override async addContractArtifact(
@@ -1,5 +1,6 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import type { ContractDataProvider } from '@aztec/pxe/server';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { ContractStore } from '@aztec/pxe/server';
3
4
  import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
6
  import {
@@ -14,20 +15,20 @@ import {
14
15
  export class TXEPublicContractDataSource implements ContractDataSource {
15
16
  #privateFunctionsRoot: Map<string, Buffer> = new Map();
16
17
  constructor(
17
- private blockNumber: number,
18
- private contractDataProvider: ContractDataProvider,
18
+ private blockNumber: BlockNumber,
19
+ private contractStore: ContractStore,
19
20
  ) {}
20
21
 
21
- getBlockNumber(): Promise<number> {
22
+ getBlockNumber(): Promise<BlockNumber> {
22
23
  return Promise.resolve(this.blockNumber);
23
24
  }
24
25
 
25
26
  async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
26
- const contractClass = await this.contractDataProvider.getContractClass(id);
27
+ const contractClass = await this.contractStore.getContractClass(id);
27
28
  if (!contractClass) {
28
29
  return;
29
30
  }
30
- const artifact = await this.contractDataProvider.getContractArtifact(id);
31
+ const artifact = await this.contractStore.getContractArtifact(id);
31
32
  if (!artifact) {
32
33
  return;
33
34
  }
@@ -57,12 +58,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
57
58
  }
58
59
 
59
60
  async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
60
- const contractClass = await this.contractDataProvider.getContractClass(id);
61
+ const contractClass = await this.contractStore.getContractClass(id);
61
62
  return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
62
63
  }
63
64
 
64
65
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
65
- const instance = await this.contractDataProvider.getContractInstance(address);
66
+ const instance = await this.contractStore.getContractInstance(address);
66
67
  return instance && { ...instance, address };
67
68
  }
68
69
 
@@ -71,12 +72,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
71
72
  }
72
73
 
73
74
  async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
74
- const instance = await this.contractDataProvider.getContractInstance(address);
75
- return instance && this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
75
+ const instance = await this.contractStore.getContractInstance(address);
76
+ return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
76
77
  }
77
78
 
78
79
  async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
79
- return await this.contractDataProvider.getDebugFunctionName(address, selector);
80
+ return await this.contractStore.getDebugFunctionName(address, selector);
80
81
  }
81
82
 
82
83
  registerContractFunctionSignatures(_signatures: []): Promise<void> {
@@ -4,19 +4,19 @@ import {
4
4
  NULLIFIER_SUBTREE_HEIGHT,
5
5
  NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
6
6
  } from '@aztec/constants';
7
+ import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
7
8
  import { padArrayEnd } from '@aztec/foundation/collection';
8
- import { Fr } from '@aztec/foundation/fields';
9
- import { L2BlockHeader } from '@aztec/stdlib/block';
10
- import { makeContentCommitment } from '@aztec/stdlib/testing';
9
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
+ import { Body, L2Block } from '@aztec/stdlib/block';
11
11
  import { AppendOnlyTreeSnapshot, MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
12
- import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
12
+ import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
13
13
 
14
14
  /**
15
15
  * Returns a transaction request hash that is valid for transactions that are the only ones in a block.
16
16
  * @param blockNumber The number for the block in which there is a single transaction.
17
17
  * @returns The transaction request hash.
18
18
  */
19
- export function getSingleTxBlockRequestHash(blockNumber: number): Fr {
19
+ export function getSingleTxBlockRequestHash(blockNumber: BlockNumber): Fr {
20
20
  return new Fr(blockNumber + 9999); // Why does this need to be a high number? Why do small numbered nullifiers already exist?
21
21
  }
22
22
 
@@ -46,18 +46,50 @@ export async function insertTxEffectIntoWorldTrees(
46
46
  export async function makeTXEBlockHeader(
47
47
  worldTrees: MerkleTreeWriteOperations,
48
48
  globalVariables: GlobalVariables,
49
- ): Promise<L2BlockHeader> {
49
+ ): Promise<BlockHeader> {
50
50
  const stateReference = await worldTrees.getStateReference();
51
51
  const archiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
52
52
 
53
- return new L2BlockHeader(
54
- new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
55
- makeContentCommitment(),
56
- stateReference,
53
+ return BlockHeader.from({
54
+ lastArchive: new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
55
+ spongeBlobHash: Fr.ZERO,
56
+ state: stateReference,
57
57
  globalVariables,
58
- Fr.ZERO,
59
- Fr.ZERO,
60
- Fr.ZERO,
61
- Fr.ZERO,
62
- );
58
+ totalFees: Fr.ZERO,
59
+ totalManaUsed: Fr.ZERO,
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Creates an L2Block with proper archive chaining.
65
+ * This function:
66
+ * 1. Gets the current archive state as lastArchive for the header
67
+ * 2. Creates the block header
68
+ * 3. Updates the archive tree with the header hash
69
+ * 4. Gets the new archive state for the block's archive
70
+ *
71
+ * @param worldTrees - The world trees to read/write from
72
+ * @param globalVariables - Global variables for the block
73
+ * @param txEffects - Transaction effects to include in the block
74
+ * @returns The created L2Block with proper archive chaining
75
+ */
76
+ export async function makeTXEBlock(
77
+ worldTrees: MerkleTreeWriteOperations,
78
+ globalVariables: GlobalVariables,
79
+ txEffects: TxEffect[],
80
+ ): Promise<L2Block> {
81
+ const header = await makeTXEBlockHeader(worldTrees, globalVariables);
82
+
83
+ // Update the archive tree with this block's header hash
84
+ await worldTrees.updateArchive(header);
85
+
86
+ // Get the new archive state after updating
87
+ const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
88
+ const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
89
+
90
+ // L2Block requires checkpointNumber and indexWithinCheckpoint
91
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
92
+ const indexWithinCheckpoint = IndexWithinCheckpoint(0);
93
+
94
+ return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
63
95
  }
@@ -1,18 +1,15 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import type { ExecutionNoteCache } from '@aztec/pxe/simulator';
3
4
  import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
4
5
  import { TxEffect, TxHash } from '@aztec/stdlib/tx';
5
6
 
6
- export async function makeTxEffect(
7
- noteCache: ExecutionNoteCache,
8
- protocolNullifier: Fr,
9
- txBlockNumber: number,
10
- ): Promise<TxEffect> {
7
+ export async function makeTxEffect(noteCache: ExecutionNoteCache, txBlockNumber: BlockNumber): Promise<TxEffect> {
11
8
  const txEffect = TxEffect.empty();
12
9
 
13
- const { usedProtocolNullifierForNonces } = noteCache.finish();
14
- const nonceGenerator = usedProtocolNullifierForNonces ? protocolNullifier : noteCache.getAllNullifiers()[0];
10
+ noteCache.finish();
15
11
 
12
+ const nonceGenerator = noteCache.getNonceGenerator();
16
13
  txEffect.noteHashes = await Promise.all(
17
14
  noteCache
18
15
  .getAllNotes()
@@ -27,10 +24,6 @@ export async function makeTxEffect(
27
24
  // Nullifiers are already siloed
28
25
  txEffect.nullifiers = noteCache.getAllNullifiers();
29
26
 
30
- if (usedProtocolNullifierForNonces) {
31
- txEffect.nullifiers.unshift(protocolNullifier);
32
- }
33
-
34
27
  txEffect.txHash = new TxHash(new Fr(txBlockNumber));
35
28
 
36
29
  return txEffect;
@@ -1,10 +0,0 @@
1
- import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import { CompleteAddress } from '@aztec/stdlib/contract';
4
- export declare class TXEAccountDataProvider {
5
- #private;
6
- constructor(store: AztecAsyncKVStore);
7
- getAccount(key: AztecAddress): Promise<CompleteAddress>;
8
- setAccount(key: AztecAddress, value: CompleteAddress): Promise<void>;
9
- }
10
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2FjY291bnRfZGF0YV9wcm92aWRlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWwvdHhlX2FjY291bnRfZGF0YV9wcm92aWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsc0JBQXNCOztJQUdqQyxZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFFbkM7SUFFSyxVQUFVLENBQUMsR0FBRyxFQUFFLFlBQVksNEJBTWpDO0lBRUssVUFBVSxDQUFDLEdBQUcsRUFBRSxZQUFZLEVBQUUsS0FBSyxFQUFFLGVBQWUsaUJBRXpEO0NBQ0YifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"txe_account_data_provider.d.ts","sourceRoot":"","sources":["../../src/util/txe_account_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,sBAAsB;;IAGjC,YAAY,KAAK,EAAE,iBAAiB,EAEnC;IAEK,UAAU,CAAC,GAAG,EAAE,YAAY,4BAMjC;IAEK,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,iBAEzD;CACF"}
@@ -1,12 +0,0 @@
1
- import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
- import { Fr } from '@aztec/aztec.js/fields';
3
- import { ContractDataProvider } from '@aztec/pxe/server';
4
- export type ContractArtifactWithHash = ContractArtifact & {
5
- artifactHash: Fr;
6
- };
7
- export declare class TXEContractDataProvider extends ContractDataProvider {
8
- #private;
9
- addContractArtifact(id: Fr, artifact: ContractArtifact | ContractArtifactWithHash): Promise<void>;
10
- getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | ContractArtifactWithHash | undefined>;
11
- }
12
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2NvbnRyYWN0X2RhdGFfcHJvdmlkZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsL3R4ZV9jb250cmFjdF9kYXRhX3Byb3ZpZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDNUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzVDLE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRXpELE1BQU0sTUFBTSx3QkFBd0IsR0FBRyxnQkFBZ0IsR0FBRztJQUFFLFlBQVksRUFBRSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBTy9FLHFCQUFhLHVCQUF3QixTQUFRLG9CQUFvQjs7SUFHekMsbUJBQW1CLENBQ3ZDLEVBQUUsRUFBRSxFQUFFLEVBQ04sUUFBUSxFQUFFLGdCQUFnQixHQUFHLHdCQUF3QixHQUNwRCxPQUFPLENBQUMsSUFBSSxDQUFDLENBS2Y7SUFFcUIsbUJBQW1CLENBQ3ZDLGVBQWUsRUFBRSxFQUFFLEdBQ2xCLE9BQU8sQ0FBQyxnQkFBZ0IsR0FBRyx3QkFBd0IsR0FBRyxTQUFTLENBQUMsQ0FRbEU7Q0FDRiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"txe_contract_data_provider.d.ts","sourceRoot":"","sources":["../../src/util/txe_contract_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,CAAC;AAO/E,qBAAa,uBAAwB,SAAQ,oBAAoB;;IAGzC,mBAAmB,CACvC,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,gBAAgB,GAAG,wBAAwB,GACpD,OAAO,CAAC,IAAI,CAAC,CAKf;IAEqB,mBAAmB,CACvC,eAAe,EAAE,EAAE,GAClB,OAAO,CAAC,gBAAgB,GAAG,wBAAwB,GAAG,SAAS,CAAC,CAQlE;CACF"}