@aztec/pxe 0.0.1-commit.3100065 → 0.0.1-commit.330febf

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 (207) hide show
  1. package/dest/bin/check_oracle_version.js +5 -46
  2. package/dest/bin/index.d.ts +2 -2
  3. package/dest/bin/index.d.ts.map +1 -1
  4. package/dest/bin/index.js +1 -1
  5. package/dest/bin/oracle_version_helpers.d.ts +8 -39
  6. package/dest/bin/oracle_version_helpers.d.ts.map +1 -1
  7. package/dest/bin/oracle_version_helpers.js +10 -239
  8. package/dest/block_synchronizer/block_synchronizer.d.ts +3 -5
  9. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  10. package/dest/block_synchronizer/block_synchronizer.js +5 -18
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract/contract_class_service.d.ts +1 -8
  13. package/dest/contract/contract_class_service.d.ts.map +1 -1
  14. package/dest/contract/contract_class_service.js +8 -40
  15. package/dest/contract/helpers.d.ts +1 -1
  16. package/dest/contract/helpers.d.ts.map +1 -1
  17. package/dest/contract/helpers.js +3 -3
  18. package/dest/contract/skip_sync_contracts.d.ts +11 -0
  19. package/dest/contract/skip_sync_contracts.d.ts.map +1 -0
  20. package/dest/contract/skip_sync_contracts.js +18 -0
  21. package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -8
  22. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/contract_function_simulator.js +5 -20
  24. package/dest/contract_function_simulator/index.d.ts +3 -3
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.js +1 -2
  27. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +7 -9
  28. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +3 -44
  30. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +5 -4
  31. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +2 -2
  33. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +4 -3
  34. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/oracle_registry.js +15 -6
  36. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +87 -35
  37. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +297 -287
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +11 -8
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +15 -4
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +168 -53
  45. package/dest/entrypoints/client/bundle/index.d.ts +2 -1
  46. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  47. package/dest/entrypoints/client/bundle/index.js +1 -0
  48. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  49. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  50. package/dest/entrypoints/client/bundle/utils.js +10 -4
  51. package/dest/entrypoints/client/lazy/index.d.ts +2 -1
  52. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  53. package/dest/entrypoints/client/lazy/index.js +1 -0
  54. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  55. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  56. package/dest/entrypoints/client/lazy/utils.js +10 -4
  57. package/dest/entrypoints/client/store.d.ts +14 -0
  58. package/dest/entrypoints/client/store.d.ts.map +1 -0
  59. package/dest/entrypoints/client/store.js +42 -0
  60. package/dest/entrypoints/server/index.d.ts +2 -1
  61. package/dest/entrypoints/server/index.d.ts.map +1 -1
  62. package/dest/entrypoints/server/index.js +1 -0
  63. package/dest/entrypoints/server/store.d.ts +18 -0
  64. package/dest/entrypoints/server/store.d.ts.map +1 -0
  65. package/dest/entrypoints/server/store.js +28 -0
  66. package/dest/entrypoints/server/utils.d.ts +1 -1
  67. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  68. package/dest/entrypoints/server/utils.js +8 -2
  69. package/dest/events/event_service.d.ts +13 -6
  70. package/dest/events/event_service.d.ts.map +1 -1
  71. package/dest/events/event_service.js +13 -13
  72. package/dest/logs/log_service.d.ts +15 -6
  73. package/dest/logs/log_service.d.ts.map +1 -1
  74. package/dest/logs/log_service.js +25 -32
  75. package/dest/messages/tx_resolver_service.d.ts +18 -7
  76. package/dest/messages/tx_resolver_service.d.ts.map +1 -1
  77. package/dest/messages/tx_resolver_service.js +13 -7
  78. package/dest/node/benchmarked_node.d.ts +20 -0
  79. package/dest/node/benchmarked_node.d.ts.map +1 -0
  80. package/dest/node/benchmarked_node.js +94 -0
  81. package/dest/node/caching_aztec_node.d.ts +24 -0
  82. package/dest/node/caching_aztec_node.d.ts.map +1 -0
  83. package/dest/node/caching_aztec_node.js +267 -0
  84. package/dest/notes/note_service.d.ts +13 -7
  85. package/dest/notes/note_service.d.ts.map +1 -1
  86. package/dest/notes/note_service.js +10 -10
  87. package/dest/oracle_version.d.ts +2 -2
  88. package/dest/oracle_version.js +5 -5
  89. package/dest/private_kernel/batch_planner.d.ts +1 -1
  90. package/dest/private_kernel/batch_planner.d.ts.map +1 -1
  91. package/dest/private_kernel/batch_planner.js +1 -1
  92. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  93. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  94. package/dest/private_kernel/private_kernel_execution_prover.js +45 -5
  95. package/dest/pxe.d.ts +1 -1
  96. package/dest/pxe.d.ts.map +1 -1
  97. package/dest/pxe.js +39 -19
  98. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  99. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  100. package/dest/storage/contract_store/contract_store.js +2 -2
  101. package/dest/storage/fact_store/fact_store.d.ts +1 -1
  102. package/dest/storage/fact_store/fact_store.js +1 -1
  103. package/dest/storage/fact_store/index.d.ts +2 -2
  104. package/dest/storage/fact_store/index.d.ts.map +1 -1
  105. package/dest/storage/fact_store/index.js +1 -1
  106. package/dest/storage/fact_store/origin_state.d.ts +4 -2
  107. package/dest/storage/fact_store/origin_state.d.ts.map +1 -1
  108. package/dest/storage/fact_store/origin_state.js +8 -1
  109. package/dest/storage/store_identity.d.ts +35 -0
  110. package/dest/storage/store_identity.d.ts.map +1 -0
  111. package/dest/storage/store_identity.js +44 -0
  112. package/dest/storage/tagging_store/sender_tagging_store.d.ts +41 -10
  113. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  114. package/dest/storage/tagging_store/sender_tagging_store.js +81 -29
  115. package/dest/tagging/constants.d.ts +10 -1
  116. package/dest/tagging/constants.d.ts.map +1 -1
  117. package/dest/tagging/constants.js +19 -0
  118. package/dest/tagging/get_all_logs_by_tags.d.ts +29 -8
  119. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  120. package/dest/tagging/get_all_logs_by_tags.js +29 -10
  121. package/dest/tagging/index.d.ts +3 -3
  122. package/dest/tagging/index.d.ts.map +1 -1
  123. package/dest/tagging/index.js +2 -2
  124. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +10 -5
  125. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -1
  126. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +69 -38
  127. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +6 -3
  128. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  129. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +23 -38
  130. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
  131. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
  132. package/dest/tagging/sender_sync/utils/classify_pending_txs.js +61 -0
  133. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +15 -5
  134. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  135. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -35
  136. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
  137. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
  138. package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +41 -0
  139. package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
  140. package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
  141. package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
  142. package/dest/tagging/testing/tag_query_test_utils.d.ts +6 -0
  143. package/dest/tagging/testing/tag_query_test_utils.d.ts.map +1 -0
  144. package/dest/tagging/testing/tag_query_test_utils.js +10 -0
  145. package/package.json +17 -17
  146. package/src/bin/check_oracle_version.ts +5 -56
  147. package/src/bin/index.ts +1 -5
  148. package/src/bin/oracle_version_helpers.ts +11 -292
  149. package/src/block_synchronizer/block_synchronizer.ts +6 -23
  150. package/src/config/package_info.ts +1 -1
  151. package/src/contract/contract_class_service.ts +8 -46
  152. package/src/contract/helpers.ts +3 -3
  153. package/src/contract/skip_sync_contracts.ts +23 -0
  154. package/src/contract_function_simulator/contract_function_simulator.ts +5 -20
  155. package/src/contract_function_simulator/index.ts +23 -3
  156. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +11 -45
  157. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +4 -3
  158. package/src/contract_function_simulator/oracle/oracle_registry.ts +12 -8
  159. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +301 -198
  160. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +19 -9
  161. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +184 -56
  162. package/src/entrypoints/client/bundle/index.ts +1 -0
  163. package/src/entrypoints/client/bundle/utils.ts +15 -3
  164. package/src/entrypoints/client/lazy/index.ts +1 -0
  165. package/src/entrypoints/client/lazy/utils.ts +15 -3
  166. package/src/entrypoints/client/store.ts +54 -0
  167. package/src/entrypoints/server/index.ts +1 -0
  168. package/src/entrypoints/server/store.ts +47 -0
  169. package/src/entrypoints/server/utils.ts +21 -7
  170. package/src/events/event_service.ts +24 -14
  171. package/src/logs/log_service.ts +41 -39
  172. package/src/messages/tx_resolver_service.ts +26 -15
  173. package/src/node/benchmarked_node.ts +140 -0
  174. package/src/node/caching_aztec_node.ts +406 -0
  175. package/src/notes/note_service.ts +20 -14
  176. package/src/oracle_version.ts +5 -5
  177. package/src/private_kernel/batch_planner.ts +0 -1
  178. package/src/private_kernel/private_kernel_execution_prover.ts +90 -4
  179. package/src/pxe.ts +40 -21
  180. package/src/storage/contract_store/contract_store.ts +2 -1
  181. package/src/storage/fact_store/fact_store.ts +1 -1
  182. package/src/storage/fact_store/index.ts +1 -0
  183. package/src/storage/fact_store/origin_state.ts +10 -1
  184. package/src/storage/store_identity.ts +72 -0
  185. package/src/storage/tagging_store/sender_tagging_store.ts +113 -41
  186. package/src/tagging/constants.ts +22 -0
  187. package/src/tagging/get_all_logs_by_tags.ts +47 -11
  188. package/src/tagging/index.ts +7 -2
  189. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +116 -62
  190. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +27 -57
  191. package/src/tagging/sender_sync/utils/classify_pending_txs.ts +91 -0
  192. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +46 -40
  193. package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +64 -0
  194. package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
  195. package/src/tagging/testing/tag_query_test_utils.ts +11 -0
  196. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +0 -39
  197. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +0 -1
  198. package/dest/contract_function_simulator/aztec_node_read_cache.js +0 -60
  199. package/dest/contract_function_simulator/benchmarked_node.d.ts +0 -9
  200. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +0 -1
  201. package/dest/contract_function_simulator/benchmarked_node.js +0 -77
  202. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +0 -17
  203. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +0 -1
  204. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +0 -60
  205. package/src/contract_function_simulator/aztec_node_read_cache.ts +0 -89
  206. package/src/contract_function_simulator/benchmarked_node.ts +0 -103
  207. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +0 -66
