Skip to content

fix(stack-encrypt)!: a data plan refuses an order index on bytes - #1611

Merged
coderdan merged 4 commits into
nextfrom
fix/stack-encrypt-order-index-on-bytes
Nov 22, 2026
Merged

coderdan merged 4 commits into
nextfrom
fix/stack-encrypt-order-index-on-bytes

Conversation

@coderdan

@coderdan coderdan commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A data plan can no longer declare an order index on a field of bytes. Before, the declaration was accepted, and it leaked. Each row stored a term that reveals its order, and no query could ever use that term.

Stack Encrypt (packages/stack-encrypt) is the Rust encryption engine under every CipherStash SDK. An order index (Ore, Ope, or OreBlock) stores a term beside the ciphertext, so a query can use <, >, and BETWEEN on encrypted values. The term reveals the order of the rows to anyone who holds them. That cost is accepted where a query needs it. No ordering operator compares bytes, so on bytes the cost buys nothing.

This PR is stacked on #1737. I rebased it onto #1737 as ADR 0014 sets out. #1737 bounds every typed order index on vitaminc-ore's Orderable. That trait does not cover bytes. So the typed half of this PR is in #1737, and the commits here that moved each bound to op::Ordered are dropped. This PR keeps the dynamic half, the Go generator, the conformance corpus, the stored-row test, and the compile-fail tests.

To upgrade: remove the order index from the bytes field. Rows stored with the term still open, because opening ignores a stored term the plan does not declare. The old terms stay in the database until the row is written again.

Changes

The dynamic interface (the path the Go SDK uses)

  • dynamic::admits refuses ore, ope, and ore_block on a bytes field. A data plan that declares one is refused with index_not_admitted, before any key is requested.
  • The second list, in dynamic::query, is removed. Op::answered_by now reads admits alone, so the two cannot disagree 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. This removes the interim path that refactor(stack-encrypt,eql-bindings)!: read every plaintext by reference #1737 kept so that its stored rows would not change.

Go

  • stashgen refuses index=ore, ope, or ore_block on a []byte field as a field error. It asks the engine, so this follows from the engine change.
  • stashgen no longer prints a notice for "an index no generated method queries". The order index on bytes was the only case left that produced it.
  • The test types Probe and ProbeOpe lose their bytes field, and their generated files are regenerated.

Conformance corpus

  • record-declarations-v1: type-bytes-ore, type-bytes-ope, and type-bytes-ore_block are now refused with index_not_admitted.
  • record-values-v1: the unanswered list is removed from the corpus and from both runners. bytes-binary declares equality alone.
  • record-query-refusals-v1: the bytes field declares equality alone. The six *-on-bytes-order-index cases are renamed *-on-bytes. They are still refused as operator_not_answered.

Tests

  • tests/ui/order_index_on_bytes.rs is a compile-fail case on the current API. It covers a set of indexes, a derived record field, each order term as a borrowed target, an owned target, and the three low-level operations. Each line is refused with vitaminc-ore's own message.
  • tests/ui/pass/order_indexes.rs is the other side: every type the ordering operators accept takes each order index in each of those places.
  • tests/stored_rows.rs: the frozen file stored_rows_v1.json is not changed. Its every_kind plan declares an order index on two bytes fields. The test removes those indexes from the plan, opens each row as stored under it, and compares the resealed row without the retired terms.
  • Two unit tests in dynamic now expect bytes to have no order term.

Docs

  • The stack-encrypt CHANGELOG has an entry under Breaking, with what to change.
  • The API plan's step 1 states the rule: an index admits exactly the plaintexts one of its operators answers.
  • conformance/stack-encrypt/values-contract.md, coverage.md, declaration-grammar.md, query-refusals-contract.md, and exchange-contract.md describe the refusal.
  • The Go CHANGELOG has an entry under Breaking, and the Go README's type table lists equality alone for []byte.

What changed in the rebase

Commit before Now
1331afa08, 9a90f078e: move each bound to op::Ordered Dropped. #1737 removes op::Ordered and bounds on vitaminc-ore's Orderable.
5b04747e9: a data plan refuses an order index on bytes Kept as b7987b777. It also removes the dynamic bytes term.
db16f7507: review fixes Kept as 78dc15b5d. One doc line moved to src/refusal.rs, where Reason now lives.
03cf6bd36: plain-language docs Kept for the Go files and dynamic/kind.rs, in 78cea4aa9. The rest described op::Ordered.
ddb18a91d: old rows open without naming the term Its upgrade note moved to #1737's CHANGELOG entry, which now owns the typed change.
(new) b56d955e3 addresses the agent review: one rule for bytes in admits and the stored-rows test, docs that say bytes have no order term, and the Go CHANGELOG.

