@aztec/txe 0.0.1-commit.d431d1c → 0.0.1-commit.db765a8

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 (55) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +88 -54
  4. package/dest/oracle/interfaces.d.ts +29 -28
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_public_context.d.ts +15 -15
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +16 -16
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -23
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +125 -54
  12. package/dest/rpc_translator.d.ts +87 -81
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +283 -166
  15. package/dest/state_machine/archiver.d.ts +2 -2
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +7 -6
  18. package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +28 -16
  21. package/dest/state_machine/index.d.ts +7 -7
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +31 -17
  24. package/dest/state_machine/mock_epoch_cache.d.ts +6 -2
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +6 -1
  27. package/dest/state_machine/synchronizer.d.ts +3 -3
  28. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  29. package/dest/txe_session.d.ts +9 -6
  30. package/dest/txe_session.d.ts.map +1 -1
  31. package/dest/txe_session.js +86 -26
  32. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  33. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  34. package/dest/util/txe_public_contract_data_source.js +5 -22
  35. package/dest/utils/block_creation.d.ts +5 -5
  36. package/dest/utils/block_creation.d.ts.map +1 -1
  37. package/dest/utils/block_creation.js +7 -5
  38. package/package.json +15 -15
  39. package/src/index.ts +89 -52
  40. package/src/oracle/interfaces.ts +32 -31
  41. package/src/oracle/txe_oracle_public_context.ts +18 -20
  42. package/src/oracle/txe_oracle_top_level_context.ts +155 -102
  43. package/src/rpc_translator.ts +298 -168
  44. package/src/state_machine/archiver.ts +6 -8
  45. package/src/state_machine/dummy_p2p_client.ts +40 -22
  46. package/src/state_machine/index.ts +49 -19
  47. package/src/state_machine/mock_epoch_cache.ts +7 -1
  48. package/src/state_machine/synchronizer.ts +2 -2
  49. package/src/txe_session.ts +101 -85
  50. package/src/util/txe_public_contract_data_source.ts +10 -36
  51. package/src/utils/block_creation.ts +8 -6
  52. package/dest/util/txe_contract_store.d.ts +0 -12
  53. package/dest/util/txe_contract_store.d.ts.map +0 -1
  54. package/dest/util/txe_contract_store.js +0 -22
  55. package/src/util/txe_contract_store.ts +0 -36
@@ -1,19 +1,11 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import type { ContractStore } from '@aztec/pxe/server';
4
- import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
+ import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import {
7
- type ContractClassPublic,
8
- type ContractDataSource,
9
- type ContractInstanceWithAddress,
10
- computePrivateFunctionsRoot,
11
- computePublicBytecodeCommitment,
12
- getContractClassPrivateFunctionFromArtifact,
13
- } from '@aztec/stdlib/contract';
6
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
14
7
 
15
8
  export class TXEPublicContractDataSource implements ContractDataSource {
16
- #privateFunctionsRoot: Map<string, Buffer> = new Map();
17
9
  constructor(
18
10
  private blockNumber: BlockNumber,
19
11
  private contractStore: ContractStore,
@@ -24,42 +16,24 @@ export class TXEPublicContractDataSource implements ContractDataSource {
24
16
  }
25
17
 
26
18
  async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
27
- const contractClass = await this.contractStore.getContractClass(id);
19
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
28
20
  if (!contractClass) {
29
21
  return;
30
22
  }
31
- const artifact = await this.contractStore.getContractArtifact(id);
32
- if (!artifact) {
33
- return;
34
- }
35
-
36
- let privateFunctionsRoot;
37
- if (!this.#privateFunctionsRoot.has(id.toString())) {
38
- const privateFunctions = await Promise.all(
39
- artifact.functions
40
- .filter(fn => fn.functionType === FunctionType.PRIVATE)
41
- .map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
42
- );
43
- privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
44
- this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
45
- } else {
46
- privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
47
- }
48
-
49
23
  return {
50
- id,
51
- artifactHash: contractClass!.artifactHash,
52
- packedBytecode: contractClass!.packedBytecode,
53
- privateFunctionsRoot,
54
- version: contractClass!.version,
24
+ id: contractClass.id,
25
+ artifactHash: contractClass.artifactHash,
26
+ packedBytecode: contractClass.packedBytecode,
27
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
28
+ version: contractClass.version,
55
29
  privateFunctions: [],
56
30
  utilityFunctions: [],
57
31
  };
58
32
  }
59
33
 
60
34
  async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
61
- const contractClass = await this.contractStore.getContractClass(id);
62
- return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
35
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
36
+ return contractClass?.publicBytecodeCommitment;
63
37
  }
64
38
 
65
39
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
@@ -7,7 +7,7 @@ import {
7
7
  import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
8
8
  import { padArrayEnd } from '@aztec/foundation/collection';
9
9
  import { Fr } from '@aztec/foundation/curves/bn254';
10
- import { Body, L2BlockNew } from '@aztec/stdlib/block';
10
+ import { Body, L2Block } from '@aztec/stdlib/block';
11
11
  import { AppendOnlyTreeSnapshot, MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
12
12
  import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
13
13
 
@@ -61,7 +61,7 @@ export async function makeTXEBlockHeader(
61
61
  }
62
62
 
63
63
  /**
64
- * Creates an L2BlockNew with proper archive chaining.
64
+ * Creates an L2Block with proper archive chaining.
65
65
  * This function:
66
66
  * 1. Gets the current archive state as lastArchive for the header
67
67
  * 2. Creates the block header
@@ -71,13 +71,13 @@ export async function makeTXEBlockHeader(
71
71
  * @param worldTrees - The world trees to read/write from
72
72
  * @param globalVariables - Global variables for the block
73
73
  * @param txEffects - Transaction effects to include in the block
74
- * @returns The created L2BlockNew with proper archive chaining
74
+ * @returns The created L2Block with proper archive chaining
75
75
  */
76
76
  export async function makeTXEBlock(
77
77
  worldTrees: MerkleTreeWriteOperations,
78
78
  globalVariables: GlobalVariables,
79
79
  txEffects: TxEffect[],
80
- ): Promise<L2BlockNew> {
80
+ ): Promise<L2Block> {
81
81
  const header = await makeTXEBlockHeader(worldTrees, globalVariables);
82
82
 
83
83
  // Update the archive tree with this block's header hash
@@ -87,9 +87,11 @@ export async function makeTXEBlock(
87
87
  const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
88
88
  const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
89
89
 
90
- // L2BlockNew requires checkpointNumber and indexWithinCheckpoint
90
+ // L2Block requires checkpointNumber and indexWithinCheckpoint.
91
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
92
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
91
93
  const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
92
94
  const indexWithinCheckpoint = IndexWithinCheckpoint(0);
93
95
 
94
- return new L2BlockNew(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
96
+ return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
95
97
  }
@@ -1,12 +0,0 @@
1
- import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
- import { Fr } from '@aztec/aztec.js/fields';
3
- import { ContractStore } from '@aztec/pxe/server';
4
- export type ContractArtifactWithHash = ContractArtifact & {
5
- artifactHash: Fr;
6
- };
7
- export declare class TXEContractStore extends ContractStore {
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2NvbnRyYWN0X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC90eGVfY29udHJhY3Rfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDNUMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWxELE1BQU0sTUFBTSx3QkFBd0IsR0FBRyxnQkFBZ0IsR0FBRztJQUFFLFlBQVksRUFBRSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBTy9FLHFCQUFhLGdCQUFpQixTQUFRLGFBQWE7O0lBRzNCLG1CQUFtQixDQUN2QyxFQUFFLEVBQUUsRUFBRSxFQUNOLFFBQVEsRUFBRSxnQkFBZ0IsR0FBRyx3QkFBd0IsR0FDcEQsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUtmO0lBRXFCLG1CQUFtQixDQUN2QyxlQUFlLEVBQUUsRUFBRSxHQUNsQixPQUFPLENBQUMsZ0JBQWdCLEdBQUcsd0JBQXdCLEdBQUcsU0FBUyxDQUFDLENBUWxFO0NBQ0YifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"txe_contract_store.d.ts","sourceRoot":"","sources":["../../src/util/txe_contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,CAAC;AAO/E,qBAAa,gBAAiB,SAAQ,aAAa;;IAG3B,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"}
@@ -1,22 +0,0 @@
1
- import { Fr } from '@aztec/aztec.js/fields';
2
- import { ContractStore } from '@aztec/pxe/server';
3
- /*
4
- * A contract store that stores contract artifacts with their hashes. Since
5
- * TXE typically deploys the same contract again and again for multiple tests, caching
6
- * the *very* expensive artifact hash computation improves testing speed significantly.
7
- */ export class TXEContractStore extends ContractStore {
8
- #artifactHashes = new Map();
9
- async addContractArtifact(id, artifact) {
10
- if ('artifactHash' in artifact) {
11
- this.#artifactHashes.set(id.toString(), artifact.artifactHash.toBuffer());
12
- }
13
- await super.addContractArtifact(id, artifact);
14
- }
15
- async getContractArtifact(contractClassId) {
16
- const artifact = await super.getContractArtifact(contractClassId);
17
- if (artifact && this.#artifactHashes.has(contractClassId.toString())) {
18
- artifact.artifactHash = Fr.fromBuffer(this.#artifactHashes.get(contractClassId.toString()));
19
- }
20
- return artifact;
21
- }
22
- }
@@ -1,36 +0,0 @@
1
- import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
- import { Fr } from '@aztec/aztec.js/fields';
3
- import { ContractStore } from '@aztec/pxe/server';
4
-
5
- export type ContractArtifactWithHash = ContractArtifact & { artifactHash: Fr };
6
-
7
- /*
8
- * A contract store that stores contract artifacts with their hashes. Since
9
- * TXE typically deploys the same contract again and again for multiple tests, caching
10
- * the *very* expensive artifact hash computation improves testing speed significantly.
11
- */
12
- export class TXEContractStore extends ContractStore {
13
- #artifactHashes: Map<string, Buffer> = new Map();
14
-
15
- public override async addContractArtifact(
16
- id: Fr,
17
- artifact: ContractArtifact | ContractArtifactWithHash,
18
- ): Promise<void> {
19
- if ('artifactHash' in artifact) {
20
- this.#artifactHashes.set(id.toString(), artifact.artifactHash.toBuffer());
21
- }
22
- await super.addContractArtifact(id, artifact);
23
- }
24
-
25
- public override async getContractArtifact(
26
- contractClassId: Fr,
27
- ): Promise<ContractArtifact | ContractArtifactWithHash | undefined> {
28
- const artifact = await super.getContractArtifact(contractClassId);
29
- if (artifact && this.#artifactHashes.has(contractClassId.toString())) {
30
- (artifact as ContractArtifactWithHash).artifactHash = Fr.fromBuffer(
31
- this.#artifactHashes.get(contractClassId.toString())!,
32
- );
33
- }
34
- return artifact;
35
- }
36
- }