@aztec/stdlib 1.0.0-nightly.20250607 → 1.0.0-nightly.20250610

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 (130) hide show
  1. package/dest/block/l2_block.js +1 -1
  2. package/dest/hash/hash.d.ts +8 -2
  3. package/dest/hash/hash.d.ts.map +1 -1
  4. package/dest/hash/hash.js +8 -16
  5. package/dest/interfaces/epoch-prover.d.ts +3 -1
  6. package/dest/interfaces/epoch-prover.d.ts.map +1 -1
  7. package/dest/interfaces/proving-job.d.ts +1 -1
  8. package/dest/interfaces/proving-job.d.ts.map +1 -1
  9. package/dest/interfaces/service.d.ts +1 -1
  10. package/dest/interfaces/service.d.ts.map +1 -1
  11. package/dest/kernel/index.d.ts +0 -1
  12. package/dest/kernel/index.d.ts.map +1 -1
  13. package/dest/kernel/index.js +0 -1
  14. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  15. package/dest/p2p/consensus_payload.js +9 -3
  16. package/dest/rollup/base_or_merge_rollup_public_inputs.d.ts +3 -3
  17. package/dest/rollup/base_or_merge_rollup_public_inputs.d.ts.map +1 -1
  18. package/dest/rollup/base_or_merge_rollup_public_inputs.js +3 -3
  19. package/dest/rollup/base_rollup_hints.d.ts +15 -14
  20. package/dest/rollup/base_rollup_hints.d.ts.map +1 -1
  21. package/dest/rollup/base_rollup_hints.js +13 -12
  22. package/dest/rollup/block_constant_data.d.ts +37 -0
  23. package/dest/rollup/block_constant_data.d.ts.map +1 -0
  24. package/dest/rollup/{constant_rollup_data.js → block_constant_data.js} +10 -13
  25. package/dest/rollup/block_root_or_block_merge_public_inputs.d.ts +12 -27
  26. package/dest/rollup/block_root_or_block_merge_public_inputs.d.ts.map +1 -1
  27. package/dest/rollup/block_root_or_block_merge_public_inputs.js +8 -15
  28. package/dest/rollup/block_root_rollup.d.ts +24 -9
  29. package/dest/rollup/block_root_rollup.d.ts.map +1 -1
  30. package/dest/rollup/block_root_rollup.js +15 -7
  31. package/dest/rollup/empty_block_root_rollup_inputs.d.ts +4 -4
  32. package/dest/rollup/empty_block_root_rollup_inputs.d.ts.map +1 -1
  33. package/dest/rollup/empty_block_root_rollup_inputs.js +2 -2
  34. package/dest/rollup/epoch_constant_data.d.ts +39 -0
  35. package/dest/rollup/epoch_constant_data.d.ts.map +1 -0
  36. package/dest/rollup/epoch_constant_data.js +40 -0
  37. package/dest/rollup/index.d.ts +2 -1
  38. package/dest/rollup/index.d.ts.map +1 -1
  39. package/dest/rollup/index.js +2 -1
  40. package/dest/rollup/root_rollup.d.ts +7 -11
  41. package/dest/rollup/root_rollup.d.ts.map +1 -1
  42. package/dest/rollup/root_rollup.js +7 -10
  43. package/dest/snapshots/types.d.ts +4 -4
  44. package/dest/tests/factories.d.ts +1 -10
  45. package/dest/tests/factories.d.ts.map +1 -1
  46. package/dest/tests/factories.js +23 -36
  47. package/dest/tests/mocks.d.ts.map +1 -1
  48. package/dest/tests/mocks.js +3 -3
  49. package/dest/trees/append_only_tree_snapshot.d.ts +6 -2
  50. package/dest/trees/append_only_tree_snapshot.d.ts.map +1 -1
  51. package/dest/trees/append_only_tree_snapshot.js +17 -2
  52. package/dest/tx/block_header.js +3 -3
  53. package/dest/tx/content_commitment.d.ts +3 -0
  54. package/dest/tx/content_commitment.d.ts.map +1 -1
  55. package/dest/tx/content_commitment.js +12 -1
  56. package/dest/tx/global_variables.js +1 -1
  57. package/dest/tx/index.d.ts +1 -0
  58. package/dest/tx/index.d.ts.map +1 -1
  59. package/dest/tx/index.js +1 -0
  60. package/dest/tx/offchain_message.d.ts +15 -0
  61. package/dest/tx/offchain_message.d.ts.map +1 -0
  62. package/dest/tx/offchain_message.js +4 -0
  63. package/dest/tx/partial_state_reference.d.ts +8 -0
  64. package/dest/tx/partial_state_reference.d.ts.map +1 -1
  65. package/dest/tx/partial_state_reference.js +19 -2
  66. package/dest/tx/private_execution_result.d.ts +18 -0
  67. package/dest/tx/private_execution_result.d.ts.map +1 -1
  68. package/dest/tx/private_execution_result.js +32 -2
  69. package/dest/tx/processed_tx.d.ts +2 -3
  70. package/dest/tx/processed_tx.d.ts.map +1 -1
  71. package/dest/tx/processed_tx.js +18 -8
  72. package/dest/tx/proposed_block_header.d.ts +3 -0
  73. package/dest/tx/proposed_block_header.d.ts.map +1 -1
  74. package/dest/tx/proposed_block_header.js +19 -1
  75. package/dest/tx/proven_tx.d.ts +2 -0
  76. package/dest/tx/proven_tx.d.ts.map +1 -1
  77. package/dest/tx/proven_tx.js +4 -1
  78. package/dest/tx/public_simulation_output.d.ts +3 -3
  79. package/dest/tx/public_simulation_output.d.ts.map +1 -1
  80. package/dest/tx/public_simulation_output.js +7 -7
  81. package/dest/tx/state_reference.d.ts +4 -0
  82. package/dest/tx/state_reference.d.ts.map +1 -1
  83. package/dest/tx/state_reference.js +20 -3
  84. package/dest/tx/tree_snapshots.js +3 -3
  85. package/dest/tx/tx.d.ts +1 -1
  86. package/dest/tx/tx.js +1 -1
  87. package/dest/tx/tx_hash.d.ts +1 -0
  88. package/dest/tx/tx_hash.d.ts.map +1 -1
  89. package/dest/tx/tx_hash.js +1 -0
  90. package/package.json +7 -7
  91. package/src/block/l2_block.ts +1 -1
  92. package/src/hash/hash.ts +16 -19
  93. package/src/interfaces/epoch-prover.ts +8 -2
  94. package/src/interfaces/service.ts +1 -1
  95. package/src/kernel/index.ts +0 -1
  96. package/src/p2p/consensus_payload.ts +13 -3
  97. package/src/rollup/base_or_merge_rollup_public_inputs.ts +4 -4
  98. package/src/rollup/base_rollup_hints.ts +12 -11
  99. package/src/rollup/block_constant_data.ts +63 -0
  100. package/src/rollup/block_root_or_block_merge_public_inputs.ts +10 -21
  101. package/src/rollup/block_root_rollup.ts +17 -5
  102. package/src/rollup/empty_block_root_rollup_inputs.ts +3 -3
  103. package/src/rollup/epoch_constant_data.ts +44 -0
  104. package/src/rollup/index.ts +2 -1
  105. package/src/rollup/root_rollup.ts +10 -12
  106. package/src/tests/factories.ts +36 -58
  107. package/src/tests/mocks.ts +3 -2
  108. package/src/trees/append_only_tree_snapshot.ts +18 -2
  109. package/src/tx/block_header.ts +3 -3
  110. package/src/tx/content_commitment.ts +19 -1
  111. package/src/tx/global_variables.ts +1 -1
  112. package/src/tx/index.ts +1 -0
  113. package/src/tx/offchain_message.ts +16 -0
  114. package/src/tx/partial_state_reference.ts +29 -4
  115. package/src/tx/private_execution_result.ts +30 -0
  116. package/src/tx/processed_tx.ts +26 -13
  117. package/src/tx/proposed_block_header.ts +31 -1
  118. package/src/tx/proven_tx.ts +10 -1
  119. package/src/tx/public_simulation_output.ts +5 -5
  120. package/src/tx/state_reference.ts +22 -3
  121. package/src/tx/tree_snapshots.ts +9 -9
  122. package/src/tx/tx.ts +1 -1
  123. package/src/tx/tx_hash.ts +1 -0
  124. package/dest/kernel/combined_constant_data.d.ts +0 -71
  125. package/dest/kernel/combined_constant_data.d.ts.map +0 -1
  126. package/dest/kernel/combined_constant_data.js +0 -73
  127. package/dest/rollup/constant_rollup_data.d.ts +0 -45
  128. package/dest/rollup/constant_rollup_data.d.ts.map +0 -1
  129. package/src/kernel/combined_constant_data.ts +0 -128
  130. package/src/rollup/constant_rollup_data.ts +0 -54