The compile-fail tests were rewritten for the current API. Plan and EncryptFrom were removed from next after they were written.

Verification

All run locally on b56d955e3. That is this PR on top of #1737 at 378bbf061.

Check Result
Root workspace: cargo nextest run --workspace --all-features 2,195 passed, 2 skipped. Includes the trybuild ui test, the frozen rows, and the conformance runners.
stack-encrypt with --no-default-features 961 passed
fmt, clippy with -D warnings, doc examples, rustdoc with warnings as errors Pass
EQL: eql-bindings with stack-encrypt, and eql-encryption-tests Pass
The stack-encrypt guest builds (wasm:guest:build, :eql, and both deterministic builds) Pass
mise run go:test Pass
go generate ./... in languages/golang No change to any generated file

Every check in the table ran on that commit. Not run: the Postgres suites, the live tests, and mutation testing.

Related

Closes #1577. The base branch is not main, so GitHub will not close the issue on merge. Stacked on #1737. ADR 0014, "How the work lands", step 3.

Review notes

  • Start with admits in packages/stack-encrypt/src/dynamic/kind.rs, then ordered in dynamic/term.rs.
  • No stored byte changes. The dynamic change refuses a declaration, and no longer derives a term no plan can declare.
  • The conformance cases are edited in place, not added as a new profile version. The conformance README says an incompatible expectation needs a new profile. Dan decided to make a one-off exception, and to leave the README rule as it is.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ed28065-b551-457b-852f-aba939f0db14

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

@changeset-bot

changeset-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b56d955

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Mutation testing (cargo-mutants, --in-diff, stack-auth + stack-encrypt + stack-encrypt-jsonpath)

caught missed unviable timeout
4 0 1 0

Every mutant in the changed lines was caught by a test.

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of this PR's own diff (the typed Rust half of #1577). I compiled scratch programs against the branch for each claim below, and ran one scratch test against the frozen stored rows. None of the scratch files is committed.

Findings

  1. Blocker. tests/ui/op_order_on_bytes.stderr quotes the standard library (::: $RUST/alloc/src/vec/mod.rs). rustc prints that snippet only when rust-src is installed. The CI toolchain in the root mise.toml has no rust-src, so the ui test will fail in CI while it passes locally. It is the only .stderr file with a $RUST/ line.
  2. Should fix. op_order_on_bytes.rs no longer tests the query refusal it is named for. The plan now fails at .with(Ore), so the .on(..) error is gone from the .stderr. No test now pins that an ordering query over bytes does not compile.
  3. Should fix. The refusal can be bypassed through the public low-level operations. I compiled a user Index<Vec<u8>> whose operation() is target::ore() and whose spec() is IndexSpec::Ore. Plan::context(..).with::<Vec<u8>, _>((Equality, MyOre)).build() compiles. A user EncryptFrom<Vec<u8>> target that zips ciphertext() with target::ore() and returns IndexSpec::Ore from indexes() also builds as a plan. The Index rustdoc invites exactly this: "an index defined in another crate implements it by composing this module's public operations". So target::ore, ope and ore_block do declare an index in practice. The keyset's ore_term, ope_term and ore_block_term cannot be composed into a description, so bounding only the three target operations on op::Ordered closes the gap. The term-level byte tests (tests/term_bytes.rs, tests/ore_block.rs) and the dynamic path use the keyset functions, so they are not affected.
  4. Should fix. Rustdoc that is now false or silent. Ore says "Defined for every S the scheme can order", but the scheme orders bytes and the index no longer takes them (Ope and OreBlock say "the same S"). The Index trait says it is "Implemented for exactly the plaintexts the index's scheme is defined over", and its diagnostic note says Ore and Ope "take the types their schemes encode". Orderable does not say that Vec<u8> has an order term but no order index. Ordered does not say it is the bound on the order indexes.
  5. Should fix. Test gaps in order_index_on_bytes.rs. It pins the Index and TermSet bounds, and EncryptTarget for OpeTerm and OreBlockTerm. It does not pin the EncryptFrom bound on the three order terms, or EncryptTarget for OreTerm. I checked: Plan::value::<Vec<u8>>().encrypt_into::<OreTerm<Vec<u8>>>() and keyset.encrypt_as::<Vec<u8>, Encrypted<(EqualityTerm, OreBlockTerm<Vec<u8>>)>> are refused today, but reverting the EncryptFrom bounds would fail no test.
  6. Nit. No positive test that each Ordered type still takes each order index through a plan, an Encrypted<..> target and EncryptFrom. tests/ui/pass/indexes.rs covers u32 and String only. A pass case would catch a later narrowing of Ordered.
  7. Nit. CHANGELOG.md says the dynamic interface still admits an order index on bytes "so that rows the Go SDK stored stay readable". Reading does not need that (see the dynamic notes below). The reason is that the decision is open. The entry could also say that a record which only opens can still name Encrypted<OreTerm<Vec<u8>>>, so rows stored before stay readable from Rust.

