@typeberry/lib 0.5.10-6cb1bd5 → 0.5.10-7338c21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/package.json +1 -1
  2. package/packages/core/codec/encoder.d.ts +1 -1
  3. package/packages/core/codec/encoder.d.ts.map +1 -1
  4. package/packages/core/codec/encoder.js +3 -2
  5. package/packages/core/pvm-interface/pvm.d.ts +2 -0
  6. package/packages/core/pvm-interface/pvm.d.ts.map +1 -1
  7. package/packages/jam/block/work-package.d.ts +7 -7
  8. package/packages/jam/block/work-package.d.ts.map +1 -1
  9. package/packages/jam/block/work-package.js +12 -12
  10. package/packages/jam/executor/pvm-executor.d.ts +9 -2
  11. package/packages/jam/executor/pvm-executor.d.ts.map +1 -1
  12. package/packages/jam/executor/pvm-executor.js +15 -0
  13. package/packages/jam/in-core/externalities/refine.d.ts +18 -8
  14. package/packages/jam/in-core/externalities/refine.d.ts.map +1 -1
  15. package/packages/jam/in-core/externalities/refine.js +86 -7
  16. package/packages/jam/in-core/externalities/refine.test.js +167 -2
  17. package/packages/jam/in-core/in-core.d.ts +7 -22
  18. package/packages/jam/in-core/in-core.d.ts.map +1 -1
  19. package/packages/jam/in-core/in-core.js +16 -186
  20. package/packages/jam/in-core/in-core.test.js +47 -15
  21. package/packages/jam/in-core/is-authorized.d.ts +33 -0
  22. package/packages/jam/in-core/is-authorized.d.ts.map +1 -0
  23. package/packages/jam/in-core/is-authorized.js +72 -0
  24. package/packages/jam/in-core/is-authorized.test.d.ts +2 -0
  25. package/packages/jam/in-core/is-authorized.test.d.ts.map +1 -0
  26. package/packages/jam/in-core/is-authorized.test.js +125 -0
  27. package/packages/jam/in-core/refine.d.ts +34 -0
  28. package/packages/jam/in-core/refine.d.ts.map +1 -0
  29. package/packages/jam/in-core/refine.js +176 -0
  30. package/packages/jam/in-core/refine.test.d.ts +2 -0
  31. package/packages/jam/in-core/refine.test.d.ts.map +1 -0
  32. package/packages/jam/in-core/refine.test.js +6 -0
  33. package/packages/jam/jam-host-calls/accumulate/bless.js +9 -9
  34. package/packages/jam/jam-host-calls/externalities/partial-state.d.ts +1 -1
  35. package/packages/jam/jam-host-calls/externalities/refine-externalities.d.ts +1 -1
  36. package/packages/jam/jam-host-calls/externalities/refine-externalities.d.ts.map +1 -1
  37. package/packages/jam/jam-host-calls/general/fetch.d.ts +164 -103
  38. package/packages/jam/jam-host-calls/general/fetch.d.ts.map +1 -1
  39. package/packages/jam/jam-host-calls/general/fetch.js +117 -23
  40. package/packages/jam/jam-host-calls/general/fetch.test.js +100 -66
  41. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts +2 -2
  42. package/packages/jam/transition/accumulate/accumulate.js +2 -2
  43. package/packages/jam/transition/accumulate/accumulation-result-merge-utils.js +48 -39
  44. package/packages/jam/transition/externalities/accumulate-externalities.d.ts +2 -2
  45. package/packages/jam/transition/externalities/accumulate-externalities.d.ts.map +1 -1
  46. package/packages/jam/transition/externalities/accumulate-externalities.js +20 -7
  47. package/packages/jam/transition/externalities/accumulate-externalities.test.js +74 -4
  48. package/packages/jam/transition/externalities/accumulate-fetch-externalities.d.ts +19 -0
  49. package/packages/jam/transition/externalities/accumulate-fetch-externalities.d.ts.map +1 -0
  50. package/packages/jam/transition/externalities/accumulate-fetch-externalities.js +45 -0
  51. package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.d.ts +2 -0
  52. package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.d.ts.map +1 -0
  53. package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.js +192 -0
  54. package/packages/jam/transition/externalities/fetch-externalities.d.ts +3 -39
  55. package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
  56. package/packages/jam/transition/externalities/fetch-externalities.js +2 -88
  57. package/packages/jam/transition/externalities/index.d.ts +3 -0
  58. package/packages/jam/transition/externalities/index.d.ts.map +1 -1
  59. package/packages/jam/transition/externalities/index.js +3 -0
  60. package/packages/jam/transition/externalities/is-authorized-fetch-externalities.d.ts +22 -0
  61. package/packages/jam/transition/externalities/is-authorized-fetch-externalities.d.ts.map +1 -0
  62. package/packages/jam/transition/externalities/is-authorized-fetch-externalities.js +41 -0
  63. package/packages/jam/transition/externalities/refine-fetch-externalities.d.ts +23 -0
  64. package/packages/jam/transition/externalities/refine-fetch-externalities.d.ts.map +1 -0
  65. package/packages/jam/transition/externalities/refine-fetch-externalities.js +56 -0
  66. package/packages/jam/transition/externalities/refine-fetch-externalities.test.d.ts +2 -0
  67. package/packages/jam/transition/externalities/refine-fetch-externalities.test.d.ts.map +1 -0
  68. package/packages/jam/transition/externalities/refine-fetch-externalities.test.js +32 -0
  69. package/packages/jam/transition/externalities/fetch-externalities.test.d.ts +0 -2
  70. package/packages/jam/transition/externalities/fetch-externalities.test.d.ts.map +0 -1
  71. package/packages/jam/transition/externalities/fetch-externalities.test.js +0 -254
@@ -1,168 +1,229 @@
1
- import type { ServiceId } from "#@typeberry/block";
1
+ import type { EntropyHash, ServiceId } from "#@typeberry/block";
2
2
  import type { BytesBlob } from "#@typeberry/bytes";
3
3
  import { type U64 } from "#@typeberry/numbers";
4
4
  import type { HostCallHandler, HostCallMemory, HostCallRegisters } from "#@typeberry/pvm-host-calls";
5
5
  import { PvmExecution } from "#@typeberry/pvm-host-calls";
6
6
  import { type IGasCounter } from "#@typeberry/pvm-interface";
7
- /** Fetchable data. */
8
- export interface IFetchExternalities {
7
+ /**
8
+ * Fetchable data contexts.
9
+ *
10
+ * The fetch host call (ecalli 1) returns context-dependent data based on
11
+ * ω₁₀ (the kind selector). Each invocation context passes different
12
+ * parameters to Ω_Y, which determines which kinds return data vs NONE.
13
+ *
14
+ * Ω_Y signature: Ω_Y(ρ, φ, μ, p, n, r, i, ī, x̄, 𝐢, ...)
15
+ *
16
+ * Context parameter mapping
17
+ * IsAuthorized: Ω_Y(ρ, φ, μ, 𝐩, ∅, ∅, ∅, ∅, ∅, ∅, ∅)
18
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2e43012e4301?v=0.7.2
19
+ * Refine: Ω_Y(ρ, φ, μ, p, H₀, r, i, ī, x̄, ∅, (m,e))
20
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fe0012fe001?v=0.7.2
21
+ * Accumulate: Ω_Y(ρ, φ, μ, ∅, η'₀, ∅, ∅, ∅, ∅, 𝐢, (x,y))
22
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/30c00030c000?v=0.7.2
23
+ *
24
+ * Kind availability per context:
25
+ * Kind 0 (constants) - all contexts
26
+ * Kind 1 (n) - Refine (H₀), Accumulate (η'₀)
27
+ * Kind 2 (r) - Refine only
28
+ * Kind 3-4 (x̄ extrinsics) - Refine only
29
+ * Kind 5-6 (ī imports) - Refine only
30
+ * Kind 7-13 (p work pkg) - IsAuthorized, Refine
31
+ * Kind 14-15 (𝐢 acc items) - Accumulate only
32
+ */
33
+ export declare enum FetchContext {
34
+ IsAuthorized = "isAuthorized",
35
+ Refine = "refine",
36
+ Accumulate = "accumulate"
37
+ }
38
+ /**
39
+ * Fetch externalities for the IsAuthorized context.
40
+ *
41
+ * Ω_Y(ρ, φ, μ, 𝐩, ∅, ∅, ∅, ∅, ∅, ∅, ∅)
42
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2e43012e4301?v=0.7.2
43
+ *
44
+ * Available kinds: 0 (constants), 7-13 (work package)
45
+ */
46
+ export interface IIsAuthorizedFetch {
47
+ readonly context: FetchContext.IsAuthorized;
9
48
  /**
10
- * Encoded constants info.
49
+ * Kind 0: Encoded constants info (𝐜).
11
50
  *
12
- * https://graypaper.fluffylabs.dev/#/9a08063/32de0032e100?v=0.6.6
51
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/315001315001?v=0.7.2
13
52
  */
14
53
  constants(): BytesBlob;
15
54
  /**
16
- * Entropy.
17
- *
18
- * Is Authorized: `p` (work package?)
19
- * Refine: `H_0` (might change in the future)
20
- * Accumulate: `eta_0 prime`
21
- * On Transfer: `eta_0 prime`
55
+ * Kind 7: Encoded work package - E(𝐩).
22
56
  *
23
- * https://graypaper.fluffylabs.dev/#/9a08063/325501325501?v=0.6.6
57
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31c10231c102?v=0.7.2
24
58
  */
25
- entropy(): BytesBlob | null;
59
+ workPackage(): BytesBlob;
26
60
  /**
61
+ * Kind 8: Authorizer configuration - p_f.
27
62
  *
28
- * Authorizer trace.
63
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31c80231c802?v=0.7.2
64
+ */
65
+ authConfiguration(): BytesBlob;
66
+ /**
67
+ * Kind 9: Authorization token - p_j.
29
68
  *
30
- * Is Authorized: <empty>
31
- * Refine: `r` - authorizer trace?
32
- * Accumulate: <empty>
33
- * On Transfer: <empty>
69
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31cf0231cf02?v=0.7.2
70
+ */
71
+ authToken(): BytesBlob;
72
+ /**
73
+ * Kind 10: Refinement context - E(p_x).
34
74
  *
35
- * https://graypaper.fluffylabs.dev/#/9a08063/325b01325b01?v=0.6.6
75
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31da0231da02?v=0.7.2
36
76
  */
37
- authorizerTrace(): BytesBlob | null;
77
+ refineContext(): BytesBlob;
38
78
  /**
39
- * Inspect currently refined or other work item's extrinsics.
79
+ * Kind 11: All work-item summaries - E(↕[S(w) | w ← p_w]).
40
80
  *
41
- * Is Authorized: <empty>
42
- * Refine: `\over(x)[*]`
43
- * https://graypaper.fluffylabs.dev/#/9a08063/2fd8002fd800?v=0.6.6
44
- * Accumulate: <empty>
45
- * On Transfer: <empty>
81
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31f40231f402?v=0.7.2
82
+ */
83
+ allWorkItems(): BytesBlob;
84
+ /**
85
+ * Kind 12: Single work-item summary - S(p_w[φ₁₁]).
46
86
  *
47
- * Other: https://graypaper.fluffylabs.dev/#/9a08063/326801326801?v=0.6.6
48
- * My: https://graypaper.fluffylabs.dev/#/9a08063/327701327701?v=0.6.6
87
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31fc0231fc02?v=0.7.2
49
88
  */
50
- workItemExtrinsic(workItem: U64 | null, index: U64): BytesBlob | null;
89
+ oneWorkItem(workItem: U64): BytesBlob | null;
51
90
  /**
52
- * Inspect import segments from current or other work items.
91
+ * Kind 13: Work-item payload - p_w[φ₁₁]_y.
53
92
  *
54
- * Is Authorized: <empty>
55
- * Refine: `\over(i)[*]`
56
- * https://graypaper.fluffylabs.dev/#/9a08063/2e15012e1501?v=0.6.6
57
- * Accumulate: <empty>
58
- * On Transfer: <empty>
93
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/313b03313b03?v=0.7.2
94
+ */
95
+ workItemPayload(workItem: U64): BytesBlob | null;
96
+ }
97
+ /**
98
+ * Fetch externalities for the Refine context.
99
+ *
100
+ * Ω_Y(ρ, φ, μ, p, H₀, r, i, ī, x̄, ∅, (m,e))
101
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fe0012fe001?v=0.7.2
102
+ *
103
+ * Available kinds: 0-13 (all except accumulation items)
104
+ */
105
+ export interface IRefineFetch {
106
+ readonly context: FetchContext.Refine;
107
+ /**
108
+ * Kind 0: Encoded constants info (𝐜).
59
109
  *
60
- * Other: https://graypaper.fluffylabs.dev/#/9a08063/328501328501?v=0.6.6
61
- * My: https://graypaper.fluffylabs.dev/#/9a08063/329601329601?v=0.6.6
110
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/315001315001?v=0.7.2
62
111
  */
63
- workItemImport(workItem: U64 | null, index: U64): BytesBlob | null;
112
+ constants(): BytesBlob;
64
113
  /**
65
- * Inspect encoding of the entire work package.
114
+ * Kind 1: Entropy pool - H₀ (zero hash).
66
115
  *
67
- * Is Authorized: <empty>
68
- * Refine: `E(p)`
69
- * Accumulate: <empty>
70
- * On Transfer: <empty>
116
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fe0012fe201?v=0.7.2
117
+ */
118
+ entropy(): EntropyHash;
119
+ /**
120
+ * Kind 2: Authorizer trace (𝐫).
71
121
  *
72
- * https://graypaper.fluffylabs.dev/#/9a08063/329f0132a201?v=0.6.6
122
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/314902314902?v=0.7.2
73
123
  */
74
- workPackage(): BytesBlob | null;
124
+ authorizerTrace(): BytesBlob;
75
125
  /**
76
- * Inspect current work package's authorizer:
77
- * authorizer code hash (`u`) and parametrization (`p`).
126
+ * Kind 3 (other) / Kind 4 (my): Work-item extrinsics (x̄).
78
127
  *
79
- * Is Authorized: <empty>
80
- * Refine: `E(p_u, ↕p_p)`
81
- * Accumulate: <empty>
82
- * On Transfer: <empty>
128
+ * When workItem is null, uses Kind 4 (current work item's extrinsics).
129
+ * When workItem is provided, uses Kind 3 (other work item's extrinsics).
83
130
  *
84
- * https://graypaper.fluffylabs.dev/#/9a08063/32aa0132aa01?v=0.6.6
131
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/315402315402?v=0.7.2
132
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/317302317302?v=0.7.2
85
133
  */
86
- authorizer(): BytesBlob | null;
134
+ workItemExtrinsic(workItem: U64 | null, index: U64): BytesBlob | null;
87
135
  /**
88
- * Inspect authorization token.
136
+ * Kind 5 (other) / Kind 6 (my): Import segments (ī).
89
137
  *
90
- * Is Authorized: <empty>
91
- * Refine: `p_j`
92
- * Accumulate: <empty>
93
- * On Transfer: <empty>
138
+ * When workItem is null, uses Kind 6 (current work item's imports).
139
+ * When workItem is provided, uses Kind 5 (other work item's imports).
94
140
  *
95
- * https://graypaper.fluffylabs.dev/#/9a08063/32b10132b101?v=0.6.6
141
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/318b02318b02?v=0.7.2
142
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31aa0231aa02?v=0.7.2
96
143
  */
97
- authorizationToken(): BytesBlob | null;
144
+ workItemImport(workItem: U64 | null, index: U64): BytesBlob | null;
98
145
  /**
99
- * Inspect refine context.
146
+ * Kind 7: Encoded work package - E(p).
100
147
  *
101
- * Is Authorized: <empty>
102
- * Refine: `p_x`
103
- * Accumulate: <empty>
104
- * On Transfer: <empty>
148
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31c10231c102?v=0.7.2
149
+ */
150
+ workPackage(): BytesBlob;
151
+ /**
152
+ * Kind 8: Authorizer configuration - p_f.
105
153
  *
106
- * https://graypaper.fluffylabs.dev/#/9a08063/32b80132b801?v=0.6.6
154
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31c80231c802?v=0.7.2
107
155
  */
108
- refineContext(): BytesBlob | null;
156
+ authConfiguration(): BytesBlob;
109
157
  /**
110
- * Encoding (varlen sequence) of all work items.
158
+ * Kind 9: Authorization token - p_j.
111
159
  *
112
- * Is Authorized: <empty>
113
- * Refine: `E(↕[S(w): w <- p_w ]))`
114
- * `S(w)`: https://graypaper.fluffylabs.dev/#/9a08063/32db0132ea01?v=0.6.6
115
- * Accumulate: <empty>
116
- * On Transfer: <empty>
160
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31cf0231cf02?v=0.7.2
161
+ */
162
+ authToken(): BytesBlob;
163
+ /**
164
+ * Kind 10: Refinement context - E(p_x).
117
165
  *
118
- * https://graypaper.fluffylabs.dev/#/9a08063/32cd0132d001?v=0.6.6
166
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31da0231da02?v=0.7.2
119
167
  */
120
- allWorkItems(): BytesBlob | null;
168
+ refineContext(): BytesBlob;
121
169
  /**
122
- * Encoding of a single (selected) work item.
123
- * `S(w)`: https://graypaper.fluffylabs.dev/#/9a08063/32db0132ea01?v=0.6.6
170
+ * Kind 11: All work-item summaries - E(↕[S(w) | w ← p_w]).
124
171
  *
125
- * Is Authorized: <empty>
126
- * Refine: `S(w)`
127
- * `S(w)`: https://graypaper.fluffylabs.dev/#/9a08063/32db0132ea01?v=0.6.6
128
- * Accumulate: <empty>
129
- * On Transfer: <empty>
172
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31f40231f402?v=0.7.2
173
+ */
174
+ allWorkItems(): BytesBlob;
175
+ /**
176
+ * Kind 12: Single work-item summary - S(p_w[φ₁₁]).
130
177
  *
131
- * https://graypaper.fluffylabs.dev/#/9a08063/32d50132d501?v=0.6.6
178
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31fc0231fc02?v=0.7.2
132
179
  */
133
180
  oneWorkItem(workItem: U64): BytesBlob | null;
134
181
  /**
135
- * Retrieve work item payload.
182
+ * Kind 13: Work-item payload - p_w[φ₁₁]_y.
136
183
  *
137
- * Is Authorized: <empty>
138
- * Refine: `p_w[omega_11]_y`
139
- * Accumulate: <empty>
140
- * On Transfer: <empty>
141
- *
142
- * https://graypaper.fluffylabs.dev/#/9a08063/32f00132f001?v=0.6.6
184
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/313b03313b03?v=0.7.2
143
185
  */
144
186
  workItemPayload(workItem: U64): BytesBlob | null;
187
+ }
188
+ /**
189
+ * Fetch externalities for the Accumulate context.
190
+ *
191
+ * Ω_Y(ρ, φ, μ, ∅, η'₀, ∅, ∅, ∅, ∅, 𝐢, (x,y))
192
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/30c00030c000?v=0.7.2
193
+ *
194
+ * Available kinds: 0 (constants), 1 (entropy), 14-15 (accumulation items)
195
+ */
196
+ export interface IAccumulateFetch {
197
+ readonly context: FetchContext.Accumulate;
145
198
  /**
146
- * Get all accumulation operands (work results?) and transfers.
199
+ * Kind 0: Encoded constants info (𝐜).
147
200
  *
148
- * Is Authorized: <empty>
149
- * Refine: <empty>
150
- * Accumulate: `E(↕i)`
201
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/315001315001?v=0.7.2
202
+ */
203
+ constants(): BytesBlob;
204
+ /**
205
+ * Kind 1: Entropy pool - η'₀ (posterior entropy).
151
206
  *
152
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/314c03314c03?v=0.7.2
207
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/314302314602?v=0.7.2
153
208
  */
154
- allTransfersAndOperands(): BytesBlob | null;
209
+ entropy(): EntropyHash;
155
210
  /**
156
- * Get one selected accumulation operand or transfer.
211
+ * Kind 14: All accumulation operands and transfers - E(↕𝐢).
157
212
  *
158
- * Is Authorized: <empty>
159
- * Refine: <empty>
160
- * Accumulate: `E(i[omega_11])`
213
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/314e03314e03?v=0.7.2
214
+ */
215
+ allTransfersAndOperands(): BytesBlob | null;
216
+ /**
217
+ * Kind 15: Single accumulation operand or transfer - E(𝐢[φ₁₁]).
161
218
  *
162
- * https://graypaper.fluffylabs.dev/#/ab2cdbd/315503315503?v=0.7.2
219
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/315903315903?v=0.7.2
163
220
  */
164
221
  oneTransferOrOperand(index: U64): BytesBlob | null;
165
222
  }
223
+ /**
224
+ * Union of all context-specific fetch externality interfaces.
225
+ */
226
+ export type IFetchExternalities = IIsAuthorizedFetch | IRefineFetch | IAccumulateFetch;
166
227
  /**
167
228
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/324000324000?v=0.6.7
168
229
  */
@@ -185,8 +246,8 @@ export declare enum FetchKind {
185
246
  OtherWorkItemImports = 5,
186
247
  MyImports = 6,
187
248
  WorkPackage = 7,
188
- Authorizer = 8,
189
- AuthorizationToken = 9,
249
+ AuthConfiguration = 8,
250
+ AuthToken = 9,
190
251
  RefineContext = 10,
191
252
  AllWorkItems = 11,
192
253
  OneWorkItem = 12,
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/jam-host-calls/general/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAA8B,KAAK,GAAG,EAAE,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Y,SAAS;IACnB,SAAS,IAAI;IACb,OAAO,IAAI;IACX,eAAe,IAAI;IACnB,uBAAuB,IAAI;IAC3B,YAAY,IAAI;IAChB,oBAAoB,IAAI;IACxB,SAAS,IAAI;IACb,WAAW,IAAI;IACf,iBAAiB,IAAI;IACrB,SAAS,IAAI;IACb,aAAa,KAAK;IAClB,YAAY,KAAK;IACjB,WAAW,KAAK;IAChB,eAAe,KAAK;IACpB,uBAAuB,KAAK;IAC5B,oBAAoB,KAAK;CAC1B"}
@@ -4,6 +4,38 @@ import { tryAsSmallGas } from "#@typeberry/pvm-interface";
4
4
  import { logger } from "../logger.js";
5
5
  import { clampU64ToU32 } from "../utils.js";
6
6
  import { HostCallResult } from "./results.js";
7
+ /**
8
+ * Fetchable data contexts.
9
+ *
10
+ * The fetch host call (ecalli 1) returns context-dependent data based on
11
+ * ω₁₀ (the kind selector). Each invocation context passes different
12
+ * parameters to Ω_Y, which determines which kinds return data vs NONE.
13
+ *
14
+ * Ω_Y signature: Ω_Y(ρ, φ, μ, p, n, r, i, ī, x̄, 𝐢, ...)
15
+ *
16
+ * Context parameter mapping
17
+ * IsAuthorized: Ω_Y(ρ, φ, μ, 𝐩, ∅, ∅, ∅, ∅, ∅, ∅, ∅)
18
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2e43012e4301?v=0.7.2
19
+ * Refine: Ω_Y(ρ, φ, μ, p, H₀, r, i, ī, x̄, ∅, (m,e))
20
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/2fe0012fe001?v=0.7.2
21
+ * Accumulate: Ω_Y(ρ, φ, μ, ∅, η'₀, ∅, ∅, ∅, ∅, 𝐢, (x,y))
22
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/30c00030c000?v=0.7.2
23
+ *
24
+ * Kind availability per context:
25
+ * Kind 0 (constants) - all contexts
26
+ * Kind 1 (n) - Refine (H₀), Accumulate (η'₀)
27
+ * Kind 2 (r) - Refine only
28
+ * Kind 3-4 (x̄ extrinsics) - Refine only
29
+ * Kind 5-6 (ī imports) - Refine only
30
+ * Kind 7-13 (p work pkg) - IsAuthorized, Refine
31
+ * Kind 14-15 (𝐢 acc items) - Accumulate only
32
+ */
33
+ export var FetchContext;
34
+ (function (FetchContext) {
35
+ FetchContext["IsAuthorized"] = "isAuthorized";
36
+ FetchContext["Refine"] = "refine";
37
+ FetchContext["Accumulate"] = "accumulate";
38
+ })(FetchContext || (FetchContext = {}));
7
39
  const IN_OUT_REG = 7;
8
40
  /**
9
41
  * https://graypaper.fluffylabs.dev/#/7e6ff6a/324000324000?v=0.6.7
@@ -43,62 +75,124 @@ export class Fetch {
43
75
  regs.set(IN_OUT_REG, value === null ? HostCallResult.NONE : valueLength);
44
76
  }
45
77
  getValue(kind, regs) {
78
+ const ext = this.fetch;
79
+ // Kind 0: constants - all contexts
46
80
  if (kind === FetchKind.Constants) {
47
- return this.fetch.constants();
81
+ return ext.constants();
48
82
  }
83
+ // Kind 1: entropy - Refine, Accumulate
49
84
  if (kind === FetchKind.Entropy) {
50
- return this.fetch.entropy();
85
+ if (ext.context === FetchContext.IsAuthorized) {
86
+ return null;
87
+ }
88
+ return ext.entropy();
51
89
  }
90
+ // Kind 2: authorizer trace - Refine only
52
91
  if (kind === FetchKind.AuthorizerTrace) {
53
- return this.fetch.authorizerTrace();
92
+ if (ext.context !== FetchContext.Refine) {
93
+ return null;
94
+ }
95
+ return ext.authorizerTrace();
54
96
  }
97
+ // Kind 3: other work item extrinsics - Refine only
55
98
  if (kind === FetchKind.OtherWorkItemExtrinsics) {
99
+ if (ext.context !== FetchContext.Refine) {
100
+ return null;
101
+ }
56
102
  const workItem = regs.get(11);
57
103
  const index = regs.get(12);
58
- return this.fetch.workItemExtrinsic(workItem, index);
104
+ return ext.workItemExtrinsic(workItem, index);
59
105
  }
106
+ // Kind 4: my extrinsics - Refine only
60
107
  if (kind === FetchKind.MyExtrinsics) {
108
+ if (ext.context !== FetchContext.Refine) {
109
+ return null;
110
+ }
61
111
  const index = regs.get(11);
62
- return this.fetch.workItemExtrinsic(null, index);
112
+ return ext.workItemExtrinsic(null, index);
63
113
  }
114
+ // Kind 5: other work item imports - Refine only
64
115
  if (kind === FetchKind.OtherWorkItemImports) {
116
+ if (ext.context !== FetchContext.Refine) {
117
+ return null;
118
+ }
65
119
  const workItem = regs.get(11);
66
120
  const index = regs.get(12);
67
- return this.fetch.workItemImport(workItem, index);
121
+ return ext.workItemImport(workItem, index);
68
122
  }
123
+ // Kind 6: my imports - Refine only
69
124
  if (kind === FetchKind.MyImports) {
125
+ if (ext.context !== FetchContext.Refine) {
126
+ return null;
127
+ }
70
128
  const index = regs.get(11);
71
- return this.fetch.workItemImport(null, index);
129
+ return ext.workItemImport(null, index);
72
130
  }
131
+ // Kind 7: work package - IsAuthorized, Refine
73
132
  if (kind === FetchKind.WorkPackage) {
74
- return this.fetch.workPackage();
75
- }
76
- if (kind === FetchKind.Authorizer) {
77
- return this.fetch.authorizer();
78
- }
79
- if (kind === FetchKind.AuthorizationToken) {
80
- return this.fetch.authorizationToken();
81
- }
133
+ if (ext.context === FetchContext.Accumulate) {
134
+ return null;
135
+ }
136
+ return ext.workPackage();
137
+ }
138
+ // Kind 8: auth configuration - IsAuthorized, Refine
139
+ if (kind === FetchKind.AuthConfiguration) {
140
+ if (ext.context === FetchContext.Accumulate) {
141
+ return null;
142
+ }
143
+ return ext.authConfiguration();
144
+ }
145
+ // Kind 9: authorization token - IsAuthorized, Refine
146
+ if (kind === FetchKind.AuthToken) {
147
+ if (ext.context === FetchContext.Accumulate) {
148
+ return null;
149
+ }
150
+ return ext.authToken();
151
+ }
152
+ // Kind 10: refine context - IsAuthorized, Refine
82
153
  if (kind === FetchKind.RefineContext) {
83
- return this.fetch.refineContext();
154
+ if (ext.context === FetchContext.Accumulate) {
155
+ return null;
156
+ }
157
+ return ext.refineContext();
84
158
  }
159
+ // Kind 11: all work items - IsAuthorized, Refine
85
160
  if (kind === FetchKind.AllWorkItems) {
86
- return this.fetch.allWorkItems();
161
+ if (ext.context === FetchContext.Accumulate) {
162
+ return null;
163
+ }
164
+ return ext.allWorkItems();
87
165
  }
166
+ // Kind 12: one work item - IsAuthorized, Refine
88
167
  if (kind === FetchKind.OneWorkItem) {
168
+ if (ext.context === FetchContext.Accumulate) {
169
+ return null;
170
+ }
89
171
  const workItem = regs.get(11);
90
- return this.fetch.oneWorkItem(workItem);
172
+ return ext.oneWorkItem(workItem);
91
173
  }
174
+ // Kind 13: work item payload - IsAuthorized, Refine
92
175
  if (kind === FetchKind.WorkItemPayload) {
176
+ if (ext.context === FetchContext.Accumulate) {
177
+ return null;
178
+ }
93
179
  const workItem = regs.get(11);
94
- return this.fetch.workItemPayload(workItem);
180
+ return ext.workItemPayload(workItem);
95
181
  }
182
+ // Kind 14: all transfers and operands - Accumulate only
96
183
  if (kind === FetchKind.AllTransfersAndOperands) {
97
- return this.fetch.allTransfersAndOperands();
184
+ if (ext.context !== FetchContext.Accumulate) {
185
+ return null;
186
+ }
187
+ return ext.allTransfersAndOperands();
98
188
  }
189
+ // Kind 15: one transfer or operand - Accumulate only
99
190
  if (kind === FetchKind.OneTransferOrOperand) {
191
+ if (ext.context !== FetchContext.Accumulate) {
192
+ return null;
193
+ }
100
194
  const index = regs.get(11);
101
- return this.fetch.oneTransferOrOperand(index);
195
+ return ext.oneTransferOrOperand(index);
102
196
  }
103
197
  return null;
104
198
  }
@@ -113,8 +207,8 @@ export var FetchKind;
113
207
  FetchKind[FetchKind["OtherWorkItemImports"] = 5] = "OtherWorkItemImports";
114
208
  FetchKind[FetchKind["MyImports"] = 6] = "MyImports";
115
209
  FetchKind[FetchKind["WorkPackage"] = 7] = "WorkPackage";
116
- FetchKind[FetchKind["Authorizer"] = 8] = "Authorizer";
117
- FetchKind[FetchKind["AuthorizationToken"] = 9] = "AuthorizationToken";
210
+ FetchKind[FetchKind["AuthConfiguration"] = 8] = "AuthConfiguration";
211
+ FetchKind[FetchKind["AuthToken"] = 9] = "AuthToken";
118
212
  FetchKind[FetchKind["RefineContext"] = 10] = "RefineContext";
119
213
  FetchKind[FetchKind["AllWorkItems"] = 11] = "AllWorkItems";
120
214
  FetchKind[FetchKind["OneWorkItem"] = 12] = "OneWorkItem";