@@ -1,4 +1,4 @@
1
- import { makeBlockBlobPublicInputs, makeSpongeBlob } from '@aztec/blob-lib/testing';
1
+ import { makeBatchedBlobAccumulator, makeBlockBlobPublicInputs, makeSpongeBlob } from '@aztec/blob-lib/testing';
2
2
  import {
3
3
  ARCHIVE_HEIGHT,
4
4
  AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
@@ -46,7 +46,7 @@ import { toBufferBE } from '@aztec/foundation/bigint-buffer';
46
46
  import { compact } from '@aztec/foundation/collection';
47
47
  import { SchnorrSignature, poseidon2HashWithSeparator, sha256 } from '@aztec/foundation/crypto';
48
48
  import { EthAddress } from '@aztec/foundation/eth-address';
49
- import { Fr, GrumpkinScalar, Point } from '@aztec/foundation/fields';
49
+ import { BLS12Point, Fr, GrumpkinScalar, Point } from '@aztec/foundation/fields';
50
50
  import type { Bufferable } from '@aztec/foundation/serialize';
51
51
  import { MembershipWitness } from '@aztec/foundation/trees';
52
52
 
@@ -99,7 +99,6 @@ import { KeyValidationRequestAndGenerator } from '../kernel/hints/key_validation
99
99
  import { ReadRequest } from '../kernel/hints/read_request.js';
100
100
  import { RollupValidationRequests } from '../kernel/hints/rollup_validation_requests.js';
101
101
  import {
102
- CombinedConstantData,
103
102
  PartialPrivateTailPublicInputsForPublic,
104
103
  PartialPrivateTailPublicInputsForRollup,
105
104
  PrivateKernelTailCircuitPublicInputs,
@@ -145,8 +144,9 @@ import {
145
144
  BlockRootRollupInputs,
146
145
  SingleTxBlockRootRollupInputs,
147
146
  } from '../rollup/block_root_rollup.js';
148
- import { ConstantRollupData } from '../rollup/constant_rollup_data.js';
149
147
  import { EmptyBlockRootRollupInputs } from '../rollup/empty_block_root_rollup_inputs.js';
148
+ import { EpochConstantData } from '../rollup/epoch_constant_data.js';
149
+ import { BlockConstantData } from '../rollup/index.js';
150
150
  import { MergeRollupInputs } from '../rollup/merge_rollup.js';
151
151
  import { PreviousRollupBlockData } from '../rollup/previous_rollup_block_data.js';
152
152
  import { PreviousRollupData } from '../rollup/previous_rollup_data.js';
@@ -314,16 +314,6 @@ function makeTxConstantData(seed = 1) {
314
314
  return new TxConstantData(makeHeader(seed), makeTxContext(seed + 0x100), new Fr(seed + 0x200), new Fr(seed + 0x201));
315
315
  }
316
316
 
317
- export function makeCombinedConstantData(seed = 1): CombinedConstantData {
318
- return new CombinedConstantData(
319
- makeHeader(seed),
320
- makeTxContext(seed + 0x100),
321
- new Fr(seed + 0x200),
322
- new Fr(seed + 0x201),
323
- makeGlobalVariables(seed + 0x300),
324
- );
325
- }
326
-
327
317
  /**
328
318
  * Creates arbitrary accumulated data.
329
319
  * @param seed - The seed to use for generating the accumulated data.
@@ -626,24 +616,6 @@ export function makeFeeRecipient(seed = 1) {
626
616
  return new FeeRecipient(EthAddress.fromField(fr(seed)), fr(seed + 1));
627
617
  }
628
618
 
629
- /**
630
- * Makes constant base rollup data.
631
- * @param seed - The seed to use for generating the constant base rollup data.
632
- * @param blockNumber - The block number to use for generating the global variables.
633
- * @returns A constant base rollup data.
634
- */
635
- export function makeConstantRollupData(
636
- seed = 1,
637
- globalVariables: GlobalVariables | undefined = undefined,
638
- ): ConstantRollupData {
639
- return ConstantRollupData.from({
640
- lastArchive: makeAppendOnlyTreeSnapshot(seed + 0x300),
641
- vkTreeRoot: fr(seed + 0x401),
642
- protocolContractTreeRoot: fr(seed + 0x402),
643
- globalVariables: globalVariables ?? makeGlobalVariables(seed + 0x500),
644
- });
645
- }
646
-
647
619
  /**
648
620
  * Makes arbitrary append only tree snapshot.
649
621
  * @param seed - The seed to use for generating the append only tree snapshot.
@@ -690,6 +662,16 @@ export function makeSchnorrSignature(seed = 1): SchnorrSignature {
690
662
  return new SchnorrSignature(Buffer.alloc(SchnorrSignature.SIZE, seed));
691
663
  }
692
664
 
665
+ function makeBlockConstantData(seed = 1, globalVariables?: GlobalVariables) {
666
+ return new BlockConstantData(
667
+ makeAppendOnlyTreeSnapshot(seed + 0x100),
668
+ makeAppendOnlyTreeSnapshot(seed + 0x200),
669
+ fr(seed + 0x300),
670
+ fr(seed + 0x400),
671
+ globalVariables ?? makeGlobalVariables(seed + 0x500),
672
+ );
673
+ }
674
+
693
675
  /**
694
676
  * Makes arbitrary base or merge rollup circuit public inputs.
695
677
  * @param seed - The seed to use for generating the base rollup circuit public inputs.
@@ -703,7 +685,7 @@ export function makeBaseOrMergeRollupPublicInputs(
703
685
  return new BaseOrMergeRollupPublicInputs(
704
686
  RollupTypes.Base,
705
687
  1,
706
- makeConstantRollupData(seed + 0x200, globalVariables),
688
+ makeBlockConstantData(seed + 0x200, globalVariables),
707
689
  makePartialStateReference(seed + 0x300),
708
690
  makePartialStateReference(seed + 0x400),
709
691
  makeSpongeBlob(seed + 0x500),
@@ -714,6 +696,10 @@ export function makeBaseOrMergeRollupPublicInputs(
714
696
  );
715
697
  }
716
698
 
699
+ function makeEpochConstantData(seed = 1) {
700
+ return new EpochConstantData(fr(seed), fr(seed + 1), fr(seed + 2));
701
+ }
702
+
717
703
  /**
718
704
  * Makes arbitrary block merge or block root rollup circuit public inputs.
719
705
  * @param seed - The seed to use for generating the block merge or block root rollup circuit public inputs.
@@ -725,6 +711,7 @@ export function makeBlockRootOrBlockMergeRollupPublicInputs(
725
711
  globalVariables: GlobalVariables | undefined = undefined,
726
712
  ): BlockRootOrBlockMergePublicInputs {
727
713
  return new BlockRootOrBlockMergePublicInputs(
714
+ makeEpochConstantData(seed + 0x100),
728
715
  makeAppendOnlyTreeSnapshot(seed + 0x200),
729
716
  makeAppendOnlyTreeSnapshot(seed + 0x300),
730
717
  globalVariables ?? makeGlobalVariables(seed + 0x400),
@@ -732,10 +719,7 @@ export function makeBlockRootOrBlockMergeRollupPublicInputs(
732
719
  fr(seed + 0x600),
733
720
  makeTuple(AZTEC_MAX_EPOCH_DURATION, () => fr(seed), 0x650),
734
721
  makeTuple(AZTEC_MAX_EPOCH_DURATION, () => makeFeeRecipient(seed), 0x700),
735
- fr(seed + 0x800),
736
- fr(seed + 0x801),
737
- fr(seed + 0x900),
738
- makeTuple(AZTEC_MAX_EPOCH_DURATION, () => makeBlockBlobPublicInputs(seed), 0x100),
722
+ makeBlockBlobPublicInputs(seed),
739
723
  );
740
724
  }
741
725
 
@@ -786,10 +770,10 @@ export function makePreviousRollupBlockData(
786
770
  * @returns A root rollup inputs.
787
771
  */
788
772
  export function makeRootRollupInputs(seed = 0, globalVariables?: GlobalVariables): RootRollupInputs {
789
- return new RootRollupInputs(
790
- [makePreviousRollupBlockData(seed, globalVariables), makePreviousRollupBlockData(seed + 0x1000, globalVariables)],
791
- fr(seed + 0x2000),
792
- );
773
+ return new RootRollupInputs([
774
+ makePreviousRollupBlockData(seed, globalVariables),
775
+ makePreviousRollupBlockData(seed + 0x1000, globalVariables),
776
+ ]);
793
777
  }
794
778
 
795
779
  function makeBlockRootRollupData(seed = 0) {
@@ -799,14 +783,16 @@ function makeBlockRootRollupData(seed = 0) {
799
783
  makeTuple(ARCHIVE_HEIGHT, fr, 0x2200),
800
784
  makeTuple(ARCHIVE_HEIGHT, fr, 0x2300),
801
785
  makeHeader(seed + 0x2400),
802
- fr(seed + 0x2500),
786
+ makeBatchedBlobAccumulator(seed + 0x2500).toBlobAccumulatorPublicInputs(),
787
+ makeBatchedBlobAccumulator(seed + 0x2600).finalBlobChallenges,
788
+ fr(seed + 0x2700),
803
789
  );
804
790
  }
805
791
 
806
792
  function makeBlockRootRollupBlobData(seed = 0) {
807
793
  return new BlockRootRollupBlobData(
808
794
  makeTuple(FIELDS_PER_BLOB * BLOBS_PER_BLOCK, fr, 0x2500),
809
- makeTuple(BLOBS_PER_BLOCK, () => makeTuple(2, fr, 0x2600)),
795
+ makeTuple(BLOBS_PER_BLOCK, () => BLS12Point.random()),
810
796
  fr(seed + 0x2700),
811
797
  );
812
798
  }
@@ -845,7 +831,7 @@ export function makeEmptyBlockRootRollupInputs(
845
831
  ): EmptyBlockRootRollupInputs {
846
832
  return new EmptyBlockRootRollupInputs(
847
833
  makeBlockRootRollupData(seed + 0x1000),
848
- makeConstantRollupData(0x2500, globalVariables),
834
+ makeBlockConstantData(0x2500, globalVariables),
849
835
  true,
850
836
  );
851
837
  }
@@ -901,7 +887,7 @@ export function makeRootRollupPublicInputs(seed = 0): RootRollupPublicInputs {
901
887
  fr(seed + 0x702),
902
888
  fr(seed + 0x703),
903
889
  fr(seed + 0x704),
904
- makeTuple(AZTEC_MAX_EPOCH_DURATION, () => makeBlockBlobPublicInputs(seed), 0x800),
890
+ makeBatchedBlobAccumulator(seed).toFinalBlobAccumulatorPublicInputs(),
905
891
  );
906
892
  }
907
893
 
@@ -1113,7 +1099,7 @@ function makePrivateBaseRollupHints(seed = 1) {
1113
1099
 
1114
1100
  const contractClassLogsFields = makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, makeContractClassLogFields, seed + 0x800);
1115
1101
 
1116
- const constants = makeConstantRollupData(0x100);
1102
+ const constants = makeBlockConstantData(0x100);
1117
1103
 
1118
1104
  const feePayerFeeJuiceBalanceReadHint = PublicDataHint.empty();
1119
1105
 
@@ -1129,19 +1115,11 @@ function makePrivateBaseRollupHints(seed = 1) {
1129
1115
  }
1130
1116
 
1131
1117
  function makePublicBaseRollupHints(seed = 1) {
1132
- const startSpongeBlob = makeSpongeBlob(seed + 0x200);
1133
-
1134
- const archiveRootMembershipWitness = makeMembershipWitness(ARCHIVE_HEIGHT, seed + 0x9000);
1135
-
1136
- const contractClassLogsFields = makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, makeContractClassLogFields, seed + 0x800);
1137
-
1138
- const constants = makeConstantRollupData(0x100);
1139
-
1140
1118
  return PublicBaseRollupHints.from({
1141
- startSpongeBlob,
1142
- archiveRootMembershipWitness,
1143
- contractClassLogsFields,
1144
- constants,
1119
+ startSpongeBlob: makeSpongeBlob(seed),
1120
+ lastArchive: makeAppendOnlyTreeSnapshot(seed + 0x1000),
1121
+ archiveRootMembershipWitness: makeMembershipWitness(ARCHIVE_HEIGHT, seed + 0x2000),
1122
+ contractClassLogsFields: makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, makeContractClassLogFields, seed + 0x3000),
1145
1123
  });
1146
1124
  }
1147
1125
 
@@ -41,7 +41,7 @@ import { PublicSimulationOutput } from '../tx/public_simulation_output.js';
41
41
  import { TxSimulationResult, accumulatePrivateReturnValues } from '../tx/simulated_tx.js';
42
42
  import { TxEffect } from '../tx/tx_effect.js';
43
43
  import { TxHash } from '../tx/tx_hash.js';
44
- import { makeCombinedConstantData, makeGas, makeHeader, makePublicCallRequest } from './factories.js';
44
+ import { makeGas, makeGlobalVariables, makeHeader, makePublicCallRequest } from './factories.js';
45
45
 
46
46
  export const randomTxHash = (): TxHash => TxHash.random();
47
47
 
@@ -181,6 +181,7 @@ const emptyPrivateCallExecutionResult = () =>
181
181
  [],
182
182
  [],
183
183
  [],
184
+ [],
184
185
  );
185
186
 
186
187
  const emptyPrivateExecutionResult = () => new PrivateExecutionResult(emptyPrivateCallExecutionResult(), Fr.zero(), []);
@@ -190,7 +191,7 @@ export const mockSimulatedTx = async (seed = 1) => {
190
191
  const tx = await mockTx(seed);
191
192
  const output = new PublicSimulationOutput(
192
193
  undefined,
193
- makeCombinedConstantData(),
194
+ makeGlobalVariables(),
194
195
  await TxEffect.random(),
195
196
  [accumulatePrivateReturnValues(privateExecutionResult)],
196
197
  {
@@ -1,3 +1,4 @@
1
+ import type { ViemAppendOnlyTreeSnapshot } from '@aztec/ethereum';
1
2
  import { Fr } from '@aztec/foundation/fields';
2
3
  import { schemas } from '@aztec/foundation/schemas';
3
4
  import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';
@@ -71,11 +72,26 @@ export class AppendOnlyTreeSnapshot {
71
72
  return new AppendOnlyTreeSnapshot(reader.readField(), Number(reader.readField().toBigInt()));
72
73
  }
73
74
 
74
- static zero() {
75
+ static fromViem(snapshot: ViemAppendOnlyTreeSnapshot) {
76
+ return new AppendOnlyTreeSnapshot(Fr.fromString(snapshot.root), snapshot.nextAvailableLeafIndex);
77
+ }
78
+
79
+ toViem(): ViemAppendOnlyTreeSnapshot {
80
+ return {
81
+ root: this.root.toString(),
82
+ nextAvailableLeafIndex: this.nextAvailableLeafIndex,
83
+ };
84
+ }
85
+
86
+ toAbi(): [`0x${string}`, number] {
87
+ return [this.root.toString(), this.nextAvailableLeafIndex];
88
+ }
89
+
90
+ static empty() {
75
91
  return new AppendOnlyTreeSnapshot(Fr.ZERO, 0);
76
92
  }
77
93
 
78
- isZero(): boolean {
94
+ isEmpty(): boolean {
79
95
  return this.root.isZero() && this.nextAvailableLeafIndex === 0;
80
96
  }
81
97
 
@@ -46,7 +46,7 @@ export class BlockHeader {
46
46
  }
47
47
 
48
48
  static getFields(fields: FieldsOf<BlockHeader>) {
49
- // Note: The order here must match the order in the HeaderLib solidity library.
49
+ // Note: The order here must match the order in the ProposedHeaderLib solidity library.
50
50
  return [
51
51
  fields.lastArchive,
52
52
  fields.contentCommitment,
@@ -124,7 +124,7 @@ export class BlockHeader {
124
124
 
125
125
  static empty(fields: Partial<FieldsOf<BlockHeader>> = {}): BlockHeader {
126
126
  return BlockHeader.from({
127
- lastArchive: AppendOnlyTreeSnapshot.zero(),
127
+ lastArchive: AppendOnlyTreeSnapshot.empty(),
128
128
  contentCommitment: ContentCommitment.empty(),
129
129
  state: StateReference.empty(),
130
130
  globalVariables: GlobalVariables.empty(),
@@ -136,7 +136,7 @@ export class BlockHeader {
136
136
 
137
137
  isEmpty(): boolean {
138
138
  return (
139
- this.lastArchive.isZero() &&
139
+ this.lastArchive.isEmpty() &&
140
140
  this.contentCommitment.isEmpty() &&
141
141
  this.state.isEmpty() &&
142
142
  this.globalVariables.isEmpty() &&
@@ -1,8 +1,9 @@
1
1
  import { CONTENT_COMMITMENT_LENGTH } from '@aztec/constants';
2
+ import type { ViemContentCommitment } from '@aztec/ethereum';
2
3
  import { Fr } from '@aztec/foundation/fields';
3
4
  import { schemas } from '@aztec/foundation/schemas';
4
5
  import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
- import { bufferToHex } from '@aztec/foundation/string';
6
+ import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
6
7
 
7
8
  import { z } from 'zod';
8
9
 
@@ -79,6 +80,14 @@ export class ContentCommitment {
79
80
  return serialized;
80
81
  }
81
82
 
83
+ toViem(): ViemContentCommitment {
84
+ return {
85
+ numTxs: this.numTxs.toBigInt(),
86
+ blobsHash: `0x${this.blobsHash.toString('hex').padStart(64, '0')}`,
87
+ inHash: `0x${this.inHash.toString('hex').padStart(64, '0')}`,
88
+ outHash: `0x${this.outHash.toString('hex').padStart(64, '0')}`,
89
+ };
90
+ }
82
91
  static fromBuffer(buffer: Buffer | BufferReader): ContentCommitment {
83
92
  const reader = BufferReader.asReader(buffer);
84
93
 
@@ -90,6 +99,15 @@ export class ContentCommitment {
90
99
  );
91
100
  }
92
101
 
102
+ static fromViem(contentCommitment: ViemContentCommitment) {
103
+ return new ContentCommitment(
104
+ new Fr(contentCommitment.numTxs),
105
+ hexToBuffer(contentCommitment.blobsHash),
106
+ hexToBuffer(contentCommitment.inHash),
107
+ hexToBuffer(contentCommitment.outHash),
108
+ );
109
+ }
110
+
93
111
  static fromFields(fields: Fr[] | FieldReader): ContentCommitment {
94
112
  const reader = FieldReader.asReader(fields);
95
113
  return new ContentCommitment(
@@ -102,7 +102,7 @@ export class GlobalVariables {
102
102
  }
103
103
 
104
104
  static getFields(fields: FieldsOf<GlobalVariables>) {
105
- // Note: The order here must match the order in the HeaderLib solidity library.
105
+ // Note: The order here must match the order in the ProposedHeaderLib solidity library.
106
106
  return [
107
107
  fields.chainId,
108
108
  fields.version,
package/src/tx/index.ts CHANGED
@@ -29,4 +29,5 @@ export * from './capsule.js';
29
29
  export * from './global_variable_builder.js';
30
30
  export * from './hashed_values.js';
31
31
  export * from './indexed_tx_effect.js';
32
+ export * from './offchain_message.js';
32
33
  export * from './profiling.js';
@@ -0,0 +1,16 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+
3
+ import type { AztecAddress } from '../aztec-address/index.js';
4
+
5
+ /**
6
+ * Represents an offchain message emitted via the `emit_offchain_message` oracle (see the oracle documentation for
7
+ * more details).
8
+ */
9
+ export type OffchainMessage = {
10
+ /** The message content */
11
+ message: Fr[];
12
+ /** The message recipient */
13
+ recipient: AztecAddress;
14
+ /** The contract that emitted the message */
15
+ contractAddress: AztecAddress;
16
+ };
@@ -1,4 +1,5 @@
1
1
  import { PARTIAL_STATE_REFERENCE_LENGTH } from '@aztec/constants';
2
+ import type { ViemPartialStateReference } from '@aztec/ethereum';
2
3
  import type { Fr } from '@aztec/foundation/fields';
3
4
  import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
5
 
@@ -55,11 +56,35 @@ export class PartialStateReference {
55
56
  return new PartialStateReference(noteHashTree, nullifierTree, publicDataTree);
56
57
  }
57
58
 
59
+ static fromViem(stateReference: ViemPartialStateReference) {
60
+ return new PartialStateReference(
61
+ AppendOnlyTreeSnapshot.fromViem(stateReference.noteHashTree),
62
+ AppendOnlyTreeSnapshot.fromViem(stateReference.nullifierTree),
63
+ AppendOnlyTreeSnapshot.fromViem(stateReference.publicDataTree),
64
+ );
65
+ }
66
+
67
+ toViem(): ViemPartialStateReference {
68
+ return {
69
+ noteHashTree: this.noteHashTree.toViem(),
70
+ nullifierTree: this.nullifierTree.toViem(),
71
+ publicDataTree: this.publicDataTree.toViem(),
72
+ };
73
+ }
74
+
75
+ toAbi(): [
76
+ ReturnType<AppendOnlyTreeSnapshot['toAbi']>,
77
+ ReturnType<AppendOnlyTreeSnapshot['toAbi']>,
78
+ ReturnType<AppendOnlyTreeSnapshot['toAbi']>,
79
+ ] {
80
+ return [this.noteHashTree.toAbi(), this.nullifierTree.toAbi(), this.publicDataTree.toAbi()];
81
+ }
82
+
58
83
  static empty(): PartialStateReference {
59
84
  return new PartialStateReference(
60
- AppendOnlyTreeSnapshot.zero(),
61
- AppendOnlyTreeSnapshot.zero(),
62
- AppendOnlyTreeSnapshot.zero(),
85
+ AppendOnlyTreeSnapshot.empty(),
86
+ AppendOnlyTreeSnapshot.empty(),
87
+ AppendOnlyTreeSnapshot.empty(),
63
88
  );
64
89
  }
65
90
 
@@ -82,7 +107,7 @@ export class PartialStateReference {
82
107
  }
83
108
 
84
109
  isEmpty(): boolean {
85
- return this.noteHashTree.isZero() && this.nullifierTree.isZero() && this.publicDataTree.isZero();
110
+ return this.noteHashTree.isEmpty() && this.nullifierTree.isEmpty() && this.publicDataTree.isEmpty();
86
111
  }
87
112
 
88
113
  public equals(other: this): boolean {
@@ -6,6 +6,7 @@ import type { FieldsOf } from '@aztec/foundation/types';
6
6
  import { z } from 'zod';
7
7
 
8
8
  import { NoteSelector } from '../abi/note_selector.js';
9
+ import { AztecAddress } from '../aztec-address/index.js';
9
10
  import { PrivateCircuitPublicInputs } from '../kernel/private_circuit_public_inputs.js';
10
11
  import type { IsEmpty } from '../kernel/utils/interfaces.js';
11
12
  import { sortByCounter } from '../kernel/utils/order_and_comparison.js';
@@ -13,6 +14,7 @@ import { ContractClassLog, ContractClassLogFields } from '../logs/contract_class
13
14
  import { Note } from '../note/note.js';
14
15
  import { type ZodFor, mapSchema, schemas } from '../schemas/index.js';
15
16
  import { HashedValues } from './hashed_values.js';
17
+ import type { OffchainMessage } from './offchain_message.js';
16
18
 
17
19
  /**
18
20
  * The contents of a new note.
@@ -131,6 +133,8 @@ export class PrivateCallExecutionResult {
131
133
  public noteHashNullifierCounterMap: Map<number, number>,
132
134
  /** The raw return values of the executed function. */
133
135
  public returnValues: Fr[],
136
+ /** The offchain messages emitted during execution of this function call via the `emit_offchain_message` oracle. */
137
+ public offchainMessages: { message: Fr[]; recipient: AztecAddress }[],
134
138
  /** The nested executions. */
135
139
  public nestedExecutions: PrivateCallExecutionResult[],
136
140
  /**
@@ -153,6 +157,7 @@ export class PrivateCallExecutionResult {
153
157
  newNotes: z.array(NoteAndSlot.schema),
154
158
  noteHashNullifierCounterMap: mapSchema(z.coerce.number(), z.number()),
155
159
  returnValues: z.array(schemas.Fr),
160
+ offchainMessages: z.array(z.object({ message: z.array(schemas.Fr), recipient: AztecAddress.schema })),
156
161
  nestedExecutions: z.array(z.lazy(() => PrivateCallExecutionResult.schema)),
157
162
  contractClassLogs: z.array(CountedContractClassLog.schema),
158
163
  })
@@ -169,6 +174,7 @@ export class PrivateCallExecutionResult {
169
174
  fields.newNotes,
170
175
  fields.noteHashNullifierCounterMap,
171
176
  fields.returnValues,
177
+ fields.offchainMessages,
172
178
  fields.nestedExecutions,
173
179
  fields.contractClassLogs,
174
180
  );
@@ -184,6 +190,12 @@ export class PrivateCallExecutionResult {
184
190
  [NoteAndSlot.random()],
185
191
  new Map([[0, 0]]),
186
192
  [Fr.random()],
193
+ [
194
+ {
195
+ message: [Fr.random()],
196
+ recipient: await AztecAddress.random(),
197
+ },
198
+ ],
187
199
  await timesParallel(nested, () => PrivateCallExecutionResult.random(0)),
188
200
  [new CountedContractClassLog(await ContractClassLog.random(), randomInt(10))],
189
201
  );
@@ -233,6 +245,24 @@ export function collectSortedContractClassLogs(execResult: PrivateExecutionResul
233
245
  return sortedLogs.map(l => l.log.fields);
234
246
  }
235
247
 
248
+ /**
249
+ * Collect all offchain messages emitted across all nested executions.
250
+ * @param execResult - The execution result to collect messages from.
251
+ * @returns Array of offchain messages.
252
+ */
253
+ export function collectOffchainMessages(execResult: PrivateExecutionResult): OffchainMessage[] {
254
+ const collectMessagesRecursive = (callResult: PrivateCallExecutionResult): OffchainMessage[] => {
255
+ return [
256
+ ...callResult.offchainMessages.map(msg => ({
257
+ ...msg,
258
+ contractAddress: callResult.publicInputs.callContext.contractAddress, // contract that emitted the message
259
+ })),
260
+ ...callResult.nestedExecutions.flatMap(nested => collectMessagesRecursive(nested)),
261
+ ];
262
+ };
263
+ return collectMessagesRecursive(execResult.entrypoint);
264
+ }
265
+
236
266
  export function getFinalMinRevertibleSideEffectCounter(execResult: PrivateExecutionResult): number {
237
267
  const collectFinalMinRevertibleSideEffectCounterRecursive = (callResult: PrivateCallExecutionResult): number => {
238
268
  return callResult.nestedExecutions.reduce((counter, exec) => {
@@ -6,8 +6,7 @@ import { RevertCode } from '../avm/revert_code.js';
6
6
  import type { SimulationError } from '../errors/simulation_error.js';
7
7
  import { Gas } from '../gas/gas.js';
8
8
  import type { GasUsed } from '../gas/gas_used.js';
9
- import { siloL2ToL1Message } from '../hash/hash.js';
10
- import { CombinedConstantData } from '../kernel/combined_constant_data.js';
9
+ import { computeL2ToL1MessageHash } from '../hash/hash.js';
11
10
  import type { PrivateKernelTailCircuitPublicInputs } from '../kernel/private_kernel_tail_circuit_public_inputs.js';
12
11
  import type { ClientIvcProof } from '../proofs/client_ivc_proof.js';
13
12
  import type { GlobalVariables } from './global_variables.js';
@@ -43,9 +42,9 @@ export type ProcessedTx = {
43
42
  */
44
43
  avmProvingRequest: AvmProvingRequest | undefined;
45
44
  /**
46
- * Combining `TxConstantData` specified by the user, and `GlobalVariables` injected by the sequencer.
45
+ * `GlobalVariables` injected by the sequencer. It's the same for all the txs in a block.
47
46
  */
48
- constants: CombinedConstantData;
47
+ globalVariables: GlobalVariables;
49
48
  /**
50
49
  * Output data of the tx.
51
50
  */
@@ -84,8 +83,6 @@ export async function makeProcessedTxFromPrivateOnlyTx(
84
83
  feePaymentPublicDataWrite: PublicDataWrite,
85
84
  globalVariables: GlobalVariables,
86
85
  ): Promise<ProcessedTx> {
87
- const constants = CombinedConstantData.combine(tx.data.constants, globalVariables);
88
-
89
86
  const data = tx.data.forRollup!;
90
87
  const txEffect = new TxEffect(
91
88
  RevertCode.OK,
@@ -94,8 +91,16 @@ export async function makeProcessedTxFromPrivateOnlyTx(
94
91
  data.end.noteHashes.filter(h => !h.isZero()),
95
92
  data.end.nullifiers.filter(h => !h.isZero()),
96
93
  data.end.l2ToL1Msgs
97
- .map(message => siloL2ToL1Message(message, constants.txContext.version, constants.txContext.chainId))
98
- .filter(h => !h.isZero()),
94
+ .filter(msg => !msg.contractAddress.isZero())
95
+ .map(msg =>
96
+ computeL2ToL1MessageHash({
97
+ l2Sender: msg.contractAddress,
98
+ l1Recipient: msg.message.recipient,
99
+ content: msg.message.content,
100
+ rollupVersion: globalVariables.version,
101
+ chainId: globalVariables.chainId,
102
+ }),
103
+ ),
99
104
  [feePaymentPublicDataWrite],
100
105
  data.end.privateLogs.filter(l => !l.isEmpty()),
101
106
  [],
@@ -115,7 +120,7 @@ export async function makeProcessedTxFromPrivateOnlyTx(
115
120
  data: tx.data,
116
121
  clientIvcProof: tx.clientIvcProof,
117
122
  avmProvingRequest: undefined,
118
- constants,
123
+ globalVariables,
119
124
  txEffect,
120
125
  gasUsed,
121
126
  revertCode: RevertCode.OK,
@@ -138,7 +143,7 @@ export async function makeProcessedTxFromTxWithPublicCalls(
138
143
  ): Promise<ProcessedTx> {
139
144
  const avmPublicInputs = avmProvingRequest.inputs.publicInputs;
140
145
 
141
- const constants = CombinedConstantData.combine(tx.data.constants, avmPublicInputs.globalVariables);
146
+ const globalVariables = avmPublicInputs.globalVariables;
142
147
 
143
148
  const publicDataWrites = avmPublicInputs.accumulatedData.publicDataWrites.filter(w => !w.isEmpty());
144
149
 
@@ -158,8 +163,16 @@ export async function makeProcessedTxFromTxWithPublicCalls(
158
163
  avmPublicInputs.accumulatedData.noteHashes.filter(h => !h.isZero()),
159
164
  avmPublicInputs.accumulatedData.nullifiers.filter(h => !h.isZero()),
160
165
  avmPublicInputs.accumulatedData.l2ToL1Msgs
161
- .map(message => siloL2ToL1Message(message, constants.txContext.version, constants.txContext.chainId))
162
- .filter(h => !h.isZero()),
166
+ .filter(msg => !msg.contractAddress.isZero())
167
+ .map(msg =>
168
+ computeL2ToL1MessageHash({
169
+ l2Sender: msg.contractAddress,
170
+ l1Recipient: msg.message.recipient,
171
+ content: msg.message.content,
172
+ rollupVersion: globalVariables.version,
173
+ chainId: globalVariables.chainId,
174
+ }),
175
+ ),
163
176
  publicDataWrites,
164
177
  privateLogs,
165
178
  avmPublicInputs.accumulatedData.publicLogs.filter(l => !l.isEmpty()),
@@ -171,7 +184,7 @@ export async function makeProcessedTxFromTxWithPublicCalls(
171
184
  data: tx.data,
172
185
  clientIvcProof: tx.clientIvcProof,
173
186
  avmProvingRequest,
174
- constants,
187
+ globalVariables,
175
188
  txEffect,
176
189
  gasUsed,
177
190
  revertCode,
@@ -1,3 +1,4 @@
1
+ import type { ViemHeader } from '@aztec/ethereum';
1
2
  import { sha256ToField } from '@aztec/foundation/crypto';
2
3
  import { EthAddress } from '@aztec/foundation/eth-address';
3
4
  import { Fr } from '@aztec/foundation/fields';
@@ -84,7 +85,7 @@ export class ProposedBlockHeader {
84
85
  }
85
86
 
86
87
  toBuffer() {
87
- // Note: The order here must match the order in the HeaderLib solidity library.
88
+ // Note: The order here must match the order in the ProposedHeaderLib solidity library.
88
89
  return serializeToBuffer([
89
90
  this.lastArchiveRoot,
90
91
  this.contentCommitment,
@@ -140,6 +141,35 @@ export class ProposedBlockHeader {
140
141
  return ProposedBlockHeader.fromBuffer(hexToBuffer(str));
141
142
  }
142
143
 
144
+ static fromViem(header: ViemHeader) {
145
+ return new ProposedBlockHeader(
146
+ Fr.fromString(header.lastArchiveRoot),
147
+ ContentCommitment.fromViem(header.contentCommitment),
148
+ new Fr(header.slotNumber),
149
+ header.timestamp,
150
+ new EthAddress(hexToBuffer(header.coinbase)),
151
+ new AztecAddress(hexToBuffer(header.feeRecipient)),
152
+ new GasFees(header.gasFees.feePerDaGas, header.gasFees.feePerL2Gas),
153
+ new Fr(header.totalManaUsed),
154
+ );
155
+ }
156
+
157
+ toViem(): ViemHeader {
158
+ return {
159
+ lastArchiveRoot: this.lastArchiveRoot.toString(),
160
+ contentCommitment: this.contentCommitment.toViem(),
161
+ slotNumber: this.slotNumber.toBigInt(),
162
+ timestamp: this.timestamp,
163
+ coinbase: this.coinbase.toString(),
164
+ feeRecipient: `0x${this.feeRecipient.toBuffer().toString('hex').padStart(64, '0')}`,
165
+ gasFees: {
166
+ feePerDaGas: this.gasFees.feePerDaGas,
167
+ feePerL2Gas: this.gasFees.feePerL2Gas,
168
+ },
169
+ totalManaUsed: this.totalManaUsed.toBigInt(),
170
+ };
171
+ }
172
+
143
173
  toInspect() {
144
174
  return {
145
175
  lastArchive: this.lastArchiveRoot.toString(),
@@ -5,7 +5,12 @@ import { z } from 'zod';
5
5
 
6
6
  import { PrivateKernelTailCircuitPublicInputs } from '../kernel/private_kernel_tail_circuit_public_inputs.js';
7
7
  import { ClientIvcProof } from '../proofs/client_ivc_proof.js';
8
- import { PrivateExecutionResult, collectSortedContractClassLogs } from './private_execution_result.js';
8
+ import type { OffchainMessage } from './offchain_message.js';
9
+ import {
10
+ PrivateExecutionResult,
11
+ collectOffchainMessages,
12
+ collectSortedContractClassLogs,
13
+ } from './private_execution_result.js';
9
14
  import { type ProvingStats, ProvingTimingsSchema } from './profiling.js';
10
15
  import { Tx } from './tx.js';
11
16
 
@@ -29,6 +34,10 @@ export class TxProvingResult {
29
34
  return tx;
30
35
  }
31
36
 
37
+ getOffchainMessages(): OffchainMessage[] {
38
+ return collectOffchainMessages(this.privateExecutionResult);
39
+ }
40
+
32
41
  static get schema() {
33
42
  return z
34
43
  .object({