Checked, and nothing to fix

  • Every ordinary typed declaration path is refused. I compiled each of these over Vec<u8> and each fails with the Ordered diagnostic: .with with Ore, Ope, OreBlock, (Equality, Ore) and vec![Ope]; Plan::value().with(..); Plan::value().encrypt_into::<Encrypted<(EqualityTerm, OreTerm<Vec<u8>>)>>() and ::<OreTerm<Vec<u8>>>(); the fields builder's encrypt_index, index, encrypt_into and target; cipher.encrypt(..).context(..).with(Ore); target::indexed(Ope); encrypt_as; Vec<..>, Option<..> and tuple targets; #[derive(EncryptTarget)]; and #[derive(EncryptFrom)] with an OreTerm<Vec<u8>> field. Markers come from the derive, so they are covered too. &[u8], Box<[u8]> and Protected<Vec<u8>> were never Orderable.
  • EQL v4 types. No eql-bindings v4 type stores an order term over bytes.
  • Decryption. Encrypted<OreTerm<Vec<u8>>> can still be named for DecryptInto and DecryptSource, and #[derive(DecryptSource)] with such a field compiles. That is right: rows stored before stay readable.
  • Query-side bounds. QueryTerm, LabelledTarget and OperatorAnswer for the order terms are still on Orderable. They cannot be reached for bytes, because Answers and DefaultIndex are already on Ordered and nothing can store an order term over bytes. Harmless, so I would leave them.
  • The other types implement trait lists in the new .stderr files are sorted by rustc and match the existing op_order_on_bytes output, so they are stable.
  • Mutation testing. The diff changes trait bounds, comments and tests only. cargo mutants --in-diff has no function body to mutate.
  • House rules. No issue numbers in code comments or rustdoc. The CHANGELOG and plan references are allowed.

The dynamic half (information for the decision, not a finding)

I read src/dynamic/record.rs and ran the frozen every_kind row from tests/fixtures/stored_rows_v1.json under edited plans:

  • record_row takes only the "c" node of a sealed field. It ignores every other output key, and it ignores stored fields the plan does not name. A field with no "c" (index only) is never opened (FieldSpec::opens).
  • With "ore" removed from blob, the row opens to the frozen opened value, byte for byte.
  • With "ore" removed from blob and the ["ope"]-only blob_ope field removed from the plan, the row still opens to the same value.
  • A field with "outputs": [] is refused when the plan is parsed (no outputs).

So option 2's stated cost ("its rows could not be read without a further rule") does not hold for reading. The rule is "remove the field", and the rows open unchanged. Option 2's real costs are: a Go program whose generated plan has the declaration fails to parse until it is regenerated; the frozen-row test parses the frozen plan as it is, so it would need a v2 fixture or a test change; and the record-declarations-v1 cases change. Option 1 keeps every plan parsing and every row opening, but it adds a write-time refusal, and the conformance cases still change meaning (accepted for reading only). Option 3 keeps writing the leaking term for every new row.

Comment thread packages/stack-encrypt/CHANGELOG.md Resolved
@coderdan coderdan changed the title fix(stack-encrypt)!: an order index on bytes does not compile fix(stack-encrypt)!: an order index on bytes is refused Nov 10, 2026
@coderdan

Copy link
Copy Markdown
Contributor Author

Pushed a51efdc41, which adds the dynamic half of #1577: a data plan now refuses an order index on bytes, the Go generator refuses the tag, and the conformance corpus follows. The description is rewritten to cover the whole issue. This commit has not had the local sub-agent review that the two earlier commits had.

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of a51efdc41 ("a data plan refuses an order index on bytes") only. The two earlier commits were reviewed before.

I found no correctness defect in the engine change. The findings are stale documentation and weak tests. Most severe first.

  1. Low-medium. The declaration grammar still says bytes admit an order index. conformance/stack-encrypt/declaration-grammar.md:178, the admission table: | bytes | Admitted | Refused | Admitted |. The corpus now refuses type-bytes-ore, type-bytes-ope and type-bytes-ore_block with index_not_admitted. This file is the specification a new runner (Python, TypeScript) is written from. A runner built from the table admits the declaration, and then fails those three cases.

  2. Low. The Go CHANGELOG names a tag word that does not exist. languages/golang/CHANGELOG.md:15-16: "A []byte field tagged index=ore, index=ope or index=ore_block is now a field error". ore_block is not a tag word. stashgen/tag.go:317 refuses it as unknown index "ore_block" on every field, before and after this commit; stashgen/declaration.go:197-200 says a field reaches it only through encrypt_into=. A reader would think index=ore_block is accepted on other types. Only a hand-built record.Plan with record.OreBlock is newly refused.

  3. Low. coverage.md still records the unanswered order index. conformance/stack-encrypt/coverage.md:146-147: "Unsupported combinations the corpora record rather than skip: the order index on bytes stores a term no operator reads". The corpora no longer record it: the declaration is refused and the unanswered list is gone.

  4. Low. Two rustdoc lists of refused pairs leave bytes out. packages/stack-encrypt/src/dynamic/mod.rs:559-560 (Reason::IndexNotAdmitted: "match on an integer, equality or an order index on a boolean, any index on a composite") and packages/stack-encrypt/src/dynamic/record.rs:416-419 (FieldPlan::with_type, # Errors, which also names the 8-bit integer). Both are on docs.rs. A caller whose bytes field, accepted by rc.3, is now refused with index_not_admitted looks there and does not find the case.

  5. Low. A Go assertion can no longer fail. languages/golang/stashgen/refusal_test.go:389 checks that no notice contains "no generated method queries". This commit removed the only code that wrote that text (indexesAnswer in emit.go), so the check passes whatever the generator prints about those fields.

  6. Low. The Go fake engine keeps the list the Rust engine dropped. languages/golang/stashgen/enginetest/enginetest.go:221-225, in answeredBy: orderable := (integer(t) && !eightBit(t)) || logical(t) || ... is the Go copy of the ordered(kind) list this commit deleted from src/dynamic/query.rs. It is now redundant: declared already calls indexApplies, which refuses an order index on bytes, a boolean and an 8-bit integer. It is two lists that must agree, the pattern the commit removed from the engine. If indexApplies changes and orderable does not, the fake admits an index and answers nothing through it, and only the cases TestRefusalsHoldAgainstTheEmbeddedEngine lists would show it.

What I checked and found sound:

  • No other path stores an order term on bytes. FieldPlan::with_type is where a data plan checks its indexes against the kind, and a field's outputs are fixed in FieldPlan::new, before it. The guest's validate and encrypt_record both parse through record::plan. No EQL type in eql-bindings has a bytes plaintext, and a target field's kind must equal its descriptor's. The guest's se_term still derives an order term over bytes through IndexSpec::defines, but as one term, and the Go host calls it only for an output the plan declares.
  • Op::answered_by is unchanged for every kind but bytes. Order indexes answer only lt, lte, gt, gte and between. For those, the deleted ordered(kind) and admits(kind, Ore | Ope | OreBlock) agree on every other kind: both take the integers of 16 bits and wider, both floats, text, decimal, date and timestamp, and both refuse bool, int8, uint8, array, object and json. There is no uuid kind.
  • tests/stored_rows.rs. The stripping is keyed on a frozen field whose type is bytes and an output key of ore, ope or ore_block. Only blob and blob_ope in every_kind match, so every other field is compared as before. STACK_ENCRYPT_REFREEZE_ORDER_TERMS=1 passes and leaves stored_rows_v1.json byte-identical, retired terms included (git status clean after the run).
  • Mutation testing. cargo mutants -p stack-encrypt --in-diff over this commit's src diff: 6 mutants (admits to true and to false, both && to ||, == to !=, delete !), 6 caught.
  • Go. record-declarations-v1.inputs.go.json is consistent: its bytes cases take their outcome from the shared cases file. With all four guests rebuilt, go generate ./... changes no file, and go vet ./... and go test ./... pass.
  • Rust. cargo nextest run -p stack-encrypt -p stack-encrypt-derive --all-features: 1390 passed, 1 skipped.

I will fix all six in one commit on this branch.

@coderdan

Copy link
Copy Markdown
Contributor Author

All six findings from the review of a51efdc41 are fixed in 7044224.

  1. Declaration grammar table said bytes admit the order indexes: fixed in 7044224. The bytes row now refuses ore, ope and ore_block, with a paragraph on why.
  2. Go CHANGELOG named index=ore_block as a tag: fixed in 7044224. The entry now names index=ore and index=ope for tags, and ore_block only for a hand-built plan.
  3. coverage.md still listed the unanswered order index: fixed in 7044224. The clause is removed.
  4. Rustdoc for Reason::IndexNotAdmitted and FieldPlan::with_type left bytes out: fixed in 7044224. Both name an order index on bytes.
  5. The stashgen assertion that could not fail: fixed in 7044224. It now checks that no notice names User.Name, User.Blob or User.Score.
  6. The Go fake engine's second list: fixed in 7044224. answeredBy reads indexApplies alone, and the unused logical helper is removed.

Checks run on 7044224:

Check Result
cargo nextest run -p stack-encrypt -p stack-encrypt-derive --all-features 1390 passed, 1 skipped
cargo fmt --all --check clean
cargo clippy --workspace --all-features --all-targets -- -D warnings clean
cargo doc -p stack-encrypt --all-features --no-deps, warnings as errors clean
cargo test -p eql-bindings -p eql-encryption-tests --all-features (in packages/eql, no database) 28 test binaries pass, Postgres tests ignored
go generate ./... no file changed
go vet ./... clean
go test ./stashgen/... ./cmd/... pass

On a51efdc41, before the fix, with all four guests rebuilt: go test ./... passed in every package. The fix commit changes only Rust doc comments, Markdown and the two Go stashgen files, so I did not rebuild the guests for it. Mutation testing of the commit's src diff: 6 mutants, 6 caught.

@coderdan
coderdan marked this pull request as ready for review November 10, 2026 21:54
@coderdan
coderdan requested a review from a team as a code owner November 10, 2026 21:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T21:56:41.947776Z 7044224 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-10T21:59:10.952730Z 7044224 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review attestation

Reviewed 7044224c · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5
Skills: code-review, company-skills:review-cross-check, company-skills:review-post

Findings (2): 2 minor, 2 inline, 0 below.

Seven findings were checked against 7044224c, and five were refuted before posting. Order terms over bytes are unreachable through query bounds and stored plans. ore_block is not a tag word. No Go caller can produce a bytes order term. The order-index lists agree today.


Generated by Claude Code

Comment thread packages/stack-encrypt/CHANGELOG.md Resolved
Comment thread languages/golang/CHANGELOG.md Resolved
@coderdan
coderdan force-pushed the refactor/stack-encrypt-remove-transitional-api branch from 4b30382 to b24c0c7 Compare November 11, 2026 07:04
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from 7044224 to bc8d1d2 Compare November 11, 2026 07:04
@coderdan
coderdan force-pushed the refactor/stack-encrypt-remove-transitional-api branch from b24c0c7 to 18cff59 Compare November 11, 2026 07:28
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from bc8d1d2 to d07ee6f Compare November 11, 2026 07:28
@coderdan
coderdan force-pushed the refactor/stack-encrypt-remove-transitional-api branch from 18cff59 to 32519a5 Compare November 11, 2026 07:48
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from d07ee6f to cad6572 Compare November 11, 2026 07:48
@coderdan
coderdan force-pushed the refactor/stack-encrypt-remove-transitional-api branch from 32519a5 to 9916276 Compare November 11, 2026 10:29
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from cad6572 to d8aeadb Compare November 11, 2026 10:29
Base automatically changed from refactor/stack-encrypt-remove-transitional-api to next November 13, 2026 10:31
@coderdan
coderdan marked this pull request as draft November 20, 2026 03:54
@coderdan

Copy link
Copy Markdown
Contributor Author

Blocked by #1734.

This PR should bound an order index on vitaminc-ore 0.10's Orderable, in place of its own sem::Orderable and op::Ordered. It cannot yet. Orderable is sealed, and it covers Vitamin C's Date, Timestamp and Decimal, not Stack Encrypt's copies of them. Stack Encrypt keeps those copies only because a value with a ciphertext and terms is cloned. #1734 removes the clones and the copies. This PR then swaps its traits.

It will be rebased onto #1732 (Vitamin C 0.10) and moved to that base.

@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from d8aeadb to 25db7d5 Compare November 20, 2026 03:57
@coderdan
coderdan changed the base branch from next to chore/stack-encrypt-vitaminc-0-10 November 20, 2026 03:57
@coderdan

Copy link
Copy Markdown
Contributor Author

Rebased onto #1732 (Vitamin C 0.10) and moved to that base. The only conflicts were CHANGELOG entries: both sides are kept, and the Go entry sits under Unreleased Breaking. One new commit, 25db7d5, fixes the docs: an old row with a bytes order term opens as StackCipherText, and no record can name Encrypted<OreTerm<Vec<u8>>>. On the rebased branch, nextest passed 2026 tests with 2 skipped, and the doctests, clippy and the Go tests pass.

@coderdan
coderdan force-pushed the chore/stack-encrypt-vitaminc-0-10 branch 2 times, most recently from 9d61883 to a72885c Compare November 20, 2026 04:46
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch 2 times, most recently from 6df50d9 to ddb18a9 Compare November 20, 2026 05:32
Base automatically changed from chore/stack-encrypt-vitaminc-0-10 to next November 20, 2026 06:59
coderdan added a commit that referenced this pull request Nov 22, 2026
…ttle its conflicts

The first version of ADR-0014 and #1737 answer #1734 two ways. The ADR
inferred each operation's role from its type through a marker
parameter. #1737 uses position: `zip` takes a borrowed description as
its argument and runs it first, so only the operation written first is
handed an owned value. The review of the ADR reports that the inferred
form is ambiguous for two readers. This revision adopts #1737's
mechanism and settles each point where the two disagreed:

- `passthrough` is the only taker, and a borrowed `passthrough` keeps
  its copy of a value stored in the clear, as ADR-0012 requires;
- the named copy adapter is dropped;
- whoever is handed an owned value wipes it on every path, which closes
  a gap in the public operations on `next`;
- queries and their checks are readers;
- the claim of one copy is scoped to the typed path, and the dynamic
  interface's count is stated;
- `Date`, `Timestamp`, `Decimal`, `sem::Orderable` and `op::Ordered` are
  removed, and an order index is bounded by Vitamin C's `Orderable`,
  which does not cover bytes. That is the typed half of #1611.

It also records the order in which #1737, the order bound and #1611
land, and defines "reader" and "taker" in CONTEXT.md.

Refs #1734, #1737, #1611.
coderdan added a commit that referenced this pull request Nov 22, 2026
… from bytes

Dan confirmed the revision's three choices on 22 November 2026, so the
status is `accepted`.

- A borrowed `passthrough` keeps its copy. The ADR now says when the
  copy happens (a whole record run from a borrow, to keep the plaintext)
  and what removing it would cost: a caller who needs the plaintext
  afterwards would clone the whole value, its secrets included.
- `Owned` mode requires `Zeroize`, as written.
- Stack Encrypt no longer derives an order term from bytes. The keyset's
  term functions take a `Vec<u8>` on `next` only because
  `sem::Orderable` covers it, and that trait is removed. No ordering
  operator compares bytes, and a stored row with such a term still
  opens. This was left open for #1611 and is now decided.

Refs #1734, #1737, #1611.
coderdan added a commit that referenced this pull request Nov 22, 2026
…able

ADR-0014 decision 5, item 4 of #1734. `sem::Orderable` named each type's
order target, and `op::Ordered` listed the types the ordering operators
answer. They disagreed on bytes: an order index on `Vec<u8>` compiled, and
no operator answered it, so its term revealed the order of the rows and
answered no query. vitaminc-ore's `Orderable` already names each target,
covers a reference to each type, and leaves bytes out. Both traits go,
and every order index, order term and ordering operator is bounded by
vitaminc-ore's trait, re-exported as `stack_encrypt::Orderable`.

An order term now makes the value's order encoding first, and then keys
its scheme: the value is read once, in place or by a walk that wipes it,
and a term whose keyset is not loaded yet keeps only the encoding. The
JSON index derives a string leaf's OPE term from the document in place,
where it cloned the string.

The keyset's term functions no longer take bytes, and their term-level
tests of bytes are removed. A data plan can still declare an order index
on bytes until #1611 refuses it, so the dynamic path derives that term by
naming the `Bytes` target, and the stored rows and the conformance corpus
do not change.

Refs #1734
coderdan added a commit that referenced this pull request Nov 22, 2026
…able

ADR-0014 decision 5, item 4 of #1734. `sem::Orderable` named each type's
order target, and `op::Ordered` listed the types the ordering operators
answer. They disagreed on bytes: an order index on `Vec<u8>` compiled, and
no operator answered it, so its term revealed the order of the rows and
answered no query. vitaminc-ore's `Orderable` already names each target,
covers a reference to each type, and leaves bytes out. Both traits go,
and every order index, order term and ordering operator is bounded by
vitaminc-ore's trait, re-exported as `stack_encrypt::Orderable`.

An order term now makes the value's order encoding first, and then keys
its scheme: the value is read once, in place or by a walk that wipes it,
and a term whose keyset is not loaded yet keeps only the encoding. The
JSON index derives a string leaf's OPE term from the document in place,
and a data plan a text field's order term from the frame in place. Each
copied the text before.

The keyset's term functions no longer take bytes, and their term-level
tests of bytes are removed. A data plan can still declare an order index
on bytes until #1611 refuses it, so the dynamic path derives that term by
naming the `Bytes` target, and the stored rows and the conformance corpus
do not change.

Refs #1734
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from ddb18a9 to 23bcce3 Compare November 22, 2026 05:59
@coderdan
coderdan changed the base branch from next to refactor/stack-encrypt-plaintext-by-reference November 22, 2026 05:59
@coderdan coderdan changed the title fix(stack-encrypt)!: an order index on bytes is refused fix(stack-encrypt)!: a data plan refuses an order index on bytes Nov 22, 2026
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from 23bcce3 to c3c0f26 Compare November 22, 2026 06:24

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Human pass. LGTM.

@coderdan
coderdan marked this pull request as ready for review November 22, 2026 06:52

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review attestation

Reviewed c3c0f265 · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: mattpocock-skills:code-review · claude-opus-5-5; code-review (manual) · claude-opus-5-5; rust-security · claude-opus-5-5 (no findings)
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check, company-skills:review-post

Findings (9): 9 minor. 7 inline, 1 below, 1 in reply.

  • general minor The PR description's Verification section and rebase table name 23bcce3d9, f5eb29daa and 964ab591b, which are not commits in this PR. The PR's commits are 4e28d8fe4, 50bb86d2b and c3c0f2656, and c3c0f265 adds the trybuild cases after the run described. On c3c0f265 with rustc 1.94.1, the ui, stored_rows, exchange_conformance and value_conformance tests pass. go:test was not re-run. Update the SHAs, and re-run go:test on c3c0f265 before claiming it.

Eleven findings were checked against c3c0f265, and two were refuted. A target field cannot carry a bytes order index, because no resolver's catalog has bytes plaintext. The order_index_on_bytes.rs doc line is accurate. The built-in code-review skill could not see the PR tree, so its pass was done by hand. The rust-security pass found no path that derives or stores an order term over bytes.


Generated by Claude Code

Comment thread conformance/stack-encrypt/coverage.md Resolved
Comment thread languages/golang/CHANGELOG.md Resolved
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from c3c0f26 to 53658f2 Compare November 22, 2026 07:35
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
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.
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
- `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
@coderdan
coderdan force-pushed the fix/stack-encrypt-order-index-on-bytes branch from 53658f2 to b56d955 Compare November 22, 2026 09:00
Base automatically changed from refactor/stack-encrypt-plaintext-by-reference to next November 22, 2026 09:12
@coderdan
coderdan merged commit a93de8e into next Nov 22, 2026
58 checks passed
@coderdan
coderdan deleted the fix/stack-encrypt-order-index-on-bytes branch November 22, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants