From b7987b777dd18078a49671323b4a2f9a34637695 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Tue, 10 Nov 2026 23:16:43 +1000 Subject: [PATCH 1/4] fix(stack-encrypt)!: a data plan refuses an order index on bytes The typed path already refuses an order index on bytes at compile time. The dynamic path, which the Go SDK uses through the guest, still accepted the declaration: `dynamic::admits` read the table of values the scheme has a term for, and the scheme has an order term for bytes. Each row then stored a term anyone holding two rows can compare, and every ordering query was refused as `operator_not_answered`, from a second list in `dynamic::query`. `admits` now refuses `ore`, `ope` and `ore_block` on bytes, and the second list is gone: `Op::answered_by` reads `admits` alone, so the two cannot disagree again. `IndexSpec::defines` is unchanged, because it reports what the scheme defines, and the low-level term operations still use it. A row stored under such a declaration still opens once the index is removed from the plan. The frozen stored rows declare one on two fields, so their test now opens them under the plan with those indexes removed, and the fixture file is untouched. The conformance corpus changes with the rule: the three bytes declaration cases are refused, the `unanswered` list is removed from the value profile and from both runners, and the query-refusal profile's bytes field declares equality alone. In Go, `stashgen` refuses the tag as a field error, its notice for an index no generated method queries is removed with the only case it had, and the two probe types lose their bytes field. Closes #1577 --- .../stack-encrypt/exchange-contract.md | 2 +- .../stack-encrypt/query-refusals-contract.md | 4 +- .../v1/record-declarations-v1.cases.json | 18 ++- .../v1/record-query-refusals-v1.cases.json | 14 +- .../v1/record-values-v1.cases.json | 5 +- conformance/stack-encrypt/values-contract.md | 28 ++-- .../2026-10-24-stack-encrypt-api-plan.md | 9 ++ languages/golang/CHANGELOG.md | 15 ++- languages/golang/encrypt/README.md | 17 ++- .../encrypt/exchange_conformance_test.go | 17 +-- .../encrypt/internal/testusers/probe_stash.go | 40 +----- .../internal/testusers/probeope_stash.go | 40 +----- .../encrypt/internal/testusers/users.go | 2 - languages/golang/encrypt/order_test.go | 12 +- .../golang/encrypt/value_conformance_test.go | 17 --- languages/golang/stashgen/emit.go | 60 +++------ .../golang/stashgen/enginetest/enginetest.go | 11 +- languages/golang/stashgen/read.go | 2 +- languages/golang/stashgen/refusal_test.go | 44 +++---- packages/stack-encrypt/CHANGELOG.md | 24 ++++ packages/stack-encrypt/src/dynamic/kind.rs | 28 +++- packages/stack-encrypt/src/dynamic/query.rs | 40 +----- packages/stack-encrypt/src/dynamic/term.rs | 35 +++-- .../tests/exchange_conformance.rs | 12 +- .../stack-encrypt/tests/fixtures/README.md | 8 ++ packages/stack-encrypt/tests/stored_rows.rs | 122 ++++++++++++++++-- .../stack-encrypt/tests/value_conformance.rs | 32 ----- 27 files changed, 312 insertions(+), 346 deletions(-) diff --git a/conformance/stack-encrypt/exchange-contract.md b/conformance/stack-encrypt/exchange-contract.md index 574efb0d54..189cfea99a 100644 --- a/conformance/stack-encrypt/exchange-contract.md +++ b/conformance/stack-encrypt/exchange-contract.md @@ -30,7 +30,7 @@ mise run test:conformance:exchange | Kind | Producer writes | Consumer checks | |---|---|---| -| `values` | One record per positive case of `v1/record-values-v1.cases.json` (the value-boundary corpus), under the plan that case declares, with context `["conformance", "exchange"]`: the sealed leaf and every declared index term; nothing for a SQL null | The record opens to the case's typed input. Every stored term equals the term the consumer's own query of the same value derives (`eq` for equality, `lt` for an order index), and the `equal_query` spelling derives the same equality term. An index the corpus lists as unanswered is present and not queried | +| `values` | One record per positive case of `v1/record-values-v1.cases.json` (the value-boundary corpus), under the plan that case declares, with context `["conformance", "exchange"]`: the sealed leaf and every declared index term; nothing for a SQL null | The record opens to the case's typed input. Every stored term equals the term the consumer's own query of the same value derives (`eq` for equality, `lt` for an order index), and the `equal_query` spelling derives the same equality term. | | `record` | The rows of the corpus's one record: a passthrough `int64` id (held on the host by Go, lowered as a `passthrough` output by Rust), text, `uint32`, decimal, date and timestamp fields with equality and order terms, a SQL-null text field and a sealed-null `float32` field, under context `["conformance", "exchange", "people"]` | The passthrough carried equals the corpus input; every sealed field opens to its input, a sealed null opens as null and a SQL null is absent from storage and opens as null; every stored term equals the consumer's derived query term | | `blobs` | A whole struct (`name`, `age`, `tags`, optional `nickname`) as one opaque ciphertext under `["conformance", "exchange", "blob"]`, field `value`: Rust through `OpaqueBlob`, Go through the storage blob the generated opaque path writes (`vcffi.MarshalStorage` sealed as the one `bytes` field) | The ciphertext opens and decodes to the corpus value through the other SDK's opaque reader (`OpaqueBlob` or `gensupport.Opaque`). A nil Go slice and an empty Rust `Vec` are one value; Rust's `Some` marker and Go's bare pointer are one value | | `eql-rows` | The EQL v4 `profiles` rows: every column of the committed fixture's plaintexts sealed afresh, Rust through eql-bindings' typed targets, Go through its generated code | Each column opens to the plaintext through the other side's typed target, and each equality column's stored `hm` equals the term the consumer's own equality query derives for that plaintext (the generated `*Eq` query in Go, the typed `*EqQuery` target in Rust) | diff --git a/conformance/stack-encrypt/query-refusals-contract.md b/conformance/stack-encrypt/query-refusals-contract.md index ce0c15779e..df6edf8836 100644 --- a/conformance/stack-encrypt/query-refusals-contract.md +++ b/conformance/stack-encrypt/query-refusals-contract.md @@ -21,7 +21,7 @@ and `languages/golang/encrypt/query_refusal_conformance_test.go`. `["conformance", ]`: equality-only text, match-only text, order-only text (ORE and block ORE), an integer with equality and order, an order-only float, a 128-bit integer with equality and OPE, a ciphertext-only bool and -text, a sealed-null and a SQL-null integer, and bytes with an order index. +text, a sealed-null and a SQL-null integer, and equality-only bytes. A case names a `field`, an `operator` and an `input`: a scalar `{type, text}` in the value profile's form, or `{"type": "list", "items": [...]}` for a @@ -40,7 +40,7 @@ Source and plan refusals cover every scalar operator (`eq`, `lt`, `lte`, indexes do not answer it, one case per pair: the equality-only text and integer, the match-only text, the ORE and block ORE text, the order-only float, the ciphertext-only bool and text, and the bytes field (equality -and an order index no operator reads). The 128-bit integer (equality and +alone: a declaration refuses an order index on bytes). The 128-bit integer (equality and OPE) and the 32-bit integer (equality and ORE) answer every operator but `matches`. The SQL-null integer shares the equality-only integer's indexes and is not repeated. A JSON document operator on an diff --git a/conformance/stack-encrypt/v1/record-declarations-v1.cases.json b/conformance/stack-encrypt/v1/record-declarations-v1.cases.json index 9df28c8eed..6dadcada26 100644 --- a/conformance/stack-encrypt/v1/record-declarations-v1.cases.json +++ b/conformance/stack-encrypt/v1/record-declarations-v1.cases.json @@ -1916,7 +1916,11 @@ } } }, - "accepted": true + "accepted": false, + "expected_error": { + "code": "stack_encrypt::dynamic_plan", + "fields": { "reason": "index_not_admitted", "field": "value" } + } }, { "id": "type-bytes-ope", @@ -1929,7 +1933,11 @@ } } }, - "accepted": true + "accepted": false, + "expected_error": { + "code": "stack_encrypt::dynamic_plan", + "fields": { "reason": "index_not_admitted", "field": "value" } + } }, { "id": "type-bytes-ore_block", @@ -1942,7 +1950,11 @@ } } }, - "accepted": true + "accepted": false, + "expected_error": { + "code": "stack_encrypt::dynamic_plan", + "fields": { "reason": "index_not_admitted", "field": "value" } + } }, { "id": "type-array-eq", diff --git a/conformance/stack-encrypt/v1/record-query-refusals-v1.cases.json b/conformance/stack-encrypt/v1/record-query-refusals-v1.cases.json index 1b126161a0..d8da2e08e4 100644 --- a/conformance/stack-encrypt/v1/record-query-refusals-v1.cases.json +++ b/conformance/stack-encrypt/v1/record-query-refusals-v1.cases.json @@ -51,7 +51,7 @@ }, "data": { "kind": "bytes", - "outputs": ["c", "eq", "ore"] + "outputs": ["c", "eq"] } }, "cases": [ @@ -216,7 +216,7 @@ } }, { - "id": "lt-on-bytes-order-index", + "id": "lt-on-bytes", "field": "data", "operator": "lt", "input": { @@ -773,7 +773,7 @@ } }, { - "id": "lte-on-bytes-order-index", + "id": "lte-on-bytes", "field": "data", "operator": "lte", "input": { @@ -789,7 +789,7 @@ } }, { - "id": "gt-on-bytes-order-index", + "id": "gt-on-bytes", "field": "data", "operator": "gt", "input": { @@ -805,7 +805,7 @@ } }, { - "id": "gte-on-bytes-order-index", + "id": "gte-on-bytes", "field": "data", "operator": "gte", "input": { @@ -821,7 +821,7 @@ } }, { - "id": "between-on-bytes-order-index", + "id": "between-on-bytes", "field": "data", "operator": "between", "input": { @@ -846,7 +846,7 @@ } }, { - "id": "matches-on-bytes-order-index", + "id": "matches-on-bytes", "field": "data", "operator": "matches", "input": { diff --git a/conformance/stack-encrypt/v1/record-values-v1.cases.json b/conformance/stack-encrypt/v1/record-values-v1.cases.json index 4cc29b3ae8..683c8a73d2 100644 --- a/conformance/stack-encrypt/v1/record-values-v1.cases.json +++ b/conformance/stack-encrypt/v1/record-values-v1.cases.json @@ -342,13 +342,12 @@ "id": "bytes-binary", "kind": "bytes", "null": "", - "outputs": ["c", "eq", "ore"], + "outputs": ["c", "eq"], "input": { "type": "bytes", "text": "00ff10" }, - "frame": "0b0300000000ff10", - "unanswered": ["ore"] + "frame": "0b0300000000ff10" }, { "id": "string-nul", diff --git a/conformance/stack-encrypt/values-contract.md b/conformance/stack-encrypt/values-contract.md index 2948a13c16..4901a7a044 100644 --- a/conformance/stack-encrypt/values-contract.md +++ b/conformance/stack-encrypt/values-contract.md @@ -93,19 +93,21 @@ requirements 1 to 4: it stores no record, so no data key is generated, no term exists to compare and no ciphertext is opened; its row reads back as null. -`unanswered` lists stored indexes no query operator answers for the kind. A -query of such an index is refused as `operator_not_answered` in both -runners. Today that is the order index on `bytes`: the declaration admits -it and the engine stores an order term, but no dynamic operator reads it. - -This is a leak, not only a gap. Anyone who holds the stored rows can -compare the order terms without a key. No query uses them. - -The typed Rust path refuses it. An order index is bounded by vitaminc-ore's -`Orderable`, which does not cover `Vec`, so an order index on bytes -does not compile. The fix for the declaration is to refuse an order index -on `bytes` there too. Data that Go rc.3 stored must stay readable. Until -then, this entry keeps the behaviour visible. +Every index a case declares is one a query operator answers for the kind, +because a declaration admits no other. An order index on `bytes` is the +case that shows it: the scheme defines an order term for bytes, but no +ordering operator is answered over them, so a stored term would let anyone +who holds two rows compare them without a key, and no query could use it. +Both paths refuse it. The typed Rust path bounds an order index on +vitaminc-ore's `Orderable`, which does not cover `Vec`, so the +declaration does not compile. The dynamic path, which both runners +use, refuses the declaration as `index_not_admitted` +(`v1/record-declarations-v1.cases.json`, cases `type-bytes-ore`, +`type-bytes-ope` and `type-bytes-ore_block`). + +A row stored under an earlier declaration of such an index still opens +once the index is removed from the plan: opening ignores a stored term the +plan does not declare. `expected_error` cases are refused before any pending operation, with the structured diagnostic `code`, `reason` and `field`, and no key call. They diff --git a/docs/plans/2026-10-24-stack-encrypt-api-plan.md b/docs/plans/2026-10-24-stack-encrypt-api-plan.md index 76e803c6f2..3c1b7b2222 100644 --- a/docs/plans/2026-10-24-stack-encrypt-api-plan.md +++ b/docs/plans/2026-10-24-stack-encrypt-api-plan.md @@ -2280,6 +2280,15 @@ review. The rules are the query artifact's. generated from the `op` types. Each index declares its operators and admitted plaintexts once, and `index_for` reads them. Overlap is refused on both paths. A test shows the typed and dynamic faces agree. + An index admits exactly the plaintexts one of its operators + answers. The typed path enforces this with a trait bound, not a + test: each order index, order term and ordering operator is bounded + by vitaminc-ore's `Orderable`, which does not cover bytes. So an + order index on bytes does not compile. The dynamic path refuses the + declaration, in `dynamic::admits`, as `index_not_admitted`. A row + stored under such a declaration still opens once the index is removed + from the plan, because opening ignores a stored term the plan does + not declare. 2. Derivation once, refusals once. The `sem` query functions, the analyzer in place of `MatchCase`, and `Match` arrive. `check`, `verifier`, `admit`, `QueryToken`, `check_input`, and the diff --git a/languages/golang/CHANGELOG.md b/languages/golang/CHANGELOG.md index f32b0e4ec4..28404aaddd 100644 --- a/languages/golang/CHANGELOG.md +++ b/languages/golang/CHANGELOG.md @@ -36,6 +36,18 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit. 9999. If you might have stored one, check before you upgrade. Decrypt the column with the release you run now, or check its plaintext source. +- **An order index on bytes is refused** (#1577). A `[]byte` field tagged + `index=ore`, `index=ope` or `index=ore_block` is now a field error from + `stashgen`, and a plan built by hand with one is refused by the guest + (`index_not_admitted`) before any key is requested. No ordering operator + is answered over bytes, so the field stored an order term that anyone + who read the column could compare and that no query could use. + `stashgen`'s notice for an index no generated method queries is gone + with the case it described. To upgrade, remove the index from the tag + and generate again. Rows stored with the term still open: opening + ignores a stored term the plan does not declare. The stored terms stay + in the database until the row is written again or the column is dropped. + ### Changed - `vcffi` and `vcvalue` move to vitaminc `f1fc9ae74`, the commit vitaminc @@ -300,8 +312,7 @@ In the code: is requested. Before, the field stored both terms and every query used the ORE one; the OPE term cost a write and told anyone who read the column how its values order. `stashgen`'s notice for a second order index - is gone with the case it described; the notice for an order index on - bytes stays. + is gone with the case it described. - **`Cipher.Extend` is now `Cipher.Scope`, and `Cipher.Bind` is new** (#1487). A scope narrows the data and the queries over it. A binding ties diff --git a/languages/golang/encrypt/README.md b/languages/golang/encrypt/README.md index dc9c7148f5..413cfb6a3d 100644 --- a/languages/golang/encrypt/README.md +++ b/languages/golang/encrypt/README.md @@ -264,7 +264,7 @@ or a type defined over one (`type Email string`): | Go field | Seals as | Indexes it can store | Query methods | |---|---|---|---| | `string` | text | `equality`, `match`, `ore`, `ope` | `Eq`, `Matches`, `Lt`, `Lte`, `Gt`, `Gte`, `Between` | -| `[]byte` | bytes | `equality`, `ore`, `ope` | `Eq` | +| `[]byte` | bytes | `equality` | `Eq` | | `bool` | a boolean | none | none | | `int16`, `int32`, `int64`, `int` | an integer of the field's own width (`int` is 64-bit) | `equality`, `ore`, `ope` | `Eq`, `Lt`, `Lte`, `Gt`, `Gte`, `Between` | | `uint16`, `uint32`, `uint64`, `uint` | the same, unsigned | `equality`, `ore`, `ope` | the same | @@ -275,9 +275,10 @@ or a type defined over one (`type Email string`): | `encrypt.Date` | a calendar date | `equality` | `Eq` | | `time.Time` | a timestamp, to the nanosecond, in UTC | `equality` | `Eq` | -Each query method needs its index declared. An `ore` or `ope` index on bytes -stores its term, but the engine answers no ordering through it, so such a -field has no `Lt` (see [Queries](#queries)). +Each query method needs its index declared. A field of bytes takes no `ore` +or `ope` index: the engine answers no ordering over bytes, so the term +would be stored and never queried, and `stashgen` refuses the declaration +(see [Queries](#queries)). `encrypt.Date`, `Int128`, `Uint128` and `Decimal` are vitaminc's `vcvalue` types; build them with `encrypt.DateOf`, `ParseInt128`, `ParseUint128` and @@ -359,11 +360,9 @@ one value, and every NaN is one value, above `+Inf`, so `Between(math.NaN(), math.Inf(1))` matches nothing. A `float32` orders as the `float64` it widens to. -An order index on bytes stores its term but answers no ordering -operator, so such a field has no `Lt`; nor does the `ope` index of a field -that declares `ore` too, since `ore` answers the orderings. stashgen prints a notice for each such index, on stderr and in -the generated file: the terms are stored, and only your own code can compare -them. A match index on an index-only field (`index=match` with no `encrypt`) +An order index on bytes is refused: no ordering operator is answered over +bytes, so the term would be stored, where anyone who reads the column can +compare it, and no query could use it. A match index on an index-only field (`index=match` with no `encrypt`) is refused, because `Verify` checks a match query's rows by decrypting them. Every query type implements `driver.Valuer`, so it binds as a parameter in diff --git a/languages/golang/encrypt/exchange_conformance_test.go b/languages/golang/encrypt/exchange_conformance_test.go index b7de110eff..2d89e40f03 100644 --- a/languages/golang/encrypt/exchange_conformance_test.go +++ b/languages/golang/encrypt/exchange_conformance_test.go @@ -227,10 +227,8 @@ func exchangeOperator(t testing.TB, index string) string { // checkExchangeTerms checks that every stored term is the term this // runner's own query of the same value derives: the query semantics of the -// artifact, independent of who wrote it. An index the corpus lists as -// unanswered has no operator to compare with, so only its presence is -// checked. -func checkExchangeTerms(t testing.TB, ctx context.Context, cipher *encrypt.Cipher, plan *record.Plan, field string, stored exchangeStored, declared, unanswered []string, input any, equal *conformanceInput, what string) { +// artifact, independent of who wrote it. +func checkExchangeTerms(t testing.TB, ctx context.Context, cipher *encrypt.Cipher, plan *record.Plan, field string, stored exchangeStored, declared []string, input any, equal *conformanceInput, what string) { t.Helper() if len(stored.Terms) != len(declared)-1 { t.Fatalf("%s: stored %d terms for %v", what, len(stored.Terms), declared[1:]) @@ -240,13 +238,6 @@ func checkExchangeTerms(t testing.TB, ctx context.Context, cipher *encrypt.Ciphe if !ok { t.Fatalf("%s: no %s term", what, index) } - skip := false - for _, u := range unanswered { - skip = skip || u == index - } - if skip { - continue - } probes := []any{input} if index == "eq" && equal != nil { probes = append(probes, conformanceValue(t, *equal)) @@ -482,7 +473,7 @@ func consumeExchange(t testing.TB, ctx context.Context, cipher *encrypt.Cipher, t.Fatalf("%s: a SQL null stores no term", what) } } else { - checkExchangeTerms(t, ctx, cipher, plan, corpus.Values.Field, stored, c.Outputs, c.Unanswered, input, c.EqualQuery, what) + checkExchangeTerms(t, ctx, cipher, plan, corpus.Values.Field, stored, c.Outputs, input, c.EqualQuery, what) sealed[corpus.Values.Field] = exchangeOutputsOf(t, stored, what) } opened, err := cipher.Open(ctx, plan, []record.Sealed{sealed}) @@ -529,7 +520,7 @@ func consumeExchange(t testing.TB, ctx context.Context, cipher *encrypt.Cipher, } continue } - checkExchangeTerms(t, ctx, cipher, plan, f.Name, outputs, f.Outputs, nil, conformanceValue(t, input), nil, what+": "+f.Name) + checkExchangeTerms(t, ctx, cipher, plan, f.Name, outputs, f.Outputs, conformanceValue(t, input), nil, what+": "+f.Name) sealed[f.Name] = exchangeOutputsOf(t, outputs, what+": "+f.Name) } if len(stored.Passthrough) != passthroughs { diff --git a/languages/golang/encrypt/internal/testusers/probe_stash.go b/languages/golang/encrypt/internal/testusers/probe_stash.go index d308c0f20d..545483fc65 100644 --- a/languages/golang/encrypt/internal/testusers/probe_stash.go +++ b/languages/golang/encrypt/internal/testusers/probe_stash.go @@ -16,17 +16,11 @@ const _ = gensupport.GeneratedVersion2 // Probe prints its sealed fields in the clear: it has no String or LogValue // method. Write them, or run stashgen with -redact. -// B: stores ore terms that no generated method queries: the engine answers no -// query through the ore index on this field ([]byte): the orderings are -// answered over integers, floats, text, decimals, dates and timestamps only. -// Drop the index unless your own code compares the stored terms. - type EncryptedProbe struct { U32 EncryptedProbeU32 U64 EncryptedProbeU64 I64 EncryptedProbeI64 S EncryptedProbeS - B EncryptedProbeB F64 EncryptedProbeF64 F32 EncryptedProbeF32 } @@ -51,11 +45,6 @@ type EncryptedProbeS struct { Ore encrypt.OreTerm } -type EncryptedProbeB struct { - Ciphertext encrypt.Ciphertext - Ore encrypt.OreTerm -} - type EncryptedProbeF64 struct { Ciphertext encrypt.Ciphertext Ore encrypt.OreTerm @@ -67,11 +56,11 @@ type EncryptedProbeF32 struct { } func (e EncryptedProbe) String() string { - return gensupport.Redacted("EncryptedProbe", nil, "U32", "U64", "I64", "S", "B", "F64", "F32") + return gensupport.Redacted("EncryptedProbe", nil, "U32", "U64", "I64", "S", "F64", "F32") } func (e EncryptedProbe) LogValue() slog.Value { - return gensupport.RedactedLog(nil, "U32", "U64", "I64", "S", "B", "F64", "F32") + return gensupport.RedactedLog(nil, "U32", "U64", "I64", "S", "F64", "F32") } // Stops compiling when Probe gains, loses, reorders or retypes a field. @@ -83,7 +72,6 @@ type probeShape struct { U64 uint64 I64 int64 S string - B []byte F64 float64 F32 float32 } @@ -93,7 +81,6 @@ var probeDeclaration = gensupport.Declare("prop"). EncryptIndex("u64", gensupport.Uint64, encrypt.Ore). EncryptIndex("i64", gensupport.Int64, encrypt.Ore). EncryptIndex("s", gensupport.String, encrypt.Ore). - EncryptIndex("b", gensupport.Bytes, encrypt.Ore). EncryptIndex("f64", gensupport.Float64, encrypt.Ore). EncryptIndex("f32", gensupport.Float32, encrypt.Ore) @@ -107,7 +94,6 @@ var probeCodec = gensupport.New(gensupport.Generated[Probe, EncryptedProbe]{ "u64": v.U64, "i64": v.I64, "s": v.S, - "b": v.B, "f64": v.F64, "f32": v.F32, } @@ -130,10 +116,6 @@ var probeCodec = gensupport.New(gensupport.Generated[Probe, EncryptedProbe]{ Ciphertext: rec["s"].Ciphertext, Ore: rec["s"].Ore, } - e.B = EncryptedProbeB{ - Ciphertext: rec["b"].Ciphertext, - Ore: rec["b"].Ore, - } e.F64 = EncryptedProbeF64{ Ciphertext: rec["f64"].Ciphertext, Ore: rec["f64"].Ore, @@ -150,7 +132,6 @@ var probeCodec = gensupport.New(gensupport.Generated[Probe, EncryptedProbe]{ "u64": {Ciphertext: e.U64.Ciphertext, Ore: e.U64.Ore}, "i64": {Ciphertext: e.I64.Ciphertext, Ore: e.I64.Ore}, "s": {Ciphertext: e.S.Ciphertext, Ore: e.S.Ore}, - "b": {Ciphertext: e.B.Ciphertext, Ore: e.B.Ore}, "f64": {Ciphertext: e.F64.Ciphertext, Ore: e.F64.Ore}, "f32": {Ciphertext: e.F32.Ciphertext, Ore: e.F32.Ore}, } @@ -170,9 +151,6 @@ var probeCodec = gensupport.New(gensupport.Generated[Probe, EncryptedProbe]{ if v.S, err = gensupport.Get[string](vals, "s"); err != nil { return Probe{}, err } - if v.B, err = gensupport.Get[[]byte](vals, "b"); err != nil { - return Probe{}, err - } if v.F64, err = gensupport.Get[float64](vals, "f64"); err != nil { return Probe{}, err } @@ -201,7 +179,6 @@ var ProbeFields = struct { U64 ProbeU64Field I64 ProbeI64Field S ProbeSField - B ProbeBField F64 ProbeF64Field F32 ProbeF32Field }{ @@ -209,7 +186,6 @@ var ProbeFields = struct { U64: ProbeU64Field{gensupport.NewField[uint64](probeDeclaration, "u64")}, I64: ProbeI64Field{gensupport.NewField[int64](probeDeclaration, "i64")}, S: ProbeSField{gensupport.NewField[string](probeDeclaration, "s")}, - B: ProbeBField{gensupport.NewField[[]byte](probeDeclaration, "b")}, F64: ProbeF64Field{gensupport.NewField[float64](probeDeclaration, "f64")}, F32: ProbeF32Field{gensupport.NewField[float32](probeDeclaration, "f32")}, } @@ -362,18 +338,6 @@ func (f ProbeSField) Between(ctx context.Context, c *encrypt.Cipher, lo, hi stri return encrypt.Range[encrypt.OreTerm]{Low: low, High: high}, err } -type ProbeBField struct { - field gensupport.Field[[]byte] -} - -func (f ProbeBField) Encrypt(ctx context.Context, c *encrypt.Cipher, v []byte) (EncryptedProbeB, error) { - out, err := f.field.Encrypt(ctx, c, v) - if err != nil { - return EncryptedProbeB{}, err - } - return EncryptedProbeB{Ciphertext: out.Ciphertext, Ore: out.Ore}, nil -} - type ProbeF64Field struct { field gensupport.Field[float64] } diff --git a/languages/golang/encrypt/internal/testusers/probeope_stash.go b/languages/golang/encrypt/internal/testusers/probeope_stash.go index 56a7e2d82a..580706d833 100644 --- a/languages/golang/encrypt/internal/testusers/probeope_stash.go +++ b/languages/golang/encrypt/internal/testusers/probeope_stash.go @@ -16,17 +16,11 @@ const _ = gensupport.GeneratedVersion2 // ProbeOpe prints its sealed fields in the clear: it has no String or LogValue // method. Write them, or run stashgen with -redact. -// B: stores ope terms that no generated method queries: the engine answers no -// query through the ope index on this field ([]byte): the orderings are -// answered over integers, floats, text, decimals, dates and timestamps only. -// Drop the index unless your own code compares the stored terms. - type EncryptedProbeOpe struct { U32 EncryptedProbeOpeU32 U64 EncryptedProbeOpeU64 I64 EncryptedProbeOpeI64 S EncryptedProbeOpeS - B EncryptedProbeOpeB F64 EncryptedProbeOpeF64 F32 EncryptedProbeOpeF32 } @@ -51,11 +45,6 @@ type EncryptedProbeOpeS struct { Ope encrypt.OpeTerm } -type EncryptedProbeOpeB struct { - Ciphertext encrypt.Ciphertext - Ope encrypt.OpeTerm -} - type EncryptedProbeOpeF64 struct { Ciphertext encrypt.Ciphertext Ope encrypt.OpeTerm @@ -67,11 +56,11 @@ type EncryptedProbeOpeF32 struct { } func (e EncryptedProbeOpe) String() string { - return gensupport.Redacted("EncryptedProbeOpe", nil, "U32", "U64", "I64", "S", "B", "F64", "F32") + return gensupport.Redacted("EncryptedProbeOpe", nil, "U32", "U64", "I64", "S", "F64", "F32") } func (e EncryptedProbeOpe) LogValue() slog.Value { - return gensupport.RedactedLog(nil, "U32", "U64", "I64", "S", "B", "F64", "F32") + return gensupport.RedactedLog(nil, "U32", "U64", "I64", "S", "F64", "F32") } // Stops compiling when ProbeOpe gains, loses, reorders or retypes a field. @@ -83,7 +72,6 @@ type probeOpeShape struct { U64 uint64 I64 int64 S string - B []byte F64 float64 F32 float32 } @@ -93,7 +81,6 @@ var probeOpeDeclaration = gensupport.Declare("prop_ope"). EncryptIndex("u64", gensupport.Uint64, encrypt.Ope). EncryptIndex("i64", gensupport.Int64, encrypt.Ope). EncryptIndex("s", gensupport.String, encrypt.Ope). - EncryptIndex("b", gensupport.Bytes, encrypt.Ope). EncryptIndex("f64", gensupport.Float64, encrypt.Ope). EncryptIndex("f32", gensupport.Float32, encrypt.Ope) @@ -107,7 +94,6 @@ var probeOpeCodec = gensupport.New(gensupport.Generated[ProbeOpe, EncryptedProbe "u64": v.U64, "i64": v.I64, "s": v.S, - "b": v.B, "f64": v.F64, "f32": v.F32, } @@ -130,10 +116,6 @@ var probeOpeCodec = gensupport.New(gensupport.Generated[ProbeOpe, EncryptedProbe Ciphertext: rec["s"].Ciphertext, Ope: rec["s"].Ope, } - e.B = EncryptedProbeOpeB{ - Ciphertext: rec["b"].Ciphertext, - Ope: rec["b"].Ope, - } e.F64 = EncryptedProbeOpeF64{ Ciphertext: rec["f64"].Ciphertext, Ope: rec["f64"].Ope, @@ -150,7 +132,6 @@ var probeOpeCodec = gensupport.New(gensupport.Generated[ProbeOpe, EncryptedProbe "u64": {Ciphertext: e.U64.Ciphertext, Ope: e.U64.Ope}, "i64": {Ciphertext: e.I64.Ciphertext, Ope: e.I64.Ope}, "s": {Ciphertext: e.S.Ciphertext, Ope: e.S.Ope}, - "b": {Ciphertext: e.B.Ciphertext, Ope: e.B.Ope}, "f64": {Ciphertext: e.F64.Ciphertext, Ope: e.F64.Ope}, "f32": {Ciphertext: e.F32.Ciphertext, Ope: e.F32.Ope}, } @@ -170,9 +151,6 @@ var probeOpeCodec = gensupport.New(gensupport.Generated[ProbeOpe, EncryptedProbe if v.S, err = gensupport.Get[string](vals, "s"); err != nil { return ProbeOpe{}, err } - if v.B, err = gensupport.Get[[]byte](vals, "b"); err != nil { - return ProbeOpe{}, err - } if v.F64, err = gensupport.Get[float64](vals, "f64"); err != nil { return ProbeOpe{}, err } @@ -201,7 +179,6 @@ var ProbeOpeFields = struct { U64 ProbeOpeU64Field I64 ProbeOpeI64Field S ProbeOpeSField - B ProbeOpeBField F64 ProbeOpeF64Field F32 ProbeOpeF32Field }{ @@ -209,7 +186,6 @@ var ProbeOpeFields = struct { U64: ProbeOpeU64Field{gensupport.NewField[uint64](probeOpeDeclaration, "u64")}, I64: ProbeOpeI64Field{gensupport.NewField[int64](probeOpeDeclaration, "i64")}, S: ProbeOpeSField{gensupport.NewField[string](probeOpeDeclaration, "s")}, - B: ProbeOpeBField{gensupport.NewField[[]byte](probeOpeDeclaration, "b")}, F64: ProbeOpeF64Field{gensupport.NewField[float64](probeOpeDeclaration, "f64")}, F32: ProbeOpeF32Field{gensupport.NewField[float32](probeOpeDeclaration, "f32")}, } @@ -362,18 +338,6 @@ func (f ProbeOpeSField) Between(ctx context.Context, c *encrypt.Cipher, lo, hi s return encrypt.Range[encrypt.OpeTerm]{Low: low, High: high}, err } -type ProbeOpeBField struct { - field gensupport.Field[[]byte] -} - -func (f ProbeOpeBField) Encrypt(ctx context.Context, c *encrypt.Cipher, v []byte) (EncryptedProbeOpeB, error) { - out, err := f.field.Encrypt(ctx, c, v) - if err != nil { - return EncryptedProbeOpeB{}, err - } - return EncryptedProbeOpeB{Ciphertext: out.Ciphertext, Ope: out.Ope}, nil -} - type ProbeOpeF64Field struct { field gensupport.Field[float64] } diff --git a/languages/golang/encrypt/internal/testusers/users.go b/languages/golang/encrypt/internal/testusers/users.go index 183b82b73c..1e65e439a5 100644 --- a/languages/golang/encrypt/internal/testusers/users.go +++ b/languages/golang/encrypt/internal/testusers/users.go @@ -84,7 +84,6 @@ type Probe struct { U64 uint64 `stash:"u64,encrypt,index=ore"` I64 int64 `stash:"i64,encrypt,index=ore"` S string `stash:"s,encrypt,index=ore"` - B []byte `stash:"b,encrypt,index=ore"` F64 float64 `stash:"f64,encrypt,index=ore"` F32 float32 `stash:"f32,encrypt,index=ore"` } @@ -98,7 +97,6 @@ type ProbeOpe struct { U64 uint64 `stash:"u64,encrypt,index=ope"` I64 int64 `stash:"i64,encrypt,index=ope"` S string `stash:"s,encrypt,index=ope"` - B []byte `stash:"b,encrypt,index=ope"` F64 float64 `stash:"f64,encrypt,index=ope"` F32 float32 `stash:"f32,encrypt,index=ope"` } diff --git a/languages/golang/encrypt/order_test.go b/languages/golang/encrypt/order_test.go index d3ae18e4a2..59c0e93804 100644 --- a/languages/golang/encrypt/order_test.go +++ b/languages/golang/encrypt/order_test.go @@ -17,9 +17,8 @@ import ( // Property tests of term ordering: random plaintexts, the terms the guest // stores for them through the generated Probe and ProbeOpe fields' Encrypt, -// comparison in Go. A query method derives the same bytes, but only over -// integers, floats and text, so the stored terms reach every index and -// kind; a field declares one order index, so ORE and OPE are two records. ORE is +// comparison in Go. A field declares one order index, so ORE and OPE are +// two records. ORE is // probabilistic — a wrong comparator or a wrong derivation still agrees // with plaintext order on many pairs — so a fixed vector set says little; // hundreds of random pairs per type say more. The index key is the @@ -260,13 +259,6 @@ func TestTermOrderIsPlaintextOrder(t *testing.T) { values = append(values, math.SmallestNonzeroFloat32, -math.SmallestNonzeroFloat32, math.MaxFloat32) adjacentProperty(t, cipher, ope, d, values, floatOrder[float32]) }) - t.Run("bytes", func(t *testing.T) { - d := probeTerm(ope, - f.B.Encrypt, func(e testusers.EncryptedProbeB) []byte { return e.Ore }, - p.B.Encrypt, func(e testusers.EncryptedProbeOpeB) []byte { return e.Ope }) - orderProperty(t, cipher, ope, d, bytes.Compare) - adjacentProperty(t, cipher, ope, d, [][]byte{{}, {0}, {0, 0}, {0, 1}, {1}, {255}, {255, 0}}, bytes.Compare) - }) }) } } diff --git a/languages/golang/encrypt/value_conformance_test.go b/languages/golang/encrypt/value_conformance_test.go index 86c634bc23..f69ae275ae 100644 --- a/languages/golang/encrypt/value_conformance_test.go +++ b/languages/golang/encrypt/value_conformance_test.go @@ -8,7 +8,6 @@ import ( "math" "path/filepath" "reflect" - "slices" "testing" "time" @@ -26,7 +25,6 @@ type valueCase struct { Frame *string `json:"frame"` Companion *conformanceInput `json:"companion"` EqualQuery *conformanceInput `json:"equal_query"` - Unanswered []string `json:"unanswered"` ExpectedError *struct { Code string `json:"code"` Reason string `json:"reason"` @@ -122,13 +120,6 @@ func TestValueConformance(t *testing.T) { if !record.Kind(c.Kind).Known() || c.Kind == "" || len(c.Outputs) == 0 || c.Outputs[0] != "c" { t.Fatal("unsupported declaration") } - // An unanswered index must be one the case declares, or the - // entry checks nothing. - for _, u := range c.Unanswered { - if !slices.Contains(c.Outputs[1:], u) { - t.Fatalf("unanswered %s is not a declared index", u) - } - } isNull := c.Input.Type == "null" if (c.Frame == nil) != isNull { t.Fatal("a frame is frozen for every value, and for no null") @@ -183,14 +174,6 @@ func TestValueConformance(t *testing.T) { operator = "lt" } term, err := cipher.QueryTerm(ctx, plan, "value", operator, value) - unanswered := false - for _, u := range c.Unanswered { - unanswered = unanswered || u == o - } - if unanswered { - assertConformanceDiagnostic(t, err, "stack_encrypt::dynamic_source", "operator_not_answered", "value") - continue - } if err != nil || len(term.Terms) != 1 || !bytes.Equal(term.Terms[0], row.Terms[record.Output(o)]) { t.Fatalf("%s: stored/query term mismatch: %v", o, err) } diff --git a/languages/golang/stashgen/emit.go b/languages/golang/stashgen/emit.go index 2103e8fa60..83416222ea 100644 --- a/languages/golang/stashgen/emit.go +++ b/languages/golang/stashgen/emit.go @@ -795,61 +795,31 @@ func planQueries(f *genFile) error { } g.queries = append(g.queries, q) } - unqueried, err := indexesAnswer(g) - if err != nil { + if err := verifiable(g); err != nil { return fieldErr(f.typeName, g.GoName, "%v", err) } - for _, n := range unqueried { - f.notices = append(f.notices, g.GoName+": "+n) - f.unqueried = append(f.unqueried, fmt.Sprintf("stashgen: %s.%s: %s", f.typeName, g.GoName, n)) - } } return nil } -// indexesAnswer checks a field's indexes against the operators the engine -// answers on it. -// -// It refuses a probabilistic query on an index-only field: the query's rows -// are checked by decrypting them with Verify, and an index-only field -// stores no ciphertext, so Verify could never pass and every real match -// would be thrown away. +// verifiable refuses a probabilistic query on an index-only field: the +// query's rows are checked by decrypting them with Verify, and an +// index-only field stores no ciphertext, so Verify could never pass and +// every real match would be thrown away. // -// It returns a notice for each index the engine answers no operator -// through on the field: the index stores a term no generated method can -// query. That is an ore or ope index on bytes: the engine stores it and -// answers the orderings over integers, floats, text, decimals, dates and -// timestamps only. Storing it is allowed, since a program may compare the -// stored terms itself, but an order term tells anyone who reads the column -// how its values order, so the generator says so. A second order index -// beside the first is no longer a notice: the engine refuses a field that -// declares two indexes for one operator (overlapping_outputs), before any -// code is written. -func indexesAnswer(g *genField) ([]string, error) { - if g.Verb != VerbEncryptIndex && g.Verb != VerbIndex { - return nil, nil - } - answers := map[IndexName]string{} - for _, op := range g.operators { - if op.Probabilistic && g.Verb == VerbIndex { - return nil, fmt.Errorf("the %s index answers %s, whose rows are checked by decrypting them with Verify, and an index-only field stores no ciphertext to decrypt; seal it as well (encrypt,index=%s)", op.Index, op.Name, op.Index) - } - if _, ok := answers[op.Index]; !ok { - answers[op.Index] = op.Name - } +// Every index the engine admits on a field answers an operator there, so +// no index is stored that a generated method cannot query. The engine +// refuses the one that would be: an order index on bytes. +func verifiable(g *genField) error { + if g.Verb != VerbIndex { + return nil } - var notices []string - for _, ix := range g.Indexes { - if _, ok := answers[ix.Name]; ok { - continue - } - why := "" - if ix.Name == IndexOre || ix.Name == IndexOpe { - why = ": the orderings are answered over integers, floats, text, decimals, dates and timestamps only" + for _, op := range g.operators { + if op.Probabilistic { + return fmt.Errorf("the %s index answers %s, whose rows are checked by decrypting them with Verify, and an index-only field stores no ciphertext to decrypt; seal it as well (encrypt,index=%s)", op.Index, op.Name, op.Index) } - notices = append(notices, fmt.Sprintf("stores %s terms that no generated method queries: the engine answers no query through the %s index on this field (%s)%s. Drop the index unless your own code compares the stored terms.", ix.Name, ix.Name, g.valueExpr, why)) } - return notices, nil + return nil } func queryFor(g *genField, op Operator) (queryMethod, error) { diff --git a/languages/golang/stashgen/enginetest/enginetest.go b/languages/golang/stashgen/enginetest/enginetest.go index dc8d1e862c..60e51d97d7 100644 --- a/languages/golang/stashgen/enginetest/enginetest.go +++ b/languages/golang/stashgen/enginetest/enginetest.go @@ -262,10 +262,11 @@ func eightBit(t stashgen.GoType) bool { // every kind vitaminc gives an equality domain (integers of every width, // floats, decimals, dates, timestamps, text and bytes; a boolean has none), // match over text alone, ORE and OPE over integers of 16 bits and wider, -// floats, text, bytes, decimals, dates and timestamps. Not over a boolean -// or an 8-bit integer, whose order term would reveal which rows are true, -// or each row's rank among 256 values. The JSON index is not in the engine -// yet. +// floats, text, decimals, dates and timestamps. Not over a boolean or an +// 8-bit integer, whose order term would reveal which rows are true, or +// each row's rank among 256 values. Not over bytes, which no ordering +// operator is answered over: the term would be stored and never queried. +// The JSON index is not in the engine yet. func indexApplies(name stashgen.IndexName, t stashgen.GoType) error { switch name { case stashgen.IndexEquality: @@ -283,7 +284,7 @@ func indexApplies(name stashgen.IndexName, t stashgen.GoType) error { return fmt.Errorf("match applies to a string, not to %s", t) case stashgen.IndexOre, stashgen.IndexOpe, stashgen.IndexOreBlock: switch t.Kind { - case stashgen.KindString, stashgen.KindBytes, stashgen.KindFloat, + case stashgen.KindString, stashgen.KindFloat, stashgen.KindDecimal, stashgen.KindDate, stashgen.KindTimestamp: return nil } diff --git a/languages/golang/stashgen/read.go b/languages/golang/stashgen/read.go index 0750e7a11f..8b6131628f 100644 --- a/languages/golang/stashgen/read.go +++ b/languages/golang/stashgen/read.go @@ -58,7 +58,7 @@ type genFile struct { notices []string printsPlaintext bool unexported []string - unqueried []string // stderr notices about one field: an index no generated method queries, an array with no Elements accessor + unqueried []string // stderr notices about one field: an array with no Elements accessor redact bool redactRecv string diff --git a/languages/golang/stashgen/refusal_test.go b/languages/golang/stashgen/refusal_test.go index 332a5aa2e3..eeb6d1ab78 100644 --- a/languages/golang/stashgen/refusal_test.go +++ b/languages/golang/stashgen/refusal_test.go @@ -382,7 +382,9 @@ func TestRefusalsHoldAgainstTheEmbeddedEngine(t *testing.T) { {"every index on an integer", "\tScore int64 `stash:\"score,encrypt,index=equality;ore\"`\n\tRank int32 `stash:\"rank,index=ope\"`"}, {"two order indexes on an integer", "\tScore int64 `stash:\"score,encrypt,index=ore;ope\"`"}, {"orders on a decimal, a date and a timestamp", "\tAmount encrypt.Decimal `stash:\"amount,encrypt,index=equality;ore\"`\n\tDay encrypt.Date `stash:\"day,encrypt,index=ope\"`\n\tAt time.Time `stash:\"at,encrypt,index=equality;ore\"`"}, - {"orders on text, bytes and a float", "\tName string `stash:\"name,encrypt,index=ope;match\"`\n\tBlob []byte `stash:\"blob,encrypt,index=equality;ore\"`\n\tScore float64 `stash:\"score,encrypt,index=ore\"`"}, + {"orders on text and a float, equality on bytes", "\tName string `stash:\"name,encrypt,index=ope;match\"`\n\tBlob []byte `stash:\"blob,encrypt,index=equality\"`\n\tScore float64 `stash:\"score,encrypt,index=ore\"`"}, + {"ore on bytes", "\tBlob []byte `stash:\"blob,encrypt,index=equality;ore\"`"}, + {"ope on bytes", "\tBlob []byte `stash:\"blob,index=ope\"`"}, {"a match query on an index-only field", "\tName string `stash:\"name,index=match\"`"}, } { dir := writeModule(t, map[string]string{"model.go": user(ctx + c.line), "crm/contact.go": crmPackage}) @@ -425,32 +427,25 @@ func TestTheWholeDeclarationIsCheckedAgainstTheEmbeddedEngine(t *testing.T) { } } -// An index no generated method queries is stored, and the generator says -// so, on stderr and in the file: an order index on bytes. An order index on -// text, a float or an integer answers the orderings, so it gets methods and -// no notice. A second order index on one field is no notice: the engine -// refuses the declaration (`TestRefusalsHoldAgainstTheEmbeddedEngine`). -func TestAnIndexNoMethodQueriesGetsANotice(t *testing.T) { - src := user(ctx + "\tName string `stash:\"name,encrypt,index=match;ope\"`\n\tBlob []byte `stash:\"blob,encrypt,index=ope\"`\n\tScore float64 `stash:\"score,encrypt,index=ore\"`\n\tAge int64 `stash:\"age,encrypt,index=ore\"`\n\tRank int32 `stash:\"rank,encrypt,index=ope\"`") +// An order index on bytes is refused: no ordering operator is answered +// over bytes, so its term would be stored and never queried. An order index +// on text, a float or an integer answers the orderings, so it gets methods. +func TestAnOrderIndexOnBytesIsRefused(t *testing.T) { + for _, index := range []string{"ore", "ope", "equality;ore"} { + src := user(ctx + "\tBlob []byte `stash:\"blob,encrypt,index=" + index + "\"`") + _, err := generate(t, src, stashgen.Request{Type: "User"}) + var fe *stashgen.FieldError + if !errors.As(err, &fe) || fe.Field != "Blob" { + t.Errorf("index=%s on bytes: %v", index, err) + } + } + src := user(ctx + "\tName string `stash:\"name,encrypt,index=match;ope\"`\n\tBlob []byte `stash:\"blob,encrypt,index=equality\"`\n\tScore float64 `stash:\"score,encrypt,index=ore\"`") file, err := generate(t, src, stashgen.Request{Type: "User"}) if err != nil { t.Fatal(err) } - notices := strings.Join(file.Notices, "\n") - for _, want := range []string{ - "stashgen: User.Blob: stores ope terms that no generated method queries", - } { - if !strings.Contains(notices, want) { - t.Errorf("notices lack %q:\n%s", want, notices) - } - } - for _, field := range []string{"User.Name", "User.Rank", "User.Score", "User.Age"} { - if strings.Contains(notices, field) { - t.Errorf("an order index that answers the orderings got a notice (%s):\n%s", field, notices) - } - } - if !strings.Contains(string(file.Content), "// Blob: stores ope terms that no generated method queries") { - t.Errorf("the file does not carry the notice:\n%s", file.Content) + if notices := strings.Join(file.Notices, "\n"); strings.Contains(notices, "no generated method queries") { + t.Errorf("an index every field can query got a notice:\n%s", notices) } if !strings.Contains(string(file.Content), "func (f NameField) Lt(") { t.Errorf("a text field with ope has no Lt:\n%s", file.Content) @@ -458,6 +453,9 @@ func TestAnIndexNoMethodQueriesGetsANotice(t *testing.T) { if !strings.Contains(string(file.Content), "func (f ScoreField) Between(") { t.Errorf("a float field with ore has no Between:\n%s", file.Content) } + if !strings.Contains(string(file.Content), "func (f BlobField) Eq(") { + t.Errorf("a bytes field with equality has no Eq:\n%s", file.Content) + } } // The storage profile writes a struct with no fields at all as an empty diff --git a/packages/stack-encrypt/CHANGELOG.md b/packages/stack-encrypt/CHANGELOG.md index 81e3730722..d7ff983a6f 100644 --- a/packages/stack-encrypt/CHANGELOG.md +++ b/packages/stack-encrypt/CHANGELOG.md @@ -766,6 +766,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 convert it: `P::decrypt_from_with_context(record, &cipher, expected)`. For no check, `P::decrypt_from(record, &cipher)` also works. +- **A data plan refuses an order index on bytes** (#1577). + `dynamic::admits` no longer admits `ore`, `ope` or `ore_block` on a + `bytes` field, so `record::plan` refuses the declaration with + `index_not_admitted`. Go reaches the same check through the guest. + Before, the declaration was accepted, each row stored an order term + that anyone who held two rows could compare, and every ordering query + was refused as `operator_not_answered`. + - To upgrade, remove the index from the plan. A row stored with the + term still opens under the new plan: opening ignores a stored term, + and an index-only field, that the plan does not declare. The stored + terms stay in the database until the row is written again. + - The dynamic path no longer derives an order term of bytes, as the + typed path does not. `IndexSpec::defines` reports no order term for + bytes, and `dynamic::term` refuses one. + - The conformance corpus follows. In `record-declarations-v1` the + cases `type-bytes-ore`, `type-bytes-ope` and `type-bytes-ore_block` + are now refused. `record-values-v1` no longer has an `unanswered` + list. In `record-query-refusals-v1` the bytes field declares + equality alone, and the six `*-on-bytes-order-index` cases are + renamed `*-on-bytes`. + - `tests/fixtures/stored_rows_v1.json` is not changed. Its `every_kind` + plan declares an order index on two bytes fields. The test now opens + those rows under the plan with the indexes removed. + - **`CipherRef` replaces `target::CipherScope` and `dynamic::Scope`** (#1488). A `CipherRef` is one borrowed value: a connection, and the keyset it is confined to, if any. It is built from `&StackCipher`, diff --git a/packages/stack-encrypt/src/dynamic/kind.rs b/packages/stack-encrypt/src/dynamic/kind.rs index 2c74527e9c..9366a05e13 100644 --- a/packages/stack-encrypt/src/dynamic/kind.rs +++ b/packages/stack-encrypt/src/dynamic/kind.rs @@ -56,12 +56,20 @@ use crate::target::IndexSpec; /// of every width, both floats, a decimal, a date, a timestamp, text and /// bytes, and not a boolean. The rest are this crate's: match over text /// alone, and ORE, OPE and block ORE over the integers of 16 bits and -/// wider, both floats, text, bytes, a decimal, a date and a timestamp. A +/// wider, both floats, text, a decimal, a date and a timestamp. A /// boolean and an 8-bit integer have no order term: over so small a domain /// it would reveal which rows are `true`, or each row's rank among 256 /// values. A composite (`array`, `object`) has no term. Only the index's /// kind matters: a match index's options do not change what it applies to. /// +/// Bytes are the one kind an index is refused though the scheme defines +/// its term. [`IndexSpec::defines`] takes bytes for an order index, but no +/// ordering operator is answered over bytes, so a plan that declared one +/// would store a term anyone can compare and no query can use. A plan +/// admits an index only over a kind one of the index's operators answers, +/// as the typed path's `Index` bound on [`op::Ordered`](crate::op::Ordered) +/// does. +/// /// ``` /// use stack_encrypt::dynamic::{admits, ValueKind}; /// use stack_encrypt::target::IndexSpec; @@ -75,9 +83,13 @@ use crate::target::IndexSpec; /// assert!(!admits(ValueKind::Bool, &IndexSpec::Equality)); /// assert!(!admits(ValueKind::Bool, &IndexSpec::Ore)); /// assert!(!admits(ValueKind::Object, &IndexSpec::Ore)); +/// assert!(admits(ValueKind::Bytes, &IndexSpec::Equality)); +/// assert!(!admits(ValueKind::Bytes, &IndexSpec::Ore)); /// ``` pub fn admits(kind: ValueKind, index: &IndexSpec) -> bool { - scalar_of(kind).is_some_and(|(ty, scalar)| index.takes(ty, &scalar)) + let unanswered = kind == ValueKind::Bytes + && matches!(index, IndexSpec::Ore | IndexSpec::Ope | IndexSpec::OreBlock); + !unanswered && scalar_of(kind).is_some_and(|(ty, scalar)| index.takes(ty, &scalar)) } /// Why `kind` does not admit `index`, or `None` when it does: the reason a @@ -687,10 +699,20 @@ mod tests { /// `admits` is `IndexSpec::defines` stated over kinds: the two cannot /// disagree about a value of any kind, and a composite admits nothing. + /// The one exception is an order index on bytes, whose term the scheme + /// defines and no operator answers: a plan does not admit it. #[test] fn admits_agrees_with_defines_for_every_kind() { for kind in value_kinds() { for index in indexes() { + let order = matches!(index, IndexSpec::Ore | IndexSpec::Ope | IndexSpec::OreBlock); + if kind == ValueKind::Bytes && order { + assert_eq!( + not_admitted(kind, &index), + Some(Reason::IndexNotAdmitted), + "bytes and {index}" + ); + } assert_eq!( admits(kind, &index), index.defines(sample(kind)), @@ -698,6 +720,8 @@ mod tests { ); } } + // Every other index bytes can hold is still admitted. + assert!(admits(ValueKind::Bytes, &IndexSpec::Equality)); // Spelled out, so the table reads without the cross-check. assert!(admits(ValueKind::UInt64, &IndexSpec::Equality)); assert!(admits(ValueKind::Float64, &IndexSpec::Equality)); diff --git a/packages/stack-encrypt/src/dynamic/query.rs b/packages/stack-encrypt/src/dynamic/query.rs index 1d35db374a..ff01abb644 100644 --- a/packages/stack-encrypt/src/dynamic/query.rs +++ b/packages/stack-encrypt/src/dynamic/query.rs @@ -189,12 +189,8 @@ impl Op { // answers is the one. A document field's JSON index answers the // document operators over a document alone; every other index // answers over the kinds it is defined for. - // An order index over bytes stores a term and answers no ordering: - // the orderings are answered over the integers, the floats, text, - // decimals, dates and timestamps. - if self.is_ordering() && !ordered(kind) { - return None; - } + // `admits` refuses an order index over bytes, the one kind with an + // order term and no ordering, so no ordering is answered there. indexes.iter().find(|index| { index.answers(self) && match index { @@ -203,38 +199,6 @@ impl Op { } }) } - - /// Whether this is an ordering operator over a scalar: `lt`, `lte`, - /// `gt`, `gte` or `between`. - fn is_ordering(self) -> bool { - matches!(self, Op::Lt | Op::Lte | Op::Gt | Op::Gte | Op::Between) - } -} - -/// The kinds the ordering operators are answered over: the integers of 16 -/// bits and wider, `int16` to `uint128`, the floats, text, and dates, -/// timestamps and decimals, as [`Orderable`](crate::Orderable) covers -/// them in the typed path. Not `int8` or `uint8`, which have no order term. -/// Each orders by its order key; a `float32` is ordered as the -/// `f64` it widens to, as the typed path asks. -fn ordered(kind: ValueKind) -> bool { - matches!( - kind, - ValueKind::Int16 - | ValueKind::Int32 - | ValueKind::Int64 - | ValueKind::Int128 - | ValueKind::UInt16 - | ValueKind::UInt32 - | ValueKind::UInt64 - | ValueKind::UInt128 - | ValueKind::Float32 - | ValueKind::Float64 - | ValueKind::String - | ValueKind::Decimal - | ValueKind::Date - | ValueKind::Timestamp - ) } /// How far the server's answer to an operator can be trusted, as a catalog diff --git a/packages/stack-encrypt/src/dynamic/term.rs b/packages/stack-encrypt/src/dynamic/term.rs index 1cc48a154d..af96b53b74 100644 --- a/packages/stack-encrypt/src/dynamic/term.rs +++ b/packages/stack-encrypt/src/dynamic/term.rs @@ -16,7 +16,7 @@ //! a domain of its own. A boolean has none. //! - **Match** takes text only, cut in Unicode 16 NFC. //! - **ORE, OPE and block ORE** take an integer of 16 bits or wider, a -//! float, text, bytes, a date, a timestamp or a decimal, each handed to +//! float, text, a date, a timestamp or a decimal, each handed to //! clww-ore (ORE, OPE) or ore-rs (block ORE) as the Rust type the typed //! path would have named: an `i16` as an `i16`, a `u128` as a `u128`, a //! date as a [`value::Date`](crate::value::Date). A boolean, a `u8` and an @@ -142,7 +142,7 @@ impl IndexSpec { /// gives an equality domain (an integer, a float, text, bytes, a date, /// timestamp, decimal or uuid, and a null), not a boolean. Match /// takes text. ORE, OPE and block ORE take an integer of 16 bits or - /// wider, a float, text, bytes, a date, a timestamp or a decimal; not a + /// wider, a float, text, a date, a timestamp or a decimal; not bytes, a /// boolean, an 8-bit integer or a uuid. A match index's options do not /// change what it takes. /// @@ -191,8 +191,9 @@ impl IndexSpec { } /// Whether the order indexes (CLLW ORE and OPE, and block ORE) order this -/// scalar: an integer of 16 bits or wider, a float, text, bytes, or a date, -/// timestamp or decimal in range. Not a boolean, and not an 8-bit integer: +/// scalar: an integer of 16 bits or wider, a float, text, or a date, +/// timestamp or decimal in range. Not bytes, which no ordering operator +/// compares. Not a boolean, and not an 8-bit integer: /// an order term over so small a domain reveals too much, which rows hold /// `true`, or each row's rank among 256 values, which a few known rows /// resolve to the values. Not a null, and not a uuid or any other logical @@ -201,7 +202,10 @@ fn ordered(ty: Option, value: &Physical<'_>) -> bool { match ty { None => match value { Physical::Int(Int::I8(_) | Int::U8(_)) | Physical::Null | Physical::Bool(_) => false, - Physical::Int(_) | Physical::Float(_) | Physical::Text(_) | Physical::Bytes(_) => true, + Physical::Int(_) | Physical::Float(_) | Physical::Text(_) => true, + // No ordering operator compares bytes, so an order term of + // them answers no query and reveals the order of the rows. + Physical::Bytes(_) => false, }, Some(Logical::Date) => Date::from_scalar(ty, *value).is_some(), Some(Logical::Timestamp(_)) => Timestamp::from_scalar(ty, *value).is_some(), @@ -642,10 +646,10 @@ enum OrderIndex { /// Rust type the typed path would have named; `None` for a scalar it does /// not order ([`ordered`]). /// -/// Text and bytes are read where the walk holds them, and not copied: -/// each term makes the scalar's order encoding first, under `Protected`, -/// so nothing is freed with the plaintext still in it, in a guest's linear -/// memory, where the host can read it. +/// Text is read where the walk holds it, and not copied: each term makes +/// the scalar's order encoding first, under `Protected`, so nothing is +/// freed with the plaintext still in it, in a guest's linear memory, where +/// the host can read it. /// /// Each scalar is encoded at the target of the Rust type named here /// ([`Orderable`]), as on the typed path: text by its case and accent @@ -697,7 +701,6 @@ where Physical::Float(Float::F32(v)) => order(cipher, index, v, context), Physical::Float(Float::F64(v)) => order(cipher, index, v, context), Physical::Text(t) => order(cipher, index, t, context), - Physical::Bytes(b) => order_at(cipher, index, OrderTarget::Bytes, b, context), _ => return None, }) } @@ -720,11 +723,6 @@ where /// The term of `value` under `index`, encoded as `target`. The term's /// bytes are its frozen encoding: the raw CLLW ciphertext, or the /// serialised block ORE one. -/// -/// Bytes are not [`Orderable`]: no ordering operator compares them, so the -/// typed path has no order term of bytes. A data plan can still declare an -/// order index on bytes, and the rows it stored carry the term, so this path -/// derives it as it did, by naming the `Bytes` target. fn order_at<'a, 'c, K: 'static, V, D>( cipher: &'a KeysetCipher<'_, K>, index: OrderIndex, @@ -1546,16 +1544,17 @@ mod tests { fn defines_is_true() { for (label, leaf) in every_scalar() { let not_bool = !matches!(leaf, Tree::Bool(_)); - let wide = not_bool && !matches!(leaf, Tree::Int8(_) | Tree::UInt8(_)); + let wide = + not_bool && !matches!(leaf, Tree::Int8(_) | Tree::UInt8(_) | Tree::Bytes(_)); assert_eq!( IndexSpec::Ore.defines(&leaf), wide, - "{label} takes an ore term exactly when it is not a boolean or 8 bits wide" + "{label} takes an ore term exactly when it is not a boolean, bytes or 8 bits wide" ); assert_eq!( IndexSpec::Ope.defines(&leaf), wide, - "{label} takes an ope term exactly when it is not a boolean or 8 bits wide" + "{label} takes an ope term exactly when it is not a boolean, bytes or 8 bits wide" ); assert_eq!( IndexSpec::Equality.defines(&leaf), diff --git a/packages/stack-encrypt/tests/exchange_conformance.rs b/packages/stack-encrypt/tests/exchange_conformance.rs index 3581049b65..c044b9dd4e 100644 --- a/packages/stack-encrypt/tests/exchange_conformance.rs +++ b/packages/stack-encrypt/tests/exchange_conformance.rs @@ -133,8 +133,6 @@ struct ValueCase { frame: Option, companion: Option, equal_query: Option, - #[serde(default)] - unanswered: Vec, expected_error: Option, } @@ -382,8 +380,6 @@ struct Terms<'a> { field: &'a str, /// The field's declared outputs, `c` first. declared: &'a [String], - /// Stored indexes no operator answers: present, and not queried. - unanswered: &'a [String], input: &'a Input, /// Another spelling whose equality query derives the same term. equal_query: Option<&'a Input>, @@ -391,8 +387,7 @@ struct Terms<'a> { /// Every stored term is the term this runner's own query of the same value /// derives: the query semantics of the artifact, independent of who wrote -/// it. An index the corpus lists as unanswered has no operator to compare -/// with, so only its presence is checked. +/// it. async fn check_terms( keyset: &KeysetCipher<'_, common::DeterministicSource>, terms: Terms<'_>, @@ -403,9 +398,6 @@ async fn check_terms( let present: BTreeSet<_> = stored.terms.keys().map(String::as_str).collect(); assert_eq!(present, declared, "{what}: stores every declared index"); for (index, term) in &stored.terms { - if terms.unanswered.contains(index) { - continue; - } let mut probes = vec![terms.input]; if index == "eq" { probes.extend(terms.equal_query); @@ -649,7 +641,6 @@ async fn consume( plan: &plan, field: &corpus.values.field, declared: &case.outputs, - unanswered: &case.unanswered, input: &case.input, equal_query: case.equal_query.as_ref(), }, @@ -694,7 +685,6 @@ async fn consume( plan: &plan, field: &field.name, declared: &field.outputs, - unanswered: &[], input, equal_query: None, }, diff --git a/packages/stack-encrypt/tests/fixtures/README.md b/packages/stack-encrypt/tests/fixtures/README.md index 9b961e1f2e..240ef2057b 100644 --- a/packages/stack-encrypt/tests/fixtures/README.md +++ b/packages/stack-encrypt/tests/fixtures/README.md @@ -219,6 +219,14 @@ of being regenerated away. sealed leaves (which carry a fresh nonce): the same shape and map keys in order, the same terms and the same passthroughs. +One declaration in the file is no longer accepted: an order index on a +`bytes` field (`blob` with `ore`, and the index-only `blob_ope`, in +`every_kind`). The file keeps it, because it records what was stored. The +test removes those indexes from the plan before it builds it, as a user +whose plan declared one must. It opens each row as stored, retired terms +included, under that plan. It seals the source again and compares the two +trees without the retired terms and without `blob_ope`. + Nothing reads `STACK_ENCRYPT_UPDATE_FIXTURES` for this file. The one test that creates it, `write_stored_rows_v1`, is `#[ignore]`d and refuses to run when the file exists. The check rewrites it only under diff --git a/packages/stack-encrypt/tests/stored_rows.rs b/packages/stack-encrypt/tests/stored_rows.rs index b36e4a680d..cd7ece618d 100644 --- a/packages/stack-encrypt/tests/stored_rows.rs +++ b/packages/stack-encrypt/tests/stored_rows.rs @@ -20,6 +20,10 @@ //! `STACK_ENCRYPT_REFREEZE_ORDER_TERMS=1`. That run asserts nothing else //! moved before it rewrites anything. //! +//! One declaration the file records is no longer accepted: an order index +//! on a `bytes` field. The file keeps it, and the check opens the rows +//! under the plan with those indexes removed ([`todays_plan`]). +//! //! The schema and the rules are in `tests/fixtures/README.md`. #![cfg(feature = "dynamic")] @@ -187,8 +191,86 @@ fn without_order_terms(json: &Json) -> Json { } } -/// Copy every order term of `resealed` over the one in the same place in -/// `stored`. The two have the same shape, which the caller has asserted. +/// The outputs a frozen plan declares that no build admits any more: an +/// order index on a `bytes` field. The plan the rows were stored under +/// declares two (`blob` with `ore`, and the index-only `blob_ope`); a +/// declaration now refuses them, because no ordering is answered over +/// bytes. +const RETIRED_ON_BYTES: [&str; 3] = ["ore", "ope", "ore_block"]; + +/// Whether `output` of a field of the frozen plan is retired. +fn retired(field: &Json, output: &Json) -> bool { + field.get("type") == Some(&json!("bytes")) + && output + .as_str() + .is_some_and(|o| RETIRED_ON_BYTES.contains(&o)) +} + +/// Whether every output of a field of the frozen plan is retired: the field +/// held an order term on bytes and nothing else. +fn emptied(field: &Json) -> bool { + field + .get("outputs") + .and_then(Json::as_array) + .is_some_and(|outputs| outputs.iter().all(|output| retired(field, output))) +} + +/// The frozen plan as a build declares it today: without an order index on +/// a `bytes` field. This is what a user whose plan declared one does: +/// remove the index. The rows stored under the old declaration must still +/// open under this one. +/// +/// A field left with no output is removed, which is the plan the rows are +/// opened under. With `holding_source`, it is kept as ciphertext instead: +/// the frozen source still carries that field's value, and sealing refuses +/// a source field the plan does not declare. +fn todays_plan(frozen: &Json, holding_source: bool) -> Json { + let mut plan = frozen.clone(); + let fields = plan.as_object_mut().expect("a plan is an object"); + fields.retain(|_, field| { + if !field.is_object() || field.get("type") != Some(&json!("bytes")) { + return true; + } + let was = field.clone(); + let outputs = field["outputs"].as_array_mut().expect("outputs"); + outputs.retain(|output| !retired(&was, output)); + if outputs.is_empty() && holding_source { + outputs.push(json!("c")); + } + !outputs.is_empty() + }); + plan +} + +/// A row without what the frozen plan's retired indexes stored: the order +/// terms of its `bytes` fields, and each field that held nothing else. +fn without_retired(row: &Json, frozen_plan: &Json) -> Json { + // A batch is stored as a sequence of rows. + if let Some(rows) = row.get("seq").and_then(Json::as_array) { + let rows: Vec = rows + .iter() + .map(|row| without_retired(row, frozen_plan)) + .collect(); + return json!({ "seq": rows }); + } + let mut row = row.clone(); + let fields = row["map"].as_array_mut().expect("a row is a map"); + fields.retain_mut(|pair| { + let field = &frozen_plan[pair[0].as_str().expect("a key")]; + if emptied(field) { + return false; + } + if let Some(outputs) = pair[1].get_mut("map").and_then(Json::as_array_mut) { + outputs.retain(|output| !retired(field, &output[0])); + } + true + }); + row +} + +/// Copy every order term of `resealed` over the one under the same key in +/// `stored`. An entry of `stored` that `resealed` does not hold (a retired +/// term) stays as it was frozen. fn refreeze_order_terms(stored: &mut Json, resealed: &Json) { let Some(object) = stored.as_object_mut() else { return; @@ -203,11 +285,15 @@ fn refreeze_order_terms(stored: &mut Json, resealed: &Json) { } } "map" => { - for (index, pair) in value.as_array_mut().expect("a list").iter_mut().enumerate() { + let theirs = theirs.as_array().expect("a list"); + for pair in value.as_array_mut().expect("a list") { + let Some(their) = theirs.iter().find(|their| their[0] == pair[0]) else { + continue; + }; if is_order_term(pair) { - pair[1] = theirs[index][1].clone(); + pair[1] = their[1].clone(); } else { - refreeze_order_terms(&mut pair[1], &theirs[index][1]); + refreeze_order_terms(&mut pair[1], &their[1]); } } } @@ -290,13 +376,21 @@ async fn every_frozen_row_opens_and_seals_as_it_did() { "the deterministic source names the keyset it named" ); - let cases = fixture["cases"].as_array_mut().expect("a list of cases"); - assert!(!cases.is_empty()); - for case in cases { + let frozen = fixture["cases"].as_array_mut().expect("a list of cases"); + assert!(!frozen.is_empty()); + for case in frozen { let name = case["name"].as_str().expect("a name"); - let plan = plan_of(&case["plan"]); + // The row is opened as it was frozen, retired order terms and all, + // under the plan a build accepts today: opening ignores a stored + // term, and an index-only field, the plan does not declare. + let plan = plan_of(&todays_plan(&case["plan"], false)); + // The frozen source is sealed again under the same plan, with a + // field that lost its last index held as ciphertext so the source + // still fits. Neither side of the comparison keeps that field. + let sealing = plan_of(&todays_plan(&case["plan"], true)); let source = Protected::new(unhex(case["source"].as_str().expect("hex"))); let stored = &case["stored"]; + let kept = without_retired(stored, &case["plan"]); let opened = open(&cipher, node_of_json(stored), &plan, expected_of(case)).await; assert_eq!( @@ -305,11 +399,13 @@ async fn every_frozen_row_opens_and_seals_as_it_did() { "{name}: the frozen row opens to what it opened to" ); - let resealed = - json_of_node(seal(&cipher, source.as_protected_ref().as_deref(), &plan).await); + let resealed = without_retired( + &json_of_node(seal(&cipher, source.as_protected_ref().as_deref(), &sealing).await), + &case["plan"], + ); assert_eq!( without_order_terms(&resealed), - without_order_terms(stored), + without_order_terms(&kept), "{name}: sealing the source today stores the same shape, terms and passthroughs" ); if refreeze { @@ -317,7 +413,7 @@ async fn every_frozen_row_opens_and_seals_as_it_did() { } else { assert_eq!( skeleton(&resealed), - skeleton(stored), + skeleton(&kept), "{name}: only ORE or OPE terms moved. If that is deliberate, re-freeze them \ with STACK_ENCRYPT_REFREEZE_ORDER_TERMS=1 and say so in the CHANGELOG \ (tests/fixtures/README.md)" diff --git a/packages/stack-encrypt/tests/value_conformance.rs b/packages/stack-encrypt/tests/value_conformance.rs index d63d0fe36f..506e886a3f 100644 --- a/packages/stack-encrypt/tests/value_conformance.rs +++ b/packages/stack-encrypt/tests/value_conformance.rs @@ -77,10 +77,6 @@ struct Case { companion: Option, /// Another spelling whose equality query must derive the stored term. equal_query: Option, - /// Stored indexes no query operator answers for this kind: the term is - /// stored, and a query of it is refused as `operator_not_answered`. - #[serde(default)] - unanswered: Vec, expected_error: Option, } @@ -170,15 +166,6 @@ async fn shared_record_value_profile() { assert!(KINDS[..18].contains(&case.kind.as_str()), "{}", case.id); assert!(KINDS.contains(&case.input.kind.as_str()), "{}", case.id); assert!(!case.outputs.is_empty() && case.outputs[0] == "c"); - // An unanswered index must be one the case declares, or the entry - // checks nothing. - for index in &case.unanswered { - assert!( - case.outputs[1..].contains(index), - "{}: unanswered {index} is not a declared index", - case.id - ); - } let is_null = case.input.kind == "null"; assert_eq!(case.frame.is_none(), is_null, "{}: frame", case.id); let mut spec = json!({"context": ["conformance", "value"], "outputs": case.outputs, "type": case.kind}); @@ -262,25 +249,6 @@ async fn shared_record_value_profile() { "ore" | "ope" => Op::Lt, other => panic!("{other}"), }; - if case.unanswered.contains(index) { - let error = dynamic::query_term( - &keyset, - &plan, - "value", - operator, - value(target), - &NoTargets, - ) - .err() - .expect("an unanswered index is refused before any term"); - refusal( - &error, - "stack_encrypt::dynamic_source", - "operator_not_answered", - "value", - ); - continue; - } queried.push((target.clone(), operator, term.clone())); } if output == 0 { From 78dc15b5d4b31842b73de2f5af493a5d749cdc11 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Wed, 11 Nov 2026 00:13:04 +1000 Subject: [PATCH 2/4] fix(stack-encrypt): address the review of the bytes order refusal The engine change in the previous commit was sound. The review found text and tests that still described the old rule, or that no longer checked anything. - The declaration grammar's admission table said bytes admit `ore`, `ope` and `ore_block`. A runner written from it would admit a declaration the corpus refuses. The table now refuses them, and says why. - `coverage.md` listed the order index on bytes as a combination the corpora record. They no longer do. - The Go CHANGELOG named `index=ore_block` as a tag that is now refused. It is not a tag word, and stashgen refused it before this change. Only a hand-built plan with an `ore_block` output on bytes is newly refused. - The rustdoc for `Reason::IndexNotAdmitted` and `FieldPlan::with_type` lists the refused pairs. It now names an order index on bytes. - A stashgen test checked that no notice held a text the generator no longer writes, so it could not fail. It now checks that no notice names one of the test's fields. - The Go fake engine kept its own list of the kinds the orderings are answered over, beside `indexApplies`. That is the second list the previous commit removed from the engine. `answeredBy` now reads `indexApplies` alone, and the unused `logical` helper is removed. --- conformance/stack-encrypt/coverage.md | 7 ++++--- .../stack-encrypt/declaration-grammar.md | 7 ++++++- languages/golang/CHANGELOG.md | 7 ++++--- .../golang/stashgen/enginetest/enginetest.go | 21 ++++--------------- languages/golang/stashgen/refusal_test.go | 8 +++++-- packages/stack-encrypt/src/dynamic/record.rs | 4 ++-- packages/stack-encrypt/src/refusal.rs | 3 ++- 7 files changed, 28 insertions(+), 29 deletions(-) diff --git a/conformance/stack-encrypt/coverage.md b/conformance/stack-encrypt/coverage.md index 10377adab7..1e37e9df02 100644 --- a/conformance/stack-encrypt/coverage.md +++ b/conformance/stack-encrypt/coverage.md @@ -144,9 +144,10 @@ Each runs in native Rust and Go WASI under `test:conformance`. | Native `a_stored_record_that_does_not_fit`, the read profile | `shape-*`, `authenticated-*`, `success-*` | Mutation vocabulary over real ciphertext | | Guest `test_frame` and `last_error` tests | `transport-*`, `leaf-*` | Plan-frame boundary cases, ABI status mapping | -Unsupported combinations the corpora record rather than skip: the order -index on `bytes` stores a term no operator reads; a repeated key in a stored record is -a transport refusal in both decoders, and the engine's own `field_repeated` +Unsupported combinations the corpora record rather than skip: the typed +chain refuses equality, order and block ORE value refusals only after its +keyset loads, where the binding refuses before any; a repeated key in a +stored record is a transport refusal in both decoders, and the engine's own `field_repeated` and `repeated_key` guards are reached natively alone; the Go host refuses the zero `Date`, a decimal scale above 28, a timestamp outside the decoder's range and non-value Go types before the engine. `NaN` and diff --git a/conformance/stack-encrypt/declaration-grammar.md b/conformance/stack-encrypt/declaration-grammar.md index 12e59eacf8..6d82a08e72 100644 --- a/conformance/stack-encrypt/declaration-grammar.md +++ b/conformance/stack-encrypt/declaration-grammar.md @@ -176,9 +176,14 @@ select a different leaf encoding. | Other integer widths | Admitted | Refused | Admitted | | float32, float64, decimal, date, timestamp | Admitted | Refused | Admitted | | string | Admitted | Admitted | Admitted | -| bytes | Admitted | Refused | Admitted | +| bytes | Admitted | Refused | Refused | | array, object, json | Refused | Refused | Refused | +An index is admitted only over a kind one of its operators answers. The +scheme defines an order term for bytes, but no ordering operator is answered +over bytes, so the term would be stored and never queried. The order indexes +are refused on bytes as `index_not_admitted`. + The corpus explicitly tests all 21 kinds against all five scalar indexes. `array` and `object` may still be sealed without indexes. A `json` field requires a document target. A raw `json` output has a recognized syntax but is refused as diff --git a/languages/golang/CHANGELOG.md b/languages/golang/CHANGELOG.md index 28404aaddd..df5a597f26 100644 --- a/languages/golang/CHANGELOG.md +++ b/languages/golang/CHANGELOG.md @@ -37,9 +37,10 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit. the column with the release you run now, or check its plaintext source. - **An order index on bytes is refused** (#1577). A `[]byte` field tagged - `index=ore`, `index=ope` or `index=ore_block` is now a field error from - `stashgen`, and a plan built by hand with one is refused by the guest - (`index_not_admitted`) before any key is requested. No ordering operator + `index=ore` or `index=ope` is now a field error from `stashgen`. A plan + built by hand with an `ore`, `ope` or `ore_block` output on a `bytes` + field is refused by the guest (`index_not_admitted`) before any key is + requested. No ordering operator is answered over bytes, so the field stored an order term that anyone who read the column could compare and that no query could use. `stashgen`'s notice for an index no generated method queries is gone diff --git a/languages/golang/stashgen/enginetest/enginetest.go b/languages/golang/stashgen/enginetest/enginetest.go index 60e51d97d7..aef3d1d785 100644 --- a/languages/golang/stashgen/enginetest/enginetest.go +++ b/languages/golang/stashgen/enginetest/enginetest.go @@ -199,9 +199,10 @@ func (e Static) operators(ctx context.Context, d stashgen.Declaration) (map[stri // answeredBy mirrors Op::answered_by in stack-encrypt: eq through an // equality index, matches through a match index, and the orderings through // the one order index the field declares (ORE, block ORE or OPE; check -// refused a field with two), over an integer of 16 bits or wider, a float, -// text, a decimal, a date or a timestamp; each only where the index applies -// to the type. +// refused a field with two); each only where the index applies to the type +// (indexApplies). There is no second list of the types the orderings are +// answered over: an index that applies answers its operators, as in the +// engine. func answeredBy(operator string, t stashgen.GoType, indexes []stashgen.IndexName) (stashgen.IndexName, bool) { declared := func(want stashgen.IndexName) bool { for _, idx := range indexes { @@ -217,11 +218,6 @@ func answeredBy(operator string, t stashgen.GoType, indexes []stashgen.IndexName case "matches": return stashgen.IndexMatch, declared(stashgen.IndexMatch) } - orderable := (integer(t) && !eightBit(t)) || logical(t) || - t.Kind == stashgen.KindFloat || t.Kind == stashgen.KindString - if !orderable { - return "", false - } for _, index := range []stashgen.IndexName{stashgen.IndexOre, stashgen.IndexOreBlock} { if declared(index) { return index, true @@ -239,15 +235,6 @@ func integer(t stashgen.GoType) bool { return false } -// logical reports whether the type is a decimal, a date or a timestamp. -func logical(t stashgen.GoType) bool { - switch t.Kind { - case stashgen.KindDecimal, stashgen.KindDate, stashgen.KindTimestamp: - return true - } - return false -} - // eightBit reports whether the type is an 8-bit integer (int8, uint8 or // byte, or a type defined over one), which has no order term. func eightBit(t stashgen.GoType) bool { diff --git a/languages/golang/stashgen/refusal_test.go b/languages/golang/stashgen/refusal_test.go index eeb6d1ab78..d25d712e42 100644 --- a/languages/golang/stashgen/refusal_test.go +++ b/languages/golang/stashgen/refusal_test.go @@ -444,8 +444,12 @@ func TestAnOrderIndexOnBytesIsRefused(t *testing.T) { if err != nil { t.Fatal(err) } - if notices := strings.Join(file.Notices, "\n"); strings.Contains(notices, "no generated method queries") { - t.Errorf("an index every field can query got a notice:\n%s", notices) + // Every index here answers a query method, so no notice names a field. + notices := strings.Join(file.Notices, "\n") + for _, field := range []string{"User.Name", "User.Blob", "User.Score"} { + if strings.Contains(notices, field) { + t.Errorf("a field whose every index is queried got a notice (%s):\n%s", field, notices) + } } if !strings.Contains(string(file.Content), "func (f NameField) Lt(") { t.Errorf("a text field with ope has no Lt:\n%s", file.Content) diff --git a/packages/stack-encrypt/src/dynamic/record.rs b/packages/stack-encrypt/src/dynamic/record.rs index d6ff7a6cd8..98dd0e0d4a 100644 --- a/packages/stack-encrypt/src/dynamic/record.rs +++ b/packages/stack-encrypt/src/dynamic/record.rs @@ -418,8 +418,8 @@ impl FieldPlan { /// [`Error::Plan`] if the field asks for an index the kind is not /// defined for ([`admits`](super::admits)), with the reason [`not_admitted`] gives: /// [`Reason::IndexNotAdmitted`] for match on an integer, equality or an - /// order index on a boolean, an order index on an 8-bit integer, any - /// index on a composite. + /// order index on a boolean, an order index on an 8-bit integer or on + /// bytes, any index on a composite. pub fn with_type(mut self, field_type: ValueKind) -> Result { for output in &self.outputs { if let Output::Term(index) = output { diff --git a/packages/stack-encrypt/src/refusal.rs b/packages/stack-encrypt/src/refusal.rs index 1e34adc379..191c1b0a43 100644 --- a/packages/stack-encrypt/src/refusal.rs +++ b/packages/stack-encrypt/src/refusal.rs @@ -478,7 +478,8 @@ reasons! { /// `"type"` is not a string naming a value type. UnknownType => "unknown_type", r#""type" does not name a value type"#; /// The field's declared type has no such index: match on an integer, - /// equality or an order index on a boolean, any index on a composite. + /// equality or an order index on a boolean, an order index on an + /// 8-bit integer or on bytes, any index on a composite. IndexNotAdmitted => "index_not_admitted", "the declared type has no such index"; /// The field declares the JSON index as an output. A data plan /// reaches the JSON index through a target that stores a document From 78cea4aa930119e4474aef6735a341d17ebdd49e Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Sun, 22 Nov 2026 16:35:32 +1100 Subject: [PATCH 3/4] test(stack-encrypt): an order index on bytes does not compile anywhere The compile-fail test lists every place an order index on bytes could be declared: a set of indexes, a field of a derived record, a target of its own (owned or borrowed), and the low-level operations. Each is refused by vitaminc-ore's `Orderable`, which does not cover bytes. A pass test holds the other side: every type the ordering operators accept takes each order index in each of those places. The docs on the Go generator, the Go fake engine and `dynamic::admits` say an operator accepts a type, in short sentences, and `admits` names `Orderable` as the typed path's rule. Refs #1577 --- languages/golang/stashgen/emit.go | 15 +- .../golang/stashgen/enginetest/enginetest.go | 10 +- packages/stack-encrypt/src/dynamic/kind.rs | 16 +- .../tests/ui/order_index_on_bytes.rs | 34 ++ .../tests/ui/order_index_on_bytes.stderr | 448 ++++++++++++++++++ .../tests/ui/pass/order_indexes.rs | 33 ++ 6 files changed, 537 insertions(+), 19 deletions(-) create mode 100644 packages/stack-encrypt/tests/ui/order_index_on_bytes.rs create mode 100644 packages/stack-encrypt/tests/ui/order_index_on_bytes.stderr create mode 100644 packages/stack-encrypt/tests/ui/pass/order_indexes.rs diff --git a/languages/golang/stashgen/emit.go b/languages/golang/stashgen/emit.go index 83416222ea..a977c66ac5 100644 --- a/languages/golang/stashgen/emit.go +++ b/languages/golang/stashgen/emit.go @@ -802,14 +802,15 @@ func planQueries(f *genFile) error { return nil } -// verifiable refuses a probabilistic query on an index-only field: the -// query's rows are checked by decrypting them with Verify, and an -// index-only field stores no ciphertext, so Verify could never pass and -// every real match would be thrown away. +// verifiable refuses a probabilistic query on a field that only stores an +// index. The caller checks the rows of such a query by decrypting them +// with Verify. A field that only stores an index has no ciphertext, so +// Verify would never pass. The caller would discard every real match. // -// Every index the engine admits on a field answers an operator there, so -// no index is stored that a generated method cannot query. The engine -// refuses the one that would be: an order index on bytes. +// The engine only accepts an index on a field if one of the index's +// operators accepts the field's type. A generated method can therefore +// query every stored index. The engine refuses the one index that no +// method could query: an order index on bytes. func verifiable(g *genField) error { if g.Verb != VerbIndex { return nil diff --git a/languages/golang/stashgen/enginetest/enginetest.go b/languages/golang/stashgen/enginetest/enginetest.go index aef3d1d785..f07eed5a49 100644 --- a/languages/golang/stashgen/enginetest/enginetest.go +++ b/languages/golang/stashgen/enginetest/enginetest.go @@ -200,9 +200,9 @@ func (e Static) operators(ctx context.Context, d stashgen.Declaration) (map[stri // equality index, matches through a match index, and the orderings through // the one order index the field declares (ORE, block ORE or OPE; check // refused a field with two); each only where the index applies to the type -// (indexApplies). There is no second list of the types the orderings are -// answered over: an index that applies answers its operators, as in the -// engine. +// (indexApplies). As in the engine, there is no second list of the types +// that the orderings accept. If an index applies to a type, each of the +// index's operators accepts that type. func answeredBy(operator string, t stashgen.GoType, indexes []stashgen.IndexName) (stashgen.IndexName, bool) { declared := func(want stashgen.IndexName) bool { for _, idx := range indexes { @@ -251,8 +251,8 @@ func eightBit(t stashgen.GoType) bool { // match over text alone, ORE and OPE over integers of 16 bits and wider, // floats, text, decimals, dates and timestamps. Not over a boolean or an // 8-bit integer, whose order term would reveal which rows are true, or -// each row's rank among 256 values. Not over bytes, which no ordering -// operator is answered over: the term would be stored and never queried. +// each row's rank among 256 values. Not over bytes: no ordering operator +// accepts bytes, so no query could use the stored term. // The JSON index is not in the engine yet. func indexApplies(name stashgen.IndexName, t stashgen.GoType) error { switch name { diff --git a/packages/stack-encrypt/src/dynamic/kind.rs b/packages/stack-encrypt/src/dynamic/kind.rs index 9366a05e13..b982105fda 100644 --- a/packages/stack-encrypt/src/dynamic/kind.rs +++ b/packages/stack-encrypt/src/dynamic/kind.rs @@ -62,13 +62,15 @@ use crate::target::IndexSpec; /// values. A composite (`array`, `object`) has no term. Only the index's /// kind matters: a match index's options do not change what it applies to. /// -/// Bytes are the one kind an index is refused though the scheme defines -/// its term. [`IndexSpec::defines`] takes bytes for an order index, but no -/// ordering operator is answered over bytes, so a plan that declared one -/// would store a term anyone can compare and no query can use. A plan -/// admits an index only over a kind one of the index's operators answers, -/// as the typed path's `Index` bound on [`op::Ordered`](crate::op::Ordered) -/// does. +/// A plan refuses an order index on bytes. No ordering operator accepts +/// bytes, so no query could use the stored term. Anyone who reads the rows +/// could still compare the terms. [`IndexSpec::defines`] gives bytes no +/// order term either. +/// +/// A plan therefore accepts an index on a kind only if one of the +/// index's operators accepts that kind. The typed interface has the same +/// rule: an order index needs [`Orderable`](crate::Orderable), which does +/// not cover bytes. /// /// ``` /// use stack_encrypt::dynamic::{admits, ValueKind}; diff --git a/packages/stack-encrypt/tests/ui/order_index_on_bytes.rs b/packages/stack-encrypt/tests/ui/order_index_on_bytes.rs new file mode 100644 index 0000000000..f6dd23016d --- /dev/null +++ b/packages/stack-encrypt/tests/ui/order_index_on_bytes.rs @@ -0,0 +1,34 @@ +//! An order index stores a term that reveals the order of the rows. No +//! ordering operator compares bytes, so an order index on bytes would store +//! that term and answer no query. vitaminc-ore's `Orderable` does not cover +//! bytes, so it does not compile: as a set of indexes, as a field of a +//! derived record, as a target of its own (owned or borrowed), or as the +//! low-level operation an index of another crate would be built from. +use stack_encrypt::sem::{OpeTerm, OreBlockTerm, OreTerm}; +use stack_encrypt::target::{self, indexed, Borrowed, EncryptTarget}; +use stack_encrypt::{Encrypted, Ope, Ore, OreBlock}; +use zeroize::Zeroize; + +#[derive(Clone, Zeroize)] +struct File { + digest: Vec, +} + +#[derive(EncryptTarget)] +#[stash(struct = File, scope = "files")] +struct EncryptedFile { + digest: Encrypted>>, +} + +fn main() { + let _ = indexed::, (), Borrowed, _>(Ore); + let _ = indexed::, (), Borrowed, _>(Ope); + let _ = indexed::, (), Borrowed, _>(OreBlock); + let _ = > as EncryptTarget>>::encryption::<()>(); + let _ = > as EncryptTarget>>::encryption::<()>(); + let _ = > as EncryptTarget>>::encryption::<()>(); + let _ = > as EncryptTarget>>::owned_encryption::<()>(); + let _ = target::ore::, (), Borrowed>(); + let _ = target::ope::, (), Borrowed>(); + let _ = target::ore_block::, (), Borrowed>(); +} diff --git a/packages/stack-encrypt/tests/ui/order_index_on_bytes.stderr b/packages/stack-encrypt/tests/ui/order_index_on_bytes.stderr new file mode 100644 index 0000000000..37aedf9b62 --- /dev/null +++ b/packages/stack-encrypt/tests/ui/order_index_on_bytes.stderr @@ -0,0 +1,448 @@ +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:20:23 + | +20 | digest: Encrypted>>, + | ^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `OreTerm` + --> src/sem/mod.rs + | + | pub struct OreTerm(OreClww8VariableV1, PhantomData T>); + | ^^^^^^^^^ required by this bound in `OreTerm` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:20:13 + | +20 | digest: Encrypted>>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `OreTerm` + --> src/sem/mod.rs + | + | pub struct OreTerm(OreClww8VariableV1, PhantomData T>); + | ^^^^^^^^^ required by this bound in `OreTerm` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:20:13 + | +20 | digest: Encrypted>>, + | ^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others + = note: required for `OreTerm>` to implement `TermSet>` + = note: required for `Encrypted>>` to implement `EncryptTarget>` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:17:10 + | +17 | #[derive(EncryptTarget)] + | ^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `OreTerm` + --> src/sem/mod.rs + | + | pub struct OreTerm(OreClww8VariableV1, PhantomData T>); + | ^^^^^^^^^ required by this bound in `OreTerm` + = note: this error originates in the derive macro `EncryptTarget` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:17:10 + | +17 | #[derive(EncryptTarget)] + | ^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `OreTerm` + --> src/sem/mod.rs + | + | pub struct OreTerm(OreClww8VariableV1, PhantomData T>); + | ^^^^^^^^^ required by this bound in `OreTerm` + = note: this error originates in the derive macro `EncryptTarget` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:24:13 + | +24 | let _ = indexed::, (), Borrowed, _>(Ore); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others + = note: required for `stack_encrypt::Ore` to implement `stack_encrypt::Index>` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:25:13 + | +25 | let _ = indexed::, (), Borrowed, _>(Ope); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others + = note: required for `stack_encrypt::Ope` to implement `stack_encrypt::Index>` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:26:13 + | +26 | let _ = indexed::, (), Borrowed, _>(OreBlock); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others + = note: required for `stack_encrypt::OreBlock` to implement `stack_encrypt::Index>` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:27:13 + | +27 | let _ = > as EncryptTarget>>::encryption::<()>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others + = note: required for `OreTerm>` to implement `EncryptTarget>` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:28:13 + | +28 | let _ = > as EncryptTarget>>::encryption::<()>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others + = note: required for `OpeTerm>` to implement `EncryptTarget>` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:29:13 + | +29 | let _ = > as EncryptTarget>>::encryption::<()>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others + = note: required for `OreBlockTerm>` to implement `EncryptTarget>` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:30:13 + | +30 | let _ = > as EncryptTarget>>::owned_encryption::<()>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `OreTerm` + --> src/sem/mod.rs + | + | pub struct OreTerm(OreClww8VariableV1, PhantomData T>); + | ^^^^^^^^^ required by this bound in `OreTerm` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:31:27 + | +31 | let _ = target::ore::, (), Borrowed>(); + | ^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `stack_encrypt::target::ore` + --> src/target/operations.rs + | + | ore, crate::sem::OreTerm, wipe(std::convert::identity), [], + | --- required by a bound in this function + | [S: crate::Orderable + EncryptRef + 'static] + | ^^^^^^^^^^^^^^^^ required by this bound in `ore` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:31:13 + | +31 | let _ = target::ore::, (), Borrowed>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `OreTerm` + --> src/sem/mod.rs + | + | pub struct OreTerm(OreClww8VariableV1, PhantomData T>); + | ^^^^^^^^^ required by this bound in `OreTerm` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:32:27 + | +32 | let _ = target::ope::, (), Borrowed>(); + | ^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `stack_encrypt::target::ope` + --> src/target/operations.rs + | + | ope, crate::sem::OpeTerm, wipe(std::convert::identity), [], + | --- required by a bound in this function + | [S: crate::Orderable + EncryptRef + 'static] + | ^^^^^^^^^^^^^^^^ required by this bound in `ope` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:32:13 + | +32 | let _ = target::ope::, (), Borrowed>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `OpeTerm` + --> src/sem/mod.rs + | + | pub struct OpeTerm(OpeClww8VariableV1, PhantomData T>); + | ^^^^^^^^^ required by this bound in `OpeTerm` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:33:33 + | +33 | let _ = target::ore_block::, (), Borrowed>(); + | ^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `stack_encrypt::target::ore_block` + --> src/target/operations.rs + | + | ore_block, crate::sem::OreBlockTerm, wipe(std::convert::identity), [], + | --------- required by a bound in this function + | [S: crate::Orderable + EncryptRef + 'static] + | ^^^^^^^^^^^^^^^^ required by this bound in `ore_block` + +error[E0277]: `Vec` is not `Orderable`: it has no order target of its own + --> tests/ui/order_index_on_bytes.rs:33:13 + | +33 | let _ = target::ore_block::, (), Borrowed>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has no order target of its own + | + = help: the trait `Orderable` is not implemented for `Vec` + = note: name the target: `scheme.target(I64).encrypt_checked(value)` + = note: there is no 8-bit target: an order term over 256 values reveals them, so an `i8` goes into `I16` or wider by name (`scheme.target(I16).encrypt(value)`), or into an equality index + = note: bytes order only into a target named for them, `scheme.target(Bytes)`: no ordering operator compares bytes + = help: the following other types implement trait `Orderable`: + &f32 + &f64 + &i128 + &i16 + &i32 + &i64 + &jiff::civil::date::Date + &jiff::timestamp::Timestamp + and $N others +note: required by a bound in `OreBlockTerm` + --> src/sem/mod.rs + | + | pub struct OreBlockTerm(ore_rs::Term, PhantomData T>); + | ^^^^^^^^^ required by this bound in `OreBlockTerm` diff --git a/packages/stack-encrypt/tests/ui/pass/order_indexes.rs b/packages/stack-encrypt/tests/ui/pass/order_indexes.rs new file mode 100644 index 0000000000..637ca34a94 --- /dev/null +++ b/packages/stack-encrypt/tests/ui/pass/order_indexes.rs @@ -0,0 +1,33 @@ +//! Every type an ordering operator accepts takes each order index: as a set +//! of indexes, as an `Encrypted` target, and as a term on its own, owned or +//! borrowed. `order_index_on_bytes.rs` is the other side: bytes take none. +use stack_encrypt::sem::{OpeTerm, OreBlockTerm, OreTerm}; +use stack_encrypt::target::{self, indexed, Borrowed, EncryptTarget}; +use stack_encrypt::value::{Date, Decimal, Timestamp}; +use stack_encrypt::{Encrypted, Ope, Ore, OreBlock}; + +macro_rules! takes_every_order_index { + ($($ty:ty),+ $(,)?) => {$( + let _ = indexed::<$ty, (), Borrowed, _>(Ore); + let _ = indexed::<$ty, (), Borrowed, _>(Ope); + let _ = indexed::<$ty, (), Borrowed, _>(OreBlock); + let _ = > as EncryptTarget<$ty>>::encryption::<()>(); + let _ = > as EncryptTarget<$ty>>::encryption::<()>(); + let _ = > as EncryptTarget<$ty>>::encryption::<()>(); + let _ = as EncryptTarget<$ty>>::encryption::<()>(); + let _ = as EncryptTarget<$ty>>::encryption::<()>(); + let _ = as EncryptTarget<$ty>>::encryption::<()>(); + let _ = as EncryptTarget<$ty>>::owned_encryption::<()>(); + let _ = as EncryptTarget<$ty>>::owned_encryption::<()>(); + let _ = as EncryptTarget<$ty>>::owned_encryption::<()>(); + let _ = target::ore::<$ty, (), Borrowed>(); + let _ = target::ope::<$ty, (), Borrowed>(); + let _ = target::ore_block::<$ty, (), Borrowed>(); + )+}; +} + +fn main() { + takes_every_order_index!( + u16, u32, u64, u128, i16, i32, i64, i128, f32, f64, String, Date, Timestamp, Decimal, + ); +} From b56d955e38221e96e6a67c8de90507d0ed44bfe2 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Sun, 22 Nov 2026 19:43:25 +1100 Subject: [PATCH 4/4] fix(stack-encrypt): address the agent review of the bytes order refusal - `dynamic::admits` reads `IndexSpec::takes` alone. Its own clause for bytes could not change the result once `ordered()` refused bytes, and it kept a second copy of the rule. - The stored-rows test asks the engine (`admits`) which indexes of the frozen plan are retired, where it kept a third copy of the rule. If the engine admits an order index on bytes again, the frozen rows must reseal as they were. - The docs say bytes have no order term, where four of them still said the scheme defines one: `admits`, `Op::answered_by`, the declaration grammar, and the values contract. A test comment and a repeated assertion are removed. - `coverage.md` loses a clause a rebase brought back. It said the typed path refuses after the keyset loads, and the query refusal contract says both paths refuse before. - The Go CHANGELOG keeps the released rc.4 text, and its upgrade note says code generated by rc.6 or earlier fails with `index_not_admitted` until it is generated again. Refs #1577 --- conformance/stack-encrypt/coverage.md | 6 ++-- .../stack-encrypt/declaration-grammar.md | 8 ++--- conformance/stack-encrypt/values-contract.md | 6 ++-- languages/golang/CHANGELOG.md | 18 ++++++++--- packages/stack-encrypt/src/dynamic/kind.rs | 18 ++++------- packages/stack-encrypt/src/dynamic/query.rs | 4 +-- packages/stack-encrypt/tests/stored_rows.rs | 32 ++++++++++++------- 7 files changed, 51 insertions(+), 41 deletions(-) diff --git a/conformance/stack-encrypt/coverage.md b/conformance/stack-encrypt/coverage.md index 1e37e9df02..a35bb18e6b 100644 --- a/conformance/stack-encrypt/coverage.md +++ b/conformance/stack-encrypt/coverage.md @@ -144,10 +144,8 @@ Each runs in native Rust and Go WASI under `test:conformance`. | Native `a_stored_record_that_does_not_fit`, the read profile | `shape-*`, `authenticated-*`, `success-*` | Mutation vocabulary over real ciphertext | | Guest `test_frame` and `last_error` tests | `transport-*`, `leaf-*` | Plan-frame boundary cases, ABI status mapping | -Unsupported combinations the corpora record rather than skip: the typed -chain refuses equality, order and block ORE value refusals only after its -keyset loads, where the binding refuses before any; a repeated key in a -stored record is a transport refusal in both decoders, and the engine's own `field_repeated` +Unsupported combinations the corpora record rather than skip: a repeated +key in a stored record is a transport refusal in both decoders, and the engine's own `field_repeated` and `repeated_key` guards are reached natively alone; the Go host refuses the zero `Date`, a decimal scale above 28, a timestamp outside the decoder's range and non-value Go types before the engine. `NaN` and diff --git a/conformance/stack-encrypt/declaration-grammar.md b/conformance/stack-encrypt/declaration-grammar.md index 6d82a08e72..889ade83d0 100644 --- a/conformance/stack-encrypt/declaration-grammar.md +++ b/conformance/stack-encrypt/declaration-grammar.md @@ -179,10 +179,10 @@ select a different leaf encoding. | bytes | Admitted | Refused | Refused | | array, object, json | Refused | Refused | Refused | -An index is admitted only over a kind one of its operators answers. The -scheme defines an order term for bytes, but no ordering operator is answered -over bytes, so the term would be stored and never queried. The order indexes -are refused on bytes as `index_not_admitted`. +An index is admitted only over a kind one of its operators answers. Bytes +have no order term: no ordering operator compares them, so a term would be +stored and never queried. The order indexes are refused on bytes as +`index_not_admitted`. The corpus explicitly tests all 21 kinds against all five scalar indexes. `array` and `object` may still be sealed without indexes. A `json` field requires diff --git a/conformance/stack-encrypt/values-contract.md b/conformance/stack-encrypt/values-contract.md index 4901a7a044..0624227395 100644 --- a/conformance/stack-encrypt/values-contract.md +++ b/conformance/stack-encrypt/values-contract.md @@ -95,9 +95,9 @@ null. Every index a case declares is one a query operator answers for the kind, because a declaration admits no other. An order index on `bytes` is the -case that shows it: the scheme defines an order term for bytes, but no -ordering operator is answered over them, so a stored term would let anyone -who holds two rows compare them without a key, and no query could use it. +case that shows it: bytes have no order term, because no ordering operator +compares them. A stored term would let anyone who holds two rows compare +them without a key, and no query could use it. Both paths refuse it. The typed Rust path bounds an order index on vitaminc-ore's `Orderable`, which does not cover `Vec`, so the declaration does not compile. The dynamic path, which both runners diff --git a/languages/golang/CHANGELOG.md b/languages/golang/CHANGELOG.md index df5a597f26..6838584324 100644 --- a/languages/golang/CHANGELOG.md +++ b/languages/golang/CHANGELOG.md @@ -44,10 +44,17 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit. is answered over bytes, so the field stored an order term that anyone who read the column could compare and that no query could use. `stashgen`'s notice for an index no generated method queries is gone - with the case it described. To upgrade, remove the index from the tag - and generate again. Rows stored with the term still open: opening - ignores a stored term the plan does not declare. The stored terms stay - in the database until the row is written again or the column is dropped. + with the case it described. + - Code that rc.6 or earlier generated for such a field still compiles, + but the guest refuses its plan when it is parsed. Until the tag is + edited and `stashgen` is run again, `Encrypt` and `Decrypt` of that + record type fail with `index_not_admitted`, as does its bytes field's + `Field.Encrypt`. That includes rows that were stored correctly. + - To upgrade, remove the index from the tag and generate again. Once the + code is generated again, rows stored with the term still open: opening + ignores a stored term the plan does not declare. The stored terms stay + in the database until the row is written again or the column is + dropped. ### Changed @@ -313,7 +320,8 @@ In the code: is requested. Before, the field stored both terms and every query used the ORE one; the OPE term cost a write and told anyone who read the column how its values order. `stashgen`'s notice for a second order index - is gone with the case it described. + is gone with the case it described; the notice for an order index on + bytes stays. - **`Cipher.Extend` is now `Cipher.Scope`, and `Cipher.Bind` is new** (#1487). A scope narrows the data and the queries over it. A binding ties diff --git a/packages/stack-encrypt/src/dynamic/kind.rs b/packages/stack-encrypt/src/dynamic/kind.rs index b982105fda..5d6fc7bf31 100644 --- a/packages/stack-encrypt/src/dynamic/kind.rs +++ b/packages/stack-encrypt/src/dynamic/kind.rs @@ -62,10 +62,10 @@ use crate::target::IndexSpec; /// values. A composite (`array`, `object`) has no term. Only the index's /// kind matters: a match index's options do not change what it applies to. /// -/// A plan refuses an order index on bytes. No ordering operator accepts -/// bytes, so no query could use the stored term. Anyone who reads the rows -/// could still compare the terms. [`IndexSpec::defines`] gives bytes no -/// order term either. +/// Bytes have no order term: no ordering operator compares them, so no +/// query could use a stored term, and anyone who reads the rows could +/// still compare the terms. So a plan refuses an order index on bytes, as +/// [`IndexSpec::defines`] gives bytes no order term. /// /// A plan therefore accepts an index on a kind only if one of the /// index's operators accepts that kind. The typed interface has the same @@ -89,9 +89,7 @@ use crate::target::IndexSpec; /// assert!(!admits(ValueKind::Bytes, &IndexSpec::Ore)); /// ``` pub fn admits(kind: ValueKind, index: &IndexSpec) -> bool { - let unanswered = kind == ValueKind::Bytes - && matches!(index, IndexSpec::Ore | IndexSpec::Ope | IndexSpec::OreBlock); - !unanswered && scalar_of(kind).is_some_and(|(ty, scalar)| index.takes(ty, &scalar)) + scalar_of(kind).is_some_and(|(ty, scalar)| index.takes(ty, &scalar)) } /// Why `kind` does not admit `index`, or `None` when it does: the reason a @@ -701,8 +699,8 @@ mod tests { /// `admits` is `IndexSpec::defines` stated over kinds: the two cannot /// disagree about a value of any kind, and a composite admits nothing. - /// The one exception is an order index on bytes, whose term the scheme - /// defines and no operator answers: a plan does not admit it. + /// Bytes have no order term, so a plan refuses an order index on them + /// with `index_not_admitted`. #[test] fn admits_agrees_with_defines_for_every_kind() { for kind in value_kinds() { @@ -722,8 +720,6 @@ mod tests { ); } } - // Every other index bytes can hold is still admitted. - assert!(admits(ValueKind::Bytes, &IndexSpec::Equality)); // Spelled out, so the table reads without the cross-check. assert!(admits(ValueKind::UInt64, &IndexSpec::Equality)); assert!(admits(ValueKind::Float64, &IndexSpec::Equality)); diff --git a/packages/stack-encrypt/src/dynamic/query.rs b/packages/stack-encrypt/src/dynamic/query.rs index ff01abb644..9ff3072d19 100644 --- a/packages/stack-encrypt/src/dynamic/query.rs +++ b/packages/stack-encrypt/src/dynamic/query.rs @@ -189,8 +189,8 @@ impl Op { // answers is the one. A document field's JSON index answers the // document operators over a document alone; every other index // answers over the kinds it is defined for. - // `admits` refuses an order index over bytes, the one kind with an - // order term and no ordering, so no ordering is answered there. + // Bytes have no order term, so `admits` refuses an order index over + // them, and no ordering is answered there. indexes.iter().find(|index| { index.answers(self) && match index { diff --git a/packages/stack-encrypt/tests/stored_rows.rs b/packages/stack-encrypt/tests/stored_rows.rs index cd7ece618d..e8282e6809 100644 --- a/packages/stack-encrypt/tests/stored_rows.rs +++ b/packages/stack-encrypt/tests/stored_rows.rs @@ -191,19 +191,27 @@ fn without_order_terms(json: &Json) -> Json { } } -/// The outputs a frozen plan declares that no build admits any more: an -/// order index on a `bytes` field. The plan the rows were stored under -/// declares two (`blob` with `ore`, and the index-only `blob_ope`); a -/// declaration now refuses them, because no ordering is answered over -/// bytes. -const RETIRED_ON_BYTES: [&str; 3] = ["ore", "ope", "ore_block"]; - -/// Whether `output` of a field of the frozen plan is retired. +/// Whether `output` of a field of the frozen plan is retired: an index the +/// engine no longer admits for the field's kind. The plan the rows were +/// stored under declares two, an order index on a `bytes` field (`blob` +/// with `ore`, and the index-only `blob_ope`). The engine's own rule +/// decides, so if it admits an order index on bytes again, nothing is +/// retired and the frozen rows must reseal as they were. fn retired(field: &Json, output: &Json) -> bool { - field.get("type") == Some(&json!("bytes")) - && output - .as_str() - .is_some_and(|o| RETIRED_ON_BYTES.contains(&o)) + let Some(kind) = field + .get("type") + .and_then(Json::as_str) + .and_then(|ty| ty.parse::().ok()) + else { + return false; + }; + let index = match output.as_str() { + Some("ore") => IndexSpec::Ore, + Some("ope") => IndexSpec::Ope, + Some("ore_block") => IndexSpec::OreBlock, + _ => return false, + }; + !admits(kind, &index) } /// Whether every output of a field of the frozen plan is retired: the field