@@ -4,12 +4,12 @@ import { padArrayEnd } from '@aztec/foundation/collection';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
6
6
  import { FieldReader } from '@aztec/foundation/serialize';
7
- import { fromUintArray } from '@aztec/simulator/client';
8
7
  import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
9
8
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
10
9
  import { BlockHash } from '@aztec/stdlib/block';
11
10
  import { Tag, appTaggingSecretKindFromDeliveryMode } from '@aztec/stdlib/logs';
12
11
  import { TxHash } from '@aztec/stdlib/tx';
12
+ import { originBlockStateFromNumber } from '../../storage/fact_store/index.js';
13
13
  import { BoundedVec } from '../noir-structs/bounded_vec.js';
14
14
  import { EphemeralArray } from '../noir-structs/ephemeral_array.js';
15
15
  import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
@@ -28,7 +28,25 @@ import { packAsHintedNote } from './note_packing_utils.js';
28
28
  });
29
29
  }
30
30
  // ─── Scalar Type Mappings ────────────────────────────────────────────────────
31
- export const FIELD = {
31
+ /**
32
+ * A leaf mapping whose {@link TypeMapping.label} is just its bare {@link TypeMapping.kind}. Its wire shape is arbitrary
33
+ * (several fields, or a variable-width run); a single-field scalar uses the shorter {@link SCALAR} instead.
34
+ */ export function LEAF(mapping) {
35
+ return {
36
+ ...mapping,
37
+ label: mapping.kind
38
+ };
39
+ }
40
+ /** A {@link LEAF} occupying a single `'scalar'` wire slot, so callers omit the shape. */ export function SCALAR(mapping) {
41
+ return LEAF({
42
+ ...mapping,
43
+ shape: [
44
+ 'scalar'
45
+ ]
46
+ });
47
+ }
48
+ export const FIELD = SCALAR({
49
+ kind: 'field',
32
50
  serialization: {
33
51
  fn: (v)=>[
34
52
  v
@@ -36,12 +54,10 @@ export const FIELD = {
36
54
  },
37
55
  deserialization: {
38
56
  fn: ([reader])=>reader.readField()
39
- },
40
- shape: [
41
- 'scalar'
42
- ]
43
- };
44
- export const BOOL = {
57
+ }
58
+ });
59
+ export const BOOL = SCALAR({
60
+ kind: 'bool',
45
61
  serialization: {
46
62
  fn: (v)=>[
47
63
  new Fr(v ? 1n : 0n)
@@ -49,70 +65,43 @@ export const BOOL = {
49
65
  },
50
66
  deserialization: {
51
67
  fn: ([reader])=>!reader.readField().isZero()
52
- },
53
- shape: [
54
- 'scalar'
55
- ]
56
- };
57
- export const U32 = {
58
- serialization: {
59
- fn: (v)=>[
60
- new Fr(v)
61
- ]
62
- },
63
- deserialization: {
64
- fn: ([reader])=>{
65
- const value = reader.readField().toBigInt();
66
- if (value > 0xffffffffn) {
67
- throw new Error(`U32 overflow: value ${value} exceeds u32 max (${0xffffffffn})`);
68
- }
69
- return Number(value);
70
- }
71
- },
72
- shape: [
73
- 'scalar'
74
- ]
75
- };
76
- export const BLOCK_NUMBER = {
68
+ }
69
+ });
70
+ export const U32 = SCALAR({
71
+ kind: 'u32',
77
72
  serialization: {
78
73
  fn: (v)=>[
79
74
  new Fr(v)
80
75
  ]
81
76
  },
82
77
  deserialization: {
83
- fn: ([reader])=>BlockNumber(reader.readField().toNumber())
84
- },
85
- shape: [
86
- 'scalar'
87
- ]
88
- };
89
- /** A u8 byte: serializes to a single Fr; deserializes from a single Fr to a number in [0, 255]. */ export const BYTE = {
78
+ fn: ([reader])=>Number(uintFromField(reader.readField(), 32))
79
+ }
80
+ });
81
+ export const BLOCK_NUMBER = ALIAS(U32, {
82
+ wrap: (v)=>BlockNumber(v),
83
+ unwrap: (v)=>v
84
+ });
85
+ export const U8 = SCALAR({
86
+ kind: 'u8',
90
87
  serialization: {
91
88
  fn: (byte)=>[
92
89
  new Fr(byte)
93
90
  ]
94
91
  },
95
92
  deserialization: {
96
- fn: ([reader])=>{
97
- const value = reader.readField().toBigInt();
98
- if (value > 0xffn) {
99
- throw new Error(`BYTE overflow: value ${value} exceeds u8 max (255)`);
100
- }
101
- return Number(value);
102
- }
103
- },
104
- shape: [
105
- 'scalar'
106
- ]
107
- };
93
+ fn: ([reader])=>Number(uintFromField(reader.readField(), 8))
94
+ }
95
+ });
108
96
  // Noir passes `MessageDelivery` onchain variants here.
109
- export const DELIVERY_MODE = {
97
+ export const DELIVERY_MODE = SCALAR({
98
+ kind: 'onchain-delivery-mode',
110
99
  deserialization: {
111
- fn: (readers)=>appTaggingSecretKindFromDeliveryMode(BYTE.deserialization.fn(readers))
112
- },
113
- shape: BYTE.shape
114
- };
115
- export const RESOLVED_TAGGING_STRATEGY = {
100
+ fn: (readers)=>appTaggingSecretKindFromDeliveryMode(U8.deserialization.fn(readers))
101
+ }
102
+ });
103
+ export const RESOLVED_TAGGING_STRATEGY = LEAF({
104
+ kind: 'resolved-tagging-strategy',
116
105
  serialization: {
117
106
  fn: (resolved)=>resolvedTaggingStrategyToFields(resolved)
118
107
  },
@@ -123,21 +112,39 @@ export const RESOLVED_TAGGING_STRATEGY = {
123
112
  'scalar',
124
113
  'scalar'
125
114
  ]
126
- };
127
- export const BIGINT = {
115
+ });
116
+ export const BIGINT = ALIAS(FIELD, {
117
+ wrap: (f)=>f.toBigInt(),
118
+ unwrap: (v)=>new Fr(v)
119
+ });
120
+ export const U64 = SCALAR({
121
+ kind: 'u64',
128
122
  serialization: {
129
123
  fn: (v)=>[
130
124
  new Fr(v)
131
125
  ]
132
126
  },
133
127
  deserialization: {
134
- fn: ([reader])=>reader.readField().toBigInt()
128
+ fn: ([reader])=>uintFromField(reader.readField(), 64)
129
+ }
130
+ });
131
+ export const U128 = SCALAR({
132
+ kind: 'u128',
133
+ serialization: {
134
+ fn: (v)=>[
135
+ new Fr(v)
136
+ ]
135
137
  },
136
- shape: [
137
- 'scalar'
138
- ]
139
- };
140
- /** Reads every field in the slot as a UTF-8 character code. */ export const STR = {
138
+ deserialization: {
139
+ fn: ([reader])=>uintFromField(reader.readField(), 128)
140
+ }
141
+ });
142
+ export const LEAF_INDEX = ALIAS(FIELD, {
143
+ wrap: (f)=>f.toNumber(),
144
+ unwrap: (v)=>new Fr(v)
145
+ });
146
+ /** Reads every field in the slot as a UTF-8 character code. */ export const STR = LEAF({
147
+ kind: 'str',
141
148
  serialization: {
142
149
  fn: (str)=>[
143
150
  Array.from(Buffer.from(str, 'utf-8')).map((b)=>new Fr(b))
@@ -155,8 +162,9 @@ export const BIGINT = {
155
162
  shape: [
156
163
  'variable'
157
164
  ]
158
- };
159
- export const AZTEC_ADDRESS = {
165
+ });
166
+ export const AZTEC_ADDRESS = SCALAR({
167
+ kind: 'aztec-address',
160
168
  serialization: {
161
169
  fn: (v)=>[
162
170
  v.toField()
@@ -164,25 +172,14 @@ export const AZTEC_ADDRESS = {
164
172
  },
165
173
  deserialization: {
166
174
  fn: ([reader])=>AztecAddress.fromFieldUnsafe(reader.readField())
167
- },
168
- shape: [
169
- 'scalar'
170
- ]
171
- };
172
- export const BLOCK_HASH = {
173
- serialization: {
174
- fn: (v)=>[
175
- new Fr(v.toBuffer())
176
- ]
177
- },
178
- deserialization: {
179
- fn: ([reader])=>new BlockHash(reader.readField())
180
- },
181
- shape: [
182
- 'scalar'
183
- ]
184
- };
185
- export const FUNCTION_SELECTOR = {
175
+ }
176
+ });
177
+ export const BLOCK_HASH = ALIAS(FIELD, {
178
+ wrap: (f)=>new BlockHash(f),
179
+ unwrap: (v)=>new Fr(v.toBuffer())
180
+ });
181
+ export const FUNCTION_SELECTOR = SCALAR({
182
+ kind: 'function-selector',
186
183
  serialization: {
187
184
  fn: (v)=>[
188
185
  v.toField()
@@ -190,50 +187,20 @@ export const FUNCTION_SELECTOR = {
190
187
  },
191
188
  deserialization: {
192
189
  fn: ([reader])=>FunctionSelector.fromField(reader.readField())
193
- },
194
- shape: [
195
- 'scalar'
196
- ]
197
- };
198
- export const NOTE_SELECTOR = {
199
- serialization: {
200
- fn: (v)=>[
201
- v.toField()
202
- ]
203
- },
204
- deserialization: {
205
- fn: ([reader])=>NoteSelector.fromField(reader.readField())
206
- },
207
- shape: [
208
- 'scalar'
209
- ]
210
- };
211
- export const TX_HASH = {
212
- serialization: {
213
- fn: (v)=>[
214
- v.hash
215
- ]
216
- },
217
- deserialization: {
218
- fn: ([reader])=>TxHash.fromField(reader.readField())
219
- },
220
- shape: [
221
- 'scalar'
222
- ]
223
- };
224
- const TAG = {
225
- serialization: {
226
- fn: (v)=>[
227
- v.value
228
- ]
229
- },
230
- deserialization: {
231
- fn: ([reader])=>new Tag(reader.readField())
232
- },
233
- shape: [
234
- 'scalar'
235
- ]
236
- };
190
+ }
191
+ });
192
+ export const NOTE_SELECTOR = ALIAS(FIELD, {
193
+ wrap: (f)=>NoteSelector.fromField(f),
194
+ unwrap: (v)=>v.toField()
195
+ });
196
+ export const TX_HASH = ALIAS(FIELD, {
197
+ wrap: (f)=>TxHash.fromField(f),
198
+ unwrap: (v)=>v.hash
199
+ });
200
+ const TAG = ALIAS(FIELD, {
201
+ wrap: (f)=>new Tag(f),
202
+ unwrap: (v)=>v.value
203
+ });
237
204
  export const POINT = STRUCT([
238
205
  {
239
206
  name: 'x',
@@ -244,7 +211,8 @@ export const POINT = STRUCT([
244
211
  type: FIELD
245
212
  }
246
213
  ]);
247
- const LOG_SOURCE = {
214
+ const LOG_SOURCE = SCALAR({
215
+ kind: 'log-source',
248
216
  serialization: {
249
217
  fn: (v)=>[
250
218
  new Fr(v)
@@ -252,12 +220,10 @@ const LOG_SOURCE = {
252
220
  },
253
221
  deserialization: {
254
222
  fn: ([reader])=>logSourceFromField(reader.readField())
255
- },
256
- shape: [
257
- 'scalar'
258
- ]
259
- };
260
- export const ETH_ADDRESS = {
223
+ }
224
+ });
225
+ export const ETH_ADDRESS = SCALAR({
226
+ kind: 'eth-address',
261
227
  serialization: {
262
228
  fn: (v)=>[
263
229
  v.toField()
@@ -265,21 +231,11 @@ export const ETH_ADDRESS = {
265
231
  },
266
232
  deserialization: {
267
233
  fn: ([reader])=>EthAddress.fromField(reader.readField())
268
- },
269
- shape: [
270
- 'scalar'
271
- ]
272
- };
273
- export const SLOT_NUMBER = {
274
- serialization: {
275
- fn: (v)=>[
276
- new Fr(v)
277
- ]
278
- },
279
- shape: [
280
- 'scalar'
281
- ]
282
- };
234
+ }
235
+ });
236
+ export const SLOT_NUMBER = ALIAS(FIELD, {
237
+ unwrap: (v)=>new Fr(v)
238
+ });
283
239
  const APPEND_ONLY_TREE_SNAPSHOT = STRUCT([
284
240
  {
285
241
  name: 'root',
@@ -287,7 +243,7 @@ const APPEND_ONLY_TREE_SNAPSHOT = STRUCT([
287
243
  },
288
244
  {
289
245
  name: 'nextAvailableLeafIndex',
290
- type: U32
246
+ type: LEAF_INDEX
291
247
  }
292
248
  ]);
293
249
  const PARTIAL_STATE_REFERENCE = STRUCT([
@@ -317,11 +273,11 @@ const STATE_REFERENCE = STRUCT([
317
273
  const GAS_FEES = STRUCT([
318
274
  {
319
275
  name: 'feePerDaGas',
320
- type: BIGINT
276
+ type: U128
321
277
  },
322
278
  {
323
279
  name: 'feePerL2Gas',
324
- type: BIGINT
280
+ type: U128
325
281
  }
326
282
  ]);
327
283
  const GLOBAL_VARIABLES = STRUCT([
@@ -343,7 +299,7 @@ const GLOBAL_VARIABLES = STRUCT([
343
299
  },
344
300
  {
345
301
  name: 'timestamp',
346
- type: BIGINT
302
+ type: U64
347
303
  },
348
304
  {
349
305
  name: 'coinbase',
@@ -577,16 +533,6 @@ export const CONTRACT_CLASS_LOG = STRUCT([
577
533
  type: U32
578
534
  }
579
535
  ]);
580
- const REVERT_CODE = {
581
- serialization: {
582
- fn: (rc)=>[
583
- rc.toField()
584
- ]
585
- },
586
- shape: [
587
- 'scalar'
588
- ]
589
- };
590
536
  const PUBLIC_DATA_WRITE = STRUCT([
591
537
  {
592
538
  name: 'leafSlot',
@@ -635,7 +581,7 @@ const CONTRACT_CLASS_LOGS = FIXED_ARRAY(CONTRACT_CLASS_LOG_ENTRY, MAX_CONTRACT_C
635
581
  export const TX_EFFECT = STRUCT([
636
582
  {
637
583
  name: 'revertCode',
638
- type: REVERT_CODE
584
+ type: U8
639
585
  },
640
586
  {
641
587
  name: 'txHash',
@@ -674,7 +620,8 @@ export const TX_EFFECT = STRUCT([
674
620
  type: CONTRACT_CLASS_LOGS
675
621
  }
676
622
  ]);
677
- export const NOTE = {
623
+ export const NOTE = LEAF({
624
+ kind: 'note',
678
625
  serialization: {
679
626
  fn: (noteData)=>packAsHintedNote({
680
627
  contractAddress: noteData.contractAddress,
@@ -691,23 +638,25 @@ export const NOTE = {
691
638
  shape: [
692
639
  'variable'
693
640
  ]
694
- };
695
- export const NOTE_VALIDATION_REQUEST = {
641
+ });
642
+ export const NOTE_VALIDATION_REQUEST = LEAF({
643
+ kind: 'note-validation-request',
696
644
  deserialization: {
697
645
  fn: ([reader])=>NoteValidationRequest.fromFields(reader)
698
646
  },
699
647
  shape: [
700
648
  'variable'
701
649
  ]
702
- };
703
- export const EVENT_VALIDATION_REQUEST = {
650
+ });
651
+ export const EVENT_VALIDATION_REQUEST = LEAF({
652
+ kind: 'event-validation-request',
704
653
  deserialization: {
705
654
  fn: ([reader])=>EventValidationRequest.fromFields(reader)
706
655
  },
707
656
  shape: [
708
657
  'variable'
709
658
  ]
710
- };
659
+ });
711
660
  export const LOG_RETRIEVAL_REQUEST = STRUCT([
712
661
  {
713
662
  name: 'contractAddress',
@@ -753,27 +702,35 @@ export const LOG_RETRIEVAL_RESPONSE = STRUCT([
753
702
  },
754
703
  {
755
704
  name: 'blockTimestamp',
756
- type: BIGINT
705
+ type: U64
757
706
  },
758
707
  {
759
708
  name: 'blockHash',
760
709
  type: BLOCK_HASH
761
710
  }
762
711
  ]);
763
- // `ResolvedTx.toFields()` packs the whole struct into a single slot: txHash, the uniqueNoteHashesInTx BoundedVec
764
- // (MAX_NOTE_HASHES_PER_TX storage fields + length), firstNullifierInTx, blockNumber and blockHash.
765
- export const RESOLVED_TX = {
766
- serialization: {
767
- fn: (resolved)=>[
768
- resolved.toFields()
769
- ]
712
+ export const RESOLVED_TX = STRUCT([
713
+ {
714
+ name: 'txHash',
715
+ type: TX_HASH
770
716
  },
771
- shape: [
772
- {
773
- len: MAX_NOTE_HASHES_PER_TX + 5
774
- }
775
- ]
776
- };
717
+ {
718
+ name: 'uniqueNoteHashesInTx',
719
+ type: FIXED_BOUNDED_VEC(FIELD, MAX_NOTE_HASHES_PER_TX)
720
+ },
721
+ {
722
+ name: 'firstNullifierInTx',
723
+ type: FIELD
724
+ },
725
+ {
726
+ name: 'blockNumber',
727
+ type: U32
728
+ },
729
+ {
730
+ name: 'blockHash',
731
+ type: FIELD
732
+ }
733
+ ]);
777
734
  export const PENDING_TAGGED_LOG = STRUCT([
778
735
  {
779
736
  name: 'log',
@@ -784,93 +741,109 @@ export const PENDING_TAGGED_LOG = STRUCT([
784
741
  type: RESOLVED_TX
785
742
  }
786
743
  ]);
787
- export const ORIGIN_BLOCK = {
744
+ export const ORIGIN_BLOCK = STRUCT([
745
+ {
746
+ name: 'blockNumber',
747
+ type: U32
748
+ },
749
+ {
750
+ name: 'blockHash',
751
+ type: FIELD
752
+ }
753
+ ]);
754
+ const ORIGIN_BLOCK_STATE = SCALAR({
755
+ kind: 'origin-block-state',
788
756
  serialization: {
789
- fn: (ob)=>[
790
- new Fr(ob.blockNumber),
791
- ob.blockHash
757
+ fn: (v)=>[
758
+ new Fr(v)
792
759
  ]
793
760
  },
794
761
  deserialization: {
795
- fn: ([blockNumberReader, blockHashReader])=>({
796
- blockNumber: blockNumberReader.readField().toNumber(),
797
- blockHash: blockHashReader.readField()
798
- })
762
+ fn: ([reader])=>originBlockStateFromNumber(reader.readField().toNumber())
763
+ }
764
+ });
765
+ /** Read-side origin of a retractable fact, carrying the chain state of its origin block. */ export const RETRACTABLE_FACT_ORIGIN = STRUCT([
766
+ {
767
+ name: 'blockNumber',
768
+ type: U32
799
769
  },
800
- shape: [
801
- 'scalar',
802
- 'scalar'
803
- ]
804
- };
805
- /** Read-side origin of a retractable fact, carrying the chain state of its origin block. */ export const RETRACTABLE_FACT_ORIGIN = {
806
- serialization: {
807
- fn: (o)=>[
808
- new Fr(o.blockNumber),
809
- o.blockHash,
810
- new Fr(o.blockState)
811
- ]
770
+ {
771
+ name: 'blockHash',
772
+ type: FIELD
812
773
  },
813
- shape: [
814
- 'scalar',
815
- 'scalar',
816
- 'scalar'
817
- ]
818
- };
819
- // `facts` and `payload` each materialize to a single service-slot id, so a Fact occupies: factTypeId, the payload
820
- // array slot, and `OPTION(RETRACTABLE_FACT_ORIGIN)` (its discriminant plus RETRACTABLE_FACT_ORIGIN's three slots).
821
- export const FACT = {
822
- serialization: {
823
- fn: (f)=>[
824
- f.factTypeId,
825
- f.payload.materializeSlot((v)=>FIELD.serialization.fn(v).flat()),
826
- ...OPTION(RETRACTABLE_FACT_ORIGIN).serialization.fn(f.originBlock)
827
- ]
774
+ {
775
+ name: 'blockState',
776
+ type: ORIGIN_BLOCK_STATE
777
+ }
778
+ ]);
779
+ export const FACT = STRUCT([
780
+ {
781
+ name: 'factTypeId',
782
+ type: FIELD
828
783
  },
829
- shape: [
830
- 'scalar',
831
- 'scalar',
832
- 'scalar',
833
- 'scalar',
834
- 'scalar',
835
- 'scalar'
836
- ]
837
- };
838
- export const FACT_COLLECTION = {
839
- serialization: {
840
- fn: (c)=>[
841
- c.contractAddress.toField(),
842
- c.scope.toField(),
843
- c.factCollectionTypeId,
844
- c.factCollectionId,
845
- c.facts.materializeSlot((v)=>FACT.serialization.fn(v).flat())
846
- ]
784
+ {
785
+ name: 'payload',
786
+ type: EPHEMERAL_ARRAY(FIELD)
847
787
  },
848
- shape: [
849
- 'scalar',
850
- 'scalar',
851
- 'scalar',
852
- 'scalar',
853
- 'scalar'
854
- ]
855
- };
856
- export const PROVIDED_SECRET = {
857
- deserialization: {
858
- fn: ([reader])=>({
859
- secret: reader.readField(),
860
- mode: appTaggingSecretKindFromDeliveryMode(BYTE.deserialization.fn([
861
- reader
862
- ]))
863
- })
788
+ {
789
+ name: 'originBlock',
790
+ type: OPTION(RETRACTABLE_FACT_ORIGIN)
791
+ }
792
+ ]);
793
+ export const FACT_COLLECTION = STRUCT([
794
+ {
795
+ name: 'contractAddress',
796
+ type: AZTEC_ADDRESS
864
797
  },
865
- shape: [
866
- {
867
- len: 2
868
- }
869
- ]
870
- };
798
+ {
799
+ name: 'scope',
800
+ type: AZTEC_ADDRESS
801
+ },
802
+ {
803
+ name: 'factCollectionTypeId',
804
+ type: FIELD
805
+ },
806
+ {
807
+ name: 'factCollectionId',
808
+ type: FIELD
809
+ },
810
+ {
811
+ name: 'facts',
812
+ type: EPHEMERAL_ARRAY(FACT)
813
+ }
814
+ ]);
815
+ export const PROVIDED_SECRET = STRUCT([
816
+ {
817
+ name: 'secret',
818
+ type: FIELD
819
+ },
820
+ {
821
+ name: 'mode',
822
+ type: DELIVERY_MODE
823
+ }
824
+ ]);
871
825
  // ─── Combinator Type Mappings ────────────────────────────────────────────────
872
- function SIBLING_PATH(height) {
826
+ /**
827
+ * A TS-side alias of `base`: the same Noir type on the wire (it inherits `base`'s `kind`, `label`, and `shape`) but a
828
+ * richer TS value. `wrap` maps a base value to the alias, `unwrap` back; a serialize-only alias passes only `unwrap`.
829
+ */ export function ALIAS(base, conversions) {
830
+ const { wrap, unwrap } = conversions;
873
831
  return {
832
+ kind: base.kind,
833
+ label: base.label,
834
+ serialization: base.serialization && unwrap ? {
835
+ fn: (value)=>base.serialization.fn(unwrap(value))
836
+ } : undefined,
837
+ deserialization: base.deserialization && wrap ? {
838
+ fn: (readers)=>wrap(base.deserialization.fn(readers))
839
+ } : undefined,
840
+ shape: base.shape
841
+ };
842
+ }
843
+ function SIBLING_PATH(height) {
844
+ return LEAF({
845
+ // On the wire (and in Noir) a sibling path is a plain `[Field; height]`, so it shares the fixed-array kind.
846
+ kind: `array(field,${height})`,
874
847
  serialization: {
875
848
  fn: (sp)=>[
876
849
  sp.toFields()
@@ -881,7 +854,7 @@ function SIBLING_PATH(height) {
881
854
  len: height
882
855
  }
883
856
  ]
884
- };
857
+ });
885
858
  }
886
859
  export function MEMBERSHIP_WITNESS(height) {
887
860
  return STRUCT([
@@ -898,6 +871,7 @@ export function MEMBERSHIP_WITNESS(height) {
898
871
  export function ARRAY(inner) {
899
872
  return {
900
873
  kind: 'array',
874
+ label: `array(${inner.label})`,
901
875
  inner,
902
876
  serialization: inner.serialization ? {
903
877
  fn: (values)=>[
@@ -924,6 +898,7 @@ export function ARRAY(inner) {
924
898
  const elementWidth = fieldWidth(element.shape);
925
899
  return {
926
900
  kind: 'fixed-array',
901
+ label: `array(${element.label},${length})`,
927
902
  inner: element,
928
903
  length,
929
904
  serialization: element.serialization ? {
@@ -948,7 +923,7 @@ export function ARRAY(inner) {
948
923
  *
949
924
  * Both directions are derived from `element`: bidirectional iff `element` has both serialization and deserialization.
950
925
  *
951
- * @example Serializing `BoundedVec.from({ data: [0x41, 0x42], maxLength: 4 })` with `BOUNDED_VEC(BYTE)`:
926
+ * @example Serializing `BoundedVec.from({ data: [0x41, 0x42], maxLength: 4 })` with `BOUNDED_VEC(U8)`:
952
927
  * ```
953
928
  * slot 0: [Fr(0x41), Fr(0x42), Fr(0), Fr(0)] // data padded to maxLength
954
929
  * slot 1: Fr(2) // actual length
@@ -956,6 +931,7 @@ export function ARRAY(inner) {
956
931
  */ export function BOUNDED_VEC(inner) {
957
932
  return {
958
933
  kind: 'bounded-vec',
934
+ label: `bounded-vec(${inner.label})`,
959
935
  inner,
960
936
  serialization: inner.serialization ? {
961
937
  fn: (bv)=>{
@@ -976,8 +952,18 @@ export function ARRAY(inner) {
976
952
  fn: ([storageReader, lengthReader])=>{
977
953
  // slot 0 is the padded storage, slot 1 the actual length. Parse only the first `length` elements out of
978
954
  // storage, then drain the trailing zero-padding so the storage reader is fully consumed.
979
- const maxLength = storageReader.remainingFields() / fieldWidth(inner.shape);
955
+ const elementWidth = fieldWidth(inner.shape);
956
+ const storageFields = storageReader.remainingFields();
957
+ if (storageFields % elementWidth !== 0) {
958
+ throw new Error(`Malformed BoundedVec: storage array holds ${storageFields} field(s), which is not a whole number of ` + `${elementWidth}-field elements`);
959
+ }
960
+ // The BoundedVec's maximum length is determined by the size of the storage array, so its length is bounded
961
+ // by it.
962
+ const maxLength = storageFields / elementWidth;
980
963
  const length = lengthReader.readField().toNumber();
964
+ if (length > maxLength) {
965
+ throw new Error(`Malformed BoundedVec: length ${length} exceeds the ${maxLength} element(s) its storage array holds`);
966
+ }
981
967
  const elements = unpackElements(inner, storageReader, length);
982
968
  storageReader.skip(storageReader.remainingFields());
983
969
  return BoundedVec.from({
@@ -1003,6 +989,7 @@ export function ARRAY(inner) {
1003
989
  const width = fieldWidth(element.shape);
1004
990
  return {
1005
991
  kind: 'fixed-bounded-vec',
992
+ label: `bounded-vec(${element.label},${maxLength})`,
1006
993
  inner: element,
1007
994
  maxLength,
1008
995
  serialization: element.serialization ? {
@@ -1046,6 +1033,7 @@ export function ARRAY(inner) {
1046
1033
  */ export function OPTION(inner) {
1047
1034
  return {
1048
1035
  kind: 'option',
1036
+ label: `option(${inner.label})`,
1049
1037
  inner,
1050
1038
  serialization: inner.serialization ? {
1051
1039
  fn: (opt)=>opt.isSome() ? [
@@ -1074,31 +1062,13 @@ export function ARRAY(inner) {
1074
1062
  ]
1075
1063
  };
1076
1064
  }
1077
- /**
1078
- * A fixed packed uint buffer (Noir `[u8; length]` at `bitSize` 8): one slot of `length` packed uint values ↔ `Buffer`.
1079
- * `length` is the field count, which equals the byte count at `bitSize` 8.
1080
- */ export function BUFFER(bitSize, length) {
1081
- return {
1082
- serialization: {
1083
- fn: (buf)=>[
1084
- Array.from(buf).map((b)=>new Fr(b))
1085
- ]
1086
- },
1087
- deserialization: {
1088
- fn: ([reader])=>fromUintArray(reader.readFieldArray(length).map((f)=>f.toString()), bitSize)
1089
- },
1090
- shape: [
1091
- {
1092
- len: length
1093
- }
1094
- ]
1095
- };
1096
- }
1097
1065
  export function EPHEMERAL_ARRAY(element) {
1098
1066
  // EphemeralArray.readAll hands each row's flat fields in as a single reader; reconstruct the element's per-slot
1099
1067
  // readers from its shape, deserialize, and assert the row was fully consumed so a row with trailing fields is
1100
1068
  // rejected.
1101
1069
  const rowElement = element.deserialization ? {
1070
+ kind: element.kind,
1071
+ label: element.label,
1102
1072
  deserialization: {
1103
1073
  fn: ([rowReader])=>deserializeElement(element, rowReader.readFieldArray(rowReader.remainingFields()))
1104
1074
  },
@@ -1109,6 +1079,9 @@ export function EPHEMERAL_ARRAY(element) {
1109
1079
  ]
1110
1080
  } : undefined;
1111
1081
  return {
1082
+ kind: 'ephemeral-array',
1083
+ label: `ephemeral-array(${element.label})`,
1084
+ inner: element,
1112
1085
  serialization: element.serialization ? {
1113
1086
  fn: (ea)=>[
1114
1087
  ea.materializeSlot((v)=>serializeElement(element, v))
@@ -1130,6 +1103,7 @@ export function EPHEMERAL_ARRAY(element) {
1130
1103
  */ export function STRUCT(fields) {
1131
1104
  return {
1132
1105
  kind: 'struct',
1106
+ label: `{${structFieldLabels(fields)}}`,
1133
1107
  fields,
1134
1108
  serialization: fields.every((f)=>f.type.serialization) ? {
1135
1109
  fn: (value)=>{
@@ -1152,6 +1126,42 @@ export function EPHEMERAL_ARRAY(element) {
1152
1126
  shape: fields.flatMap((f)=>f.type.shape)
1153
1127
  };
1154
1128
  }
1129
+ export function isArrayMapping(type) {
1130
+ return type.kind === 'array';
1131
+ }
1132
+ export function isBoundedVecMapping(type) {
1133
+ return type.kind === 'bounded-vec';
1134
+ }
1135
+ export function isOptionMapping(type) {
1136
+ return type.kind === 'option';
1137
+ }
1138
+ export function isStructMapping(type) {
1139
+ return type.kind === 'struct';
1140
+ }
1141
+ export function isFixedArrayMapping(type) {
1142
+ return type.kind === 'fixed-array';
1143
+ }
1144
+ export function isFixedBoundedVecMapping(type) {
1145
+ return type.kind === 'fixed-bounded-vec';
1146
+ }
1147
+ export function isEphemeralArrayMapping(type) {
1148
+ return type.kind === 'ephemeral-array';
1149
+ }
1150
+ /**
1151
+ * The comma-joined labels of a struct's fields, with nested struct labels spliced into the parent: nesting affects
1152
+ * neither the wire (struct slots concatenate) nor the interface, so the label treats nested and flat declarations as
1153
+ * the same type.
1154
+ */ function structFieldLabels(fields) {
1155
+ return fields.map((f)=>isStructMapping(f.type) ? structFieldLabels(f.type.fields) : f.type.label).join(',');
1156
+ }
1157
+ /** The field's value as a bigint, asserted to fit a `bits`-wide uint. */ function uintFromField(field, bits) {
1158
+ const max = 2n ** BigInt(bits) - 1n;
1159
+ const value = field.toBigInt();
1160
+ if (value > max) {
1161
+ throw new Error(`u${bits} overflow: value ${value} exceeds max (${max})`);
1162
+ }
1163
+ return value;
1164
+ }
1155
1165
  /** Number of InputSlots a deserializable type spans, derived from its {@link TypeMapping.shape}. */ export function slotsOf(mapping) {
1156
1166
  return mapping.shape.length;
1157
1167
  }