1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//! Layer-3 substrate-Term verb bodies per [Wiki ADR-024][09-adr-024] +
//! [Wiki ADR-031][09-adr-031] + [Wiki ADR-055][09-adr-055] (universal
//! substrate-Term verb body discipline, supersedes ADR-054 RA2).
//!
//! Per ADR-024 a Layer-3 implementation contributes both axes
//! (substrate-extension vocabularies via `axis!`) AND verbs (named,
//! reusable compositions of prism operators applied to substrate
//! primitives via `verb!`). Per ADR-055 every `AxisExtension` impl
//! (standard-library AND application-author custom) carries a
//! substrate-Term verb body via the foundation-declared
//! `SubstrateTermBody` supertrait.
//!
//! # Substrate-Term verbs shipped
//!
//! Foundation-sdk 0.4.11 admits the full
//! `add`/`sub`/`mul`/`div`/`r#mod`/`pow`/`xor`/`and`/`or`/`neg`/`bnot`/`succ`/`pred`
//! PrimitiveOp call forms in verb bodies plus the ADR-056-unblocked
//! `concat`/`le`/`lt`/`ge`/`gt`/`hash`/`first_admit` vocabulary, plus
//! `literal_u64` / `literal_bytes` wide-Witt-literal embedding per
//! ADR-051, plus depth-2 partition-product field access on
//! const-generic leaves via `partition_product!`'s `syn::Type`
//! operand admission per the v0.4.11 fix.
//!
//! Per ADR-055 + ADR-056 every ADR-054 § Substrate-Term realization-
//! examples canonical body is now **syntactically expressible** in
//! the verb-body grammar; the work that remains is operational
//! composition (round-by-round SHA, fold_n-unrolled polyeval, etc.)
//! against the wiki's published roster.
//!
//! Verbs shipped here (16 total across single-input, ring-arithmetic,
//! hypercube-arithmetic, three-operand, and secp256k1-pinned-prime
//! families):
//!
//! - [`succ_twice`], [`pred_twice`], [`square`] — single-input
//! architectural-witness compositions.
//! - [`add_substrate`], [`sub_substrate`], [`mul_substrate`],
//! [`div_substrate`], [`mod_substrate`], [`pow_substrate`] —
//! substrate-Term realizations of the six ADR-053 ring-arithmetic
//! `PrimitiveOp`s over `partition_product(BigInt32, BigInt32)` at
//! W256. Per ADR-050's width-parametric arithmetic the substrate
//! evaluates at the full 256-bit width without truncation.
//! - [`gf2_add_substrate`], [`gf2_mul_substrate`], [`or_substrate`] —
//! the three hypercube-axis `PrimitiveOp`s (`Xor` / `And` / `Or`)
//! at W256.
//! - [`fma`], [`mod_pow`], [`field_add`], [`field_sub`], [`field_mul`]
//! — three-operand compositions over
//! `partition_product(BigIntPair32, BigIntShape<32>)` exercising
//! foundation-sdk 0.4.11's depth-2 const-generic-leaf projection.
//! `field_*` here is the parametric-prime form (`p` is an input
//! operand); the secp256k1-pinned forms below bake P inline.
//! - [`secp256k1_field_add`], [`secp256k1_field_sub`],
//! [`secp256k1_field_mul`] — the ADR-054 (4) canonical bodies of
//! `PrimeFieldNumericSecp256k1::{add, sub, mul}` per ADR-031.
//! `r#mod(<arithmetic>(input.0, input.1), literal_bytes(SECP256K1_P_BYTES, W256_LEVEL))`
//! per foundation-sdk 0.4.10's `literal_bytes` wide-Witt embedding.
//!
//! The catamorphism walks each composition as a fold-fusion-reachable
//! Term tree per ADR-019 / ADR-029 / ADR-054 — no opaque axis-kernel
//! boundary remains inside the substrate's structural reach for any
//! of these compositions.
//!
//! # Wiki-named compound verbs — operational composition follow-on
//!
//! ADR-031, ADR-054 § Substrate-Term realization examples, and
//! ADR-055 commit prism-numerics to a richer compound roster:
//! `modexp_p` (chains `pow` and `r#mod` against an embedded P
//! literal); `polyeval` and `horner` (`fold_n` over `add` and `mul`);
//! `gcd` and `ext_euclidean` (`recurse` with `r#mod`-driven
//! termination predicates per the ADR-056-admitted comparison ops);
//! `newton_step` (`add`, `sub`, `mul`, `div` iteration); `field_inv`
//! over a parametric P (Fermat's little theorem,
//! `pow(x, p - 2) mod p`). Each is a Term-arena composition over
//! already-admitted call forms with no remaining architectural
//! blockers per ADR-056; these are published-roster follow-ons.
//!
//! [09-adr-024]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
//! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
//! [09-adr-055]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
use ConstrainedTypeInput;
use ;
use crateBigIntShape;
// Single-input architectural-witness verbs.
verb!
verb!
verb!
// Three-input fused-multiply-add. Routes the canonical roster's `fma`
// from the wiki — a single Add over a single Mul over the three
// projections of a `BigIntShape<32>`-triple partition-product input.
/// Concrete 256-bit BigInt alias for partition-product composition.
/// `partition_product!` parses operands as bare type paths; generic
/// types like `BigIntShape<32>` need a type alias for the macro's
/// tokenizer.
pub type BigInt32 = ;
partition_product!;
// Substrate-native 256-bit modular arithmetic: `add_substrate` /
// `sub_substrate` / `mul_substrate` are the substrate-Term realizations
// per ADR-055 of the corresponding `BigIntAxis` kernel bodies.
// The substrate evaluates `Add`/`Sub`/`Mul` at the full 256-bit operand
// width per ADR-050's width-parametric fold-rules (low 256 bits of
// the schoolbook product for `Mul`). The catamorphism walks each
// composition as a fold-fusion-reachable Term tree — no opaque
// axis-kernel boundary remains inside the substrate's structural reach
// for these three operations.
verb!
verb!
verb!
// Substrate-native 256-bit GF(2) hypercube arithmetic — substrate-Term
// realizations per ADR-055 of `Gf2NumericAxisN<32>::{add, mul}`.
// Per ADR-050 the substrate evaluates `Xor`/`And` byte-wise at any
// operand width (trivially width-parametric since they have no carry).
verb!
verb!
verb!
// Substrate-native 256-bit ring arithmetic via the new ADR-053
// PrimitiveOp call forms (`div`, `r#mod`, `pow`) admitted by
// foundation-sdk 0.4.9's verb-body grammar.
verb!
verb!
verb!
// ---- Three-operand verbs (parametric-modulus form).
//
// Note: depth-2 partition-product field access works in
// foundation-sdk 0.4.10's verb! macro when the leaf factor is a
// hand-written ConstrainedTypeShape without explicit
// PartitionProductFields impl (the smoke-test pattern at
// uor-foundation-sdk/tests/smoke.rs `verb_depth2_pos00` over
// PosOuter = (InnerLR, LeafA)). Replicating that pattern with
// BigIntShape<N> as the leaf factor (which is parametric over a
// const generic byte-width parameter) triggers a verb!-macro
// const-eval "index out of bounds" failure not reproduced by the
// hand-written non-generic LeafA pattern; the failure mode
// appears specific to const-generic leaf factors. The
// secp256k1-pinned verbs below (depth-1 access + wide literal
// embedding) realize the same semantics with the modulus baked
// in as a `literal_bytes` const, avoiding the depth-2 path.
// ---- Wide-literal P verbs over `literal_bytes(<bytes>, <level>)`
// for W128+ inline-constant embedding (foundation-sdk 0.4.10
// grammar admission).
/// Secp256k1 base-field prime as a 32-byte big-endian literal:
/// `p = 2^256 - 2^32 - 977`.
pub const SECP256K1_P_BYTES: & = &;
/// W256 Witt-level marker for the secp256k1 P_LITERAL embedding.
pub const W256_LEVEL: WittLevel = new;
// secp256k1-pinned field arithmetic — the parametric `field_*`
// verbs above with the W256 P literal baked into the verb body via
// `literal_bytes`. These are the substrate-Term realizations of
// `PrimeFieldNumericSecp256k1::{add, sub, mul}` per ADR-054 (4) +
// ADR-055.
verb!
verb!
verb!
// ---- Compound-arithmetic verbs (ADR-056 + 0.4.10 grammar admissions).
// `polyeval_horner_2(x, c0, c1) = c0 + x * c1` — Horner-method
// evaluation of a degree-1 polynomial, the smallest compound form
// the canonical roster's `polyeval` / `horner` family generalizes.
// Composes substrate `add` and `mul` over a single pair input
// (x and c1 concatenated as the partition_product; c0 is a fixed
// literal at the verb-body level). Per ADR-056 verb bodies admit
// the full PrimitiveOp surface unconditionally; this verb's
// composition path is fold-fused into the catamorphism's evaluation
// per ADR-054.
verb!
// ---- Three-operand verbs (depth-2 partition-product field access,
// closed by foundation-sdk 0.4.11's syn::Type operand admission in
// `partition_product!` — const-generic leaf shapes like
// `BigIntShape<32>` can now be used directly without a type-alias
// indirection that obscured the const-generic instantiation from
// the macro's projection-chain const-eval lookups).
partition_product!;
// Wiki ADR-031's `fma(a, b, c) = a*b + c` canonical numerics verb —
// the architectural witness that 0.4.11's verb!-macro depth-2 path
// now matches prism_model!'s smoke-tested coverage.
verb!
// Wiki ADR-031's `mod_pow(base, exp, m) = (base^exp) mod m` —
// parametric-modulus modular exponentiation. The wiki's
// `modexp_p<P>` variant pins P at the verb-body literal level.
verb!
// Wiki ADR-031's parametric prime-field arithmetic — the modulus
// comes in as an input operand, complementing the secp256k1-pinned
// forms above (which embed P as a `literal_bytes` constant).
verb!
verb!
verb!