Skip to content

refactor(stack-encrypt,eql-bindings)!: read every plaintext by reference - #1737

Merged
coderdan merged 7 commits into
nextfrom
refactor/stack-encrypt-plaintext-by-reference
Nov 22, 2026
Merged

coderdan merged 7 commits into
nextfrom
refactor/stack-encrypt-plaintext-by-reference

Conversation

@coderdan

@coderdan coderdan commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stack Encrypt (packages/stack-encrypt) is the Rust engine that the CipherStash language SDKs run on. A plaintext is the value before it is encrypted. Until now, one plaintext that fed several outputs was copied for each output, so the plaintext type had to be Clone. An example is a field with a ciphertext and a search term. Each copy is one more thing to wipe from memory.

This PR does all four items of #1734, as ADR 0014 decides them:

  1. Every operation reads its plaintext in place. One value with a ciphertext and several terms is not copied. Its type does not need Clone.
  2. Stack Encrypt's own Date, Timestamp, and Decimal are removed. Callers use Vitamin C's types. Vitamin C is CipherStash's Rust cryptography library.
  3. An operation in owned mode wipes the value it is handed, on every path. Before, two public operations dropped a value without wiping it.
  4. An order index is bounded by vitaminc-ore's Orderable. sem::Orderable and op::Ordered are removed, so an order index on bytes no longer compiles.

The stored format does not change. The frozen vectors, the stored-row fixtures, and the conformance corpus pass unchanged.

Changes

Every operation reads in place (commit 7893c5091)

  • An operation is handed a Source: either a borrow of the value, or the value itself. A borrowed description always gets a borrow. An owned description gets the value.
  • A ciphertext, an equality term, and the order terms each read a borrow.
  • zip lends the value. The second description always reads a borrow, and runs first. The first description is handed what it would get alone. So in owned mode the first one takes the value after the other has read it. The outputs stay in written order.
  • ShareSource is removed. ConsumeSource stays for passthrough only.
  • A sealed or indexed plaintext is bounded by Encrypt + EncryptRef, where it was Encrypt + Clone. EncryptRef means &T: Encrypt. stack_encrypt::EncryptRef is a new re-export.
  • The dynamic engine is the path the Go SDK uses. A data plan's sealed and indexed fields read their value in place. A passthrough field's value is moved into the output. ValueFrame and JsonPlaintext are no longer Clone.
  • A call on a keyset that is not loaded yet keeps no borrow of the plaintext. It keeps what it derived without the keyset: a term's normalized form or order encoding, wiped on drop. A borrowed JSON document is the one plaintext that is copied in this case. The copy is made once. It is wiped.

Vitamin C's dates, timestamps, and decimals (commit 026a1c20f)

  • stack_encrypt::value re-exports Vitamin C's Date, Timestamp, Decimal, and OutOfRange. Stack Encrypt's own types and RangeError are removed.
  • The types exist only with the jiff and rust_decimal features. Both are on by default, and the dynamic feature turns both on.
  • eql-bindings: the stack-encrypt feature turns both features on.

An owned operation wipes its value (commit e8b7decc5)

  • ciphertext dropped a value whose context was refused without wiping it. A match term dropped every owned value without wiping it. Both now wipe it.
  • The bound is a new mode trait, target::WipeSource. Borrowed implements it for every plaintext. Owned implements it for a plaintext that is Zeroize. So the Zeroize bound applies in owned mode only, and a borrowed &str can still be sealed.
  • ciphertext, equality, matching, the three order terms, indexed, Index::operation, and Indexes::operations are bounded by WipeSource, where they were bounded by SourceMode.
  • A typed query hands its value to its index by value, so a query value is Zeroize. Every query value this crate and eql-bindings accept already is.
  • The JSON operations keep their own guard and SourceMode.
  • The crate-internal wiping_ciphertext and indexed_beside are removed, because ciphertext now wipes.
  • ADR 0014 has an amendment that records the bound.

Order indexes on vitaminc-ore's Orderable (commit ab5a96ce6)

  • sem::Orderable and op::Ordered are removed. stack_encrypt::Orderable re-exports vitaminc-ore's trait, and its table is vitaminc-ore's. It covers the integers of 16 bits and wider, f32, f64, String, &str, and the three value types. It does not cover bytes, an 8-bit integer, or a bool.
  • An order term makes the value's order encoding first, and then keys its scheme. The value is read once. A term whose keyset is not loaded yet keeps only the encoding.
  • The keyset's ore_term, ope_term, and ore_block_term no longer take bytes. Their term-level tests of bytes are removed.
  • The JSON index derives a string leaf's OPE term from the document in place. A data plan derives a text field's order term from the frame in place. Each copied the text before.
  • A data plan can still declare an order index on bytes until fix(stack-encrypt)!: a data plan refuses an order index on bytes #1611 refuses it. Until then, the dynamic path derives that term by naming the Bytes target. So the stored rows and the conformance corpus do not change in this PR.

Review fixes (commits 26e8a745f, 163b5a044, 378bbf061)

  • Mutants: an unobservable sort in the data plan is removed, Source's Debug has a test, and Zeroize for the data plan's record has a test.
  • A reader that panics: zip and the match term hold an owned value in a guard. The guard wipes the value if the read panics. zip is bounded by WipeSource as a result.
  • A refused query value: a typed query value is wiped when its scope is refused. The JSON query operands are moved into their terms instead of cloned.
  • Simpler code: one function per order scheme in sem, and one macro for the six order Term impls. Source derives OpaqueDebug.
  • Docs and examples: every doc example keeps plaintext in a type that wipes it, as the crate asks a caller to. Orderable's docs cover jiff's and rust_decimal's Copy types. ADR 0009 is amended, and two pending changesets now describe Vitamin C's date types. A new changeset covers this PR's eql-bindings changes.
  • The compile error for an order term on bytes or an 8-bit integer is vitaminc-ore's. Its note is tracked in vitaminc-ore: an i8 still orders into a wider target, and the compile error recommends it vitaminc#631.

Tests

  • tests/source_mode.rs counts clones on a type that is not Clone, and asserts zero.
  • Two new tests count wipes on a type that is not Clone:
    • a_value_with_a_ciphertext_and_two_terms_is_wiped_once: an Encrypted<(EqualityTerm, MatchTerms)> sealed by encrypt_into wipes the value once. A refused context also wipes it once. The borrowed form leaves it with the caller.
    • each_owned_operation_wipes_its_value_once: ciphertext, equality, and matching in owned mode each wipe once, when the value is read and when the context is refused.
  • sem::order_terms_before_the_keyset_loads: an order term built before the keyset loads equals the term built after it, for all three schemes. A refusal reads the same before and after.
  • Compile tests: pass/owned_fan_out_without_clone.rs replaces a test that asserted an owned zip needs Clone. pass/owned_without_clone.rs now names Zeroize. Four compile-error snapshots changed because a bound changed. Two of those now show vitaminc-ore's own message for bytes and for an 8-bit integer.
  • heap_hygiene (both crates) passes. Its JSON assertions now expect the same allocations in the borrowed and owned forms.

Breaking changes

  • zip takes a borrowed description as its second argument, and runs it first.
  • A plaintext with only a by-value Encrypt impl must add impl Encrypt for &T.
  • In owned mode, a value that is sealed or indexed must be Zeroize. An Index implemented outside this crate changes M: SourceMode<'s, S> to M: WipeSource<'s, S>.
  • ShareSource, Clone for ValueFrame, and Clone for JsonPlaintext are removed.
  • Date, Timestamp, and Decimal are Vitamin C's. None is Clone. A build with default-features = false must name jiff and rust_decimal.
  • sem::Orderable and op::Ordered are removed. An order index on bytes does not compile, and the keyset's order term functions no longer take bytes.

Both CHANGELOGs have an entry for each change.

One Clone bound remains

Borrowed passthrough. Its output is the value itself, so from a borrow it can only copy. The value is stored in the clear, so this is not a copy of a secret. ADR 0014 decision 3 keeps it.

Go guest size

Measured with cargo build --target wasm32-wasip1 --release --locked, against next at 96e7242fd. The plain build now links jiff and rust_decimal.

Build next This PR Change
Plain, bytes 3,311,466 3,274,893 −36,573 (−1.1%)
Plain, gzip −9 854,662 863,420 +8,758 (+1.0%)
--features eql, bytes 4,960,019 5,029,906 +69,887 (+1.4%)
--features eql, gzip −9 1,003,029 1,016,899 +13,870 (+1.4%)

mise run wasm:guest:build passes, including its check of the module's imports.

Verification

All run on 378bbf061, except the guest size. I measured the size on 620dbe46f, before the review fixes.

Check Result
Root workspace: cargo nextest run --workspace --all-features 2,195 passed, 2 skipped. Includes heap_hygiene, the frozen vectors, the stored-row fixtures, and the conformance corpus.
stack-encrypt with --no-default-features: tests, clippy, and rustdoc 961 passed. Clippy and rustdoc pass.
Root workspace: fmt, clippy with -D warnings, doc examples, rustdoc with warnings as errors Pass
EQL crates: eql-bindings with stack-encrypt, with targets, and eql-encryption-tests Tests, doc examples, and clippy pass
Go guest Type-checks with and without --features eql. Release build and import check pass.
Go module tests Run on #1611, which is stacked on this PR. See #1611.

Not run: mutation testing.

Related

Refs #1734. ADR 0014 (packages/stack-encrypt/docs/adr/0014-operations-read-the-plaintext-and-at-most-one-takes-it.md). #1611 is stacked on this PR.

Review notes

  • WipeSource is a new public name. ADR 0014 left the form of the bound to the implementation. I tried a bound on Zeroize in both modes first. It refused a borrowed &str. A borrow never needs a wipe. Tell me if you want another name, or the bound written another way.
  • Start with packages/stack-encrypt/src/target/source.rs, then zip and run in target/operations.rs.
  • The order term path is order_encoding and order_pending in sem/mod.rs.
  • The interim bytes path is order_at in dynamic/term.rs. fix(stack-encrypt)!: a data plan refuses an order index on bytes #1611 removes it.

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 378bbf0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@cipherstash/eql Minor
stash Patch
@cipherstash/stack-prisma Patch
@cipherstash/basic-example Patch
@cipherstash/e2e Patch
@cipherstash/prisma-example Patch
@cipherstash/stack-drizzle Patch
@cipherstash/stack-supabase Patch
@cipherstash/stack Patch
@cipherstash/wizard Patch
@cipherstash/bench Patch
@cipherstash/test-kit Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai

coderabbitai Bot commented Nov 20, 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: 71bebc6b-8d52-443d-8644-0bb5752c14cd

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

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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

caught missed unviable timeout
25 0 106 0

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

@coderdan
coderdan force-pushed the refactor/stack-encrypt-remove-chain-and-old-traits branch 2 times, most recently from e7258ac to b44e96a Compare November 21, 2026 09:02
Base automatically changed from refactor/stack-encrypt-remove-chain-and-old-traits to next November 21, 2026 11:38
@coderdan
coderdan force-pushed the refactor/stack-encrypt-plaintext-by-reference branch 4 times, most recently from aaa842f to fc3a506 Compare November 22, 2026 03:57
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.
A plaintext with a ciphertext and terms was copied once for each extra
output. The operations took the plaintext by value, as vitaminc 0.9
required, so a description handed a borrow cloned it for each operation
(`ConsumeSource for Borrowed`), and one handed the value cloned it for
every side of a `zip` but the last (`ShareSource for Owned`). Every
`Clone` bound on a plaintext followed from those two.

vitaminc 0.10 reads by reference, so nothing needs the copy:

- A ciphertext walks a borrow through `EncryptRef::lend`. In owned mode
  it still walks the value, so vitaminc wipes it.
- An equality term normalizes a lent value. An order term keys its scheme
  with vitaminc-ore's `SchemeVisitor`, which holds no plaintext, and then
  encrypts the value by reference.
- `zip` lends the plaintext to its second description, which is always a
  borrowed one, and then hands the first what it would be handed alone.
  So several operations over one owned value make no copy.
- A data plan is handed its values. Each sealed or indexed field reads its
  value in place, and each passthrough field's value is moved into the
  output.

`ShareSource` is removed. `ConsumeSource` remains for `passthrough`
alone, whose output is the plaintext itself: a borrowed passthrough
copies a value that is stored in the clear. A plaintext that is sealed or
indexed is bounded by `EncryptRef` where it was bounded by `Clone`.

`ValueFrame` and `JsonPlaintext` are no longer `Clone`. No library code
used either impl.

The stored format is unchanged: the frozen vectors, the stored-row
fixtures and the conformance corpus pass as they are.

Refs #1734
… and Decimal

Stack Encrypt kept its own `value::Date`, `value::Timestamp` and
`value::Decimal` because each term took its own copy of the plaintext,
so a plaintext had to be `Clone`, and vitaminc's types are not. Every
operation now reads its plaintext in place, so the copies have no
reason to exist. `stack_encrypt::value` re-exports vitaminc-aead's
types instead.

vitaminc's types are built from jiff's and rust_decimal's, and exist
only with those features. So:

- `jiff` and `rust_decimal` are default features of stack-encrypt, and
  `dynamic` turns both on: a binding is handed every kind of value, and
  an order term over a date is derived from vitaminc's type.
- The type lists in `sem`, `op` and `marker` are gated on the features,
  so a build with no default features still compiles and tests.
- eql-bindings' `stack-encrypt` feature turns both on, because the
  date, timestamp and numeric families name the types. Its `jiff` and
  `rust_decimal` features remain as names for `stack-encrypt`.

The constructors from integers, the integer accessors and `RangeError`
are removed with the types. The stored format is unchanged: the frozen
vectors, the stored-row fixtures, the pinned EQL payloads and the Go
ledger rows pass as they were.

Refs #1734
… handed

ADR-0014 decision 4. The public `ciphertext` operation dropped a value
whose context was refused without wiping it, because its `S` need not be
`Zeroize`. A match term dropped every owned value unwiped. The targets and
the derive avoided both with their own wiping forms, but a caller who
composed the public operations did not.

The bound is a third mode trait, `WipeSource`. `Borrowed` implements it for
every plaintext, and `Owned` for a plaintext that is `Zeroize`, so the bound
applies in owned mode only and a borrowed `&str` is still sealed. Every
operation that seals or indexes is bounded by it, and so are
`Index::operation` and `Indexes::operations`. With `ciphertext` wiping,
the crate-internal `wiping_ciphertext` and `indexed_beside` go.

A typed query hands its value to the index by value, so a query value is
`Zeroize`. The JSON operations keep their own guard and `SourceMode`.

Two tests count wipes on a type that is not `Clone`: a value with a
ciphertext and two terms is wiped once when sealed and once when refused,
and each public operation wipes its owned value once on both paths.

ADR-0014 is amended to record the bound.

Refs #1734
@coderdan
coderdan force-pushed the refactor/stack-encrypt-plaintext-by-reference branch from fc3a506 to 620dbe4 Compare November 22, 2026 05:29
…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
Comment thread packages/stack-encrypt/fuzz/Cargo.lock Resolved
- `compose` sorted a record's output slots into the plan's order. Nothing
  reads that order: `shape_record` takes each slot by name, in the plan's
  order. The sort is removed, and with it the `==` mutant no test could
  catch.
- `Source`'s `Debug` had no test. One now checks that a lent and a given
  source both print `Source { .. }`, and nothing they hold.
- `WipeSource::wipe` for `Borrowed` dropped a borrow. Dropping a borrow does
  nothing, so replacing the body with `()` was an equivalent mutant. The
  body is now empty.

Refs #1734
Comment thread packages/stack-encrypt/src/sem/mod.rs Resolved
@coderdan
coderdan marked this pull request as ready for review November 22, 2026 06:46
@coderdan
coderdan requested a review from a team as a code owner November 22, 2026 06:46

@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 (minor findings).

@coderdan
coderdan requested a balanced review from Copilot November 22, 2026 06:47

Copilot AI 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.

🟡 Changes recommended

Owned plaintext lacks a drop guard, allowing panics in borrowed zip or owned matching paths to drop sensitive values without wiping them.

1 open issue
What changed in this PR

Refactors Stack Encrypt, the Rust engine behind the language SDKs, and EQL bindings to read plaintext by reference rather than cloning it. This addresses #1734 while preserving stored formats; dynamic rejection of byte order indexes remains in the stacked #1611.

Changes:

  • Reworks borrowed and owned operations to share plaintext reads and wipe owned inputs.
  • Replaces local date, timestamp, decimal, and ordering types with Vitamin C’s types and traits.
  • Updates EQL adapters, feature wiring, migration guidance, and regression tests.
File Description
packages/​stack-encrypt/​tests/​ui/​plaintext_needs_encrypt.stderr Records the required borrowed encryption implementation.
packages/​stack-encrypt/​tests/​ui/​pass/​query_only_and_borrowed.rs Replaces query clone bounds with EncryptRef.
packages/​stack-encrypt/​tests/​ui/​pass/​owned_without_clone.rs Checks owned operations’ capability and wipe bounds.
packages/​stack-encrypt/​tests/​ui/​pass/​owned_fan_out_without_clone.rs Adds compile coverage for clone-free fan-out.
packages/​stack-encrypt/​tests/​ui/​owned_fan_out_needs_clone.stderr Removes the obsolete clone-error snapshot.
packages/​stack-encrypt/​tests/​ui/​owned_fan_out_needs_clone.rs Removes the obsolete fan-out restriction test.
packages/​stack-encrypt/​tests/​ui/​order_term_of_an_8_bit_integer.stderr Updates ordering refusal diagnostics.
packages/​stack-encrypt/​tests/​ui/​order_term_of_an_8_bit_integer.rs Updates the ordering trait name in comments.
packages/​stack-encrypt/​tests/​ui/​op_order_on_bytes.stderr Records compile-time rejection of byte order terms.
packages/​stack-encrypt/​tests/​ui/​op_inexact_operator_needs_probabilistic.rs Adapts a custom index to WipeSource.
packages/​stack-encrypt/​tests/​ui/​field_reference_operator_not_answered.stderr Updates query-bound diagnostics.
packages/​stack-encrypt/​tests/​ui/​execution_callback.stderr Updates private-constructor diagnostics.
packages/​stack-encrypt/​tests/​ui/​divergent_context_in_target.stderr Records borrowed-mode zip diagnostics.
packages/​stack-encrypt/​tests/​ui/​derive_match_on_integer.stderr Updates derived-target bound diagnostics.
packages/​stack-encrypt/​tests/​transcode.rs Adapts custom targets to EncryptRef.
packages/​stack-encrypt/​tests/​term_serde.rs Uses the re-exported ordering trait.
packages/​stack-encrypt/​tests/​term_bytes.rs Removes unsupported typed byte-order coverage.
packages/​stack-encrypt/​tests/​record_lowering.rs Moves passthrough values through owned composition.
packages/​stack-encrypt/​tests/​owned_records.rs Uses a non-Clone plaintext wipe probe.
packages/​stack-encrypt/​tests/​ore_block.rs Migrates scalar constructors and removes byte-order tests.
packages/​stack-encrypt/​tests/​op.rs Updates custom index wipe bounds.
packages/​stack-encrypt/​tests/​index.rs Adds borrowed encryption bounds to test helpers.
packages/​stack-encrypt/​tests/​heap_hygiene.rs Updates allocation expectations for borrowed JSON.
packages/​stack-encrypt/​tests/​derive.rs Updates the ordering trait import.
packages/​stack-encrypt/​tests/​context_conformance.rs Removes reliance on frame cloning.
packages/​stack-encrypt/​tests/​conformance.rs Borrows record inputs and rebuilds query values.
packages/​stack-encrypt/​tests/​combinators.rs Adds EncryptRef to comparison helpers.
packages/​stack-encrypt/​src/​target/​transcode.rs Uses Vitamin C’s ordering bounds.
packages/​stack-encrypt/​src/​target/​source.rs Introduces shared source handling and WipeSource.
packages/​stack-encrypt/​src/​target/​mod.rs Exports source traits and documents reference reads.
packages/​stack-encrypt/​src/​target/​conversion.rs Uses the owned-description constructor.
packages/​stack-encrypt/​src/​target/​collections.rs Separates borrowed and owned collection construction.
packages/​stack-encrypt/​src/​sem/​query.rs Validates query values through borrowed encodings.
packages/​stack-encrypt/​src/​op/​mod.rs Replaces clone and local ordering bounds.
packages/​stack-encrypt/​src/​lib.rs Re-exports EncryptRef and Vitamin C’s Orderable.
packages/​stack-encrypt/​src/​json/​target.rs Adapts owned JSON target construction.
packages/​stack-encrypt/​src/​json/​plaintext.rs Removes Clone from JSON plaintext.
packages/​stack-encrypt/​src/​json/​inputs.rs Calls guarded owned JSON operations directly.
packages/​stack-encrypt/​src/​json/​derive.rs Reads documents and string leaves in place.
packages/​stack-encrypt/​src/​field_reference.rs Adapts query inputs to feature-gated scalar types.
packages/​stack-encrypt/​src/​dynamic/​value_frame.rs Removes frame cloning.
packages/​stack-encrypt/​src/​dynamic/​term.rs Borrows term inputs and preserves interim byte ordering.
packages/​stack-encrypt/​src/​dynamic/​record.rs Transfers values into owned plan execution.
packages/​stack-encrypt/​src/​dynamic/​query.rs Updates trait references and frame-based tests.
packages/​stack-encrypt/​src/​dynamic/​planned.rs Moves passthrough fields without copying.
packages/​stack-encrypt/​fuzz/​Cargo.lock Resolves newly enabled scalar dependencies.
packages/​stack-encrypt/​docs/​adr/​0014-operations-read-the-plaintext-and-at-most-one-takes-it.md Records wipe bounds and the interim dynamic byte path.
packages/​stack-encrypt/​CHANGELOG.md Documents breaking changes and migration steps.
packages/​stack-encrypt/​Cargo.toml Enables Vitamin C scalar features by default.
packages/​stack-encrypt-derive/​src/​lib.rs Updates the custom-target documentation example.
packages/​eql/​tests/​encryption/​tests/​v4_types.rs Migrates scalar fixtures and frame reuse.
packages/​eql/​tests/​encryption/​tests/​v4_terms.rs Rebuilds plaintext instead of cloning it.
packages/​eql/​tests/​encryption/​tests/​v4_range.rs Uses shared scalar fixture constructors.
packages/​eql/​tests/​encryption/​tests/​v4_owned.rs Tests clone-free owned and borrowed ciphertext creation.
packages/​eql/​tests/​encryption/​tests/​v4_ore_block.rs Rebuilds non-Clone ordered values per write.
packages/​eql/​tests/​encryption/​tests/​v4_order.rs Migrates ordered scalar fixtures.
packages/​eql/​tests/​encryption/​tests/​typed_queries.rs Removes cloning from typed query fixtures.
packages/​eql/​tests/​encryption/​tests/​record_fields.rs Removes unnecessary record clone derives.
packages/​eql/​tests/​encryption/​tests/​json_tree_owned.rs Uses a non-Clone JSON record.
packages/​eql/​tests/​encryption/​tests/​heap_hygiene.rs Checks matching borrowed and owned JSON allocations.
packages/​eql/​tests/​encryption/​tests/​common/​mod.rs Adds shared Vitamin C scalar constructors.
packages/​eql/​crates/​eql-bindings/​src/​v4/​plaintext.rs Re-exports Vitamin C scalars and OutOfRange.
packages/​eql/​crates/​eql-bindings/​src/​encryption/​query.rs Updates query adapters’ reference and wipe bounds.
packages/​eql/​crates/​eql-bindings/​src/​encryption.rs Reads ciphertext and equality inputs by reference.
packages/​eql/​crates/​eql-bindings/​README.md Updates scalar guidance and frame examples.
packages/​eql/​crates/​eql-bindings/​CHANGELOG.md Documents EQL plaintext API migration.
packages/​eql/​crates/​eql-bindings/​Cargo.toml Enables scalar features with Stack Encrypt support.
packages/​eql/​Cargo.lock Updates EQL dependency resolution.
conformance/​stack-encrypt/​values-contract.md Distinguishes typed rejection from remaining dynamic behavior.
Cargo.toml Enables Vitamin C’s keyed ordering support.
Cargo.lock Records ordering and scalar dependencies.

Review effort: Balanced

@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 26e8a745 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; rust-security agent · claude-opus-5-5; mattpocock-skills:code-review (standards, spec) · claude-opus-5-5
Skills: code-review, rust-security, mattpocock-skills:code-review, review-cross-check, review-post

Findings (10): 1 major, 9 minor — 7 inline, 3 below.

  • packages/stack-encrypt/src/target/operations.rs:86-88, 1328-1330, 1540-1543 (outside diff) minor These docs are stale. :88 says zip "is the one place that asks for [Clone]", but it now bounds only Ctx: Clone. :1330 says sealing "reads the document through one copy", which is wrong for owned encrypt_into, and for borrowed it copies only before the keyset loads. :1542 says only Owned mode takes a value that is not Clone, but Borrowed no longer needs Clone either. Source: code-review · claude-opus-5-5
  • packages/stack-encrypt/docs/adr/0009-operators-select-the-index-and-a-query-term-is-not-the-stored-term.md:602 (outside diff) minor This ADR still names op::Ordered as the ordering bound, and this PR removes it. Add a dated amendment that points to ADR 0014 and vitaminc-ore's Orderable. Source: mattpocock-skills:code-review (standards) · claude-opus-5-5
  • docs/target-directed-encryption.md:306 (outside diff) minor It still reads "Resolved: (1). S: Encrypt + Clone on the bridge", and decision 2 (:308) still describes term clones. This PR takes option (2), but the "Superseded in part" note at :4 does not say so. Source: mattpocock-skills:code-review (standards) · claude-opus-5-5

Each finding was checked against the head commit before posting. Seven findings were refuted and are not posted. One example is the removed bytes order-term unit test: stored_rows_v1.json still pins those term bytes. Open design questions, not posted: jiff/rust_decimal as default features that dynamic and the Go guest now link; the eql-bindings jiff/rust_decimal features kept as aliases; the six duplicated order Term impls in sem/mod.rs; block ORE over bytes on the dynamic path, untested since tests/ore_block.rs lost its bytes tests; and the CONTEXT.md Reader line that says no reader copies the value.


Generated by Claude Code

Comment thread packages/stack-encrypt/src/op/mod.rs Resolved
Comment thread packages/stack-encrypt/src/lib.rs Resolved
Comment thread packages/stack-encrypt/src/sem/mod.rs Resolved
- An owned value is wiped when a reader panics. `zip` runs its borrowed
  argument over an owned value before handing the value on, and a match
  term reads the value it was given. Both now hold the value in a guard
  that wipes it through `WipeSource` if it is dropped before it is taken.
  So `zip` is bounded by `WipeSource`, and a data plan's `FieldValues`
  is `Zeroize`: it clears its fields, which are frames that wipe
  themselves. Two tests count one wipe after a reader panics.
- `Source` derives `OpaqueDebug`, where it had a `Debug` of its own.
- The order term functions in `sem` collapse to one per scheme (`ore`,
  `ope`, `ore_block`), each over an order encoding. The six `Term` impls
  come from one macro, and `ope_of` and the typed wrappers go.
- The doc examples hold plaintext as the crate asks a caller to. The data
  plan and query examples put each value straight into a frame, where
  they serialised a `serde_json::Value` into a plain buffer. The derive
  examples move the value in, where they cloned it, and every example
  that decrypts text opens it into `Protected<String>`.

Refs #1734
… place

- A typed query value is wiped when its scope is refused. The three query
  sites ran the owned value through `under`, which drops a refused value.
  They use `under_field`, which wipes it, and the JSON query wipes its
  document through `PlainJson`. The JSON query operands are moved into
  their terms where they were cloned.
- `ore_block_term` takes a reference to a local value: the `'static` bound
  is gone.
- Tests: a query value refused for its scope is wiped once; an owned
  `indexed` equality term whose by-reference read panics wipes the value
  once; a date, which is not `Clone`, is sealed with a ciphertext, an
  equality term, and an order or block ORE term, owned and borrowed, and
  in a compile test; a borrowed `ore_block_term`; `Zeroize` for
  `FieldValues`, which the mutants gate found untested.
- Docs: `Orderable` says that vitaminc-ore also covers jiff's and
  rust_decimal's `Copy` types and that nothing wipes them. Three passages
  in `target/operations.rs` that still described a copy are corrected.
  ADR 0009 is amended for `op::Ordered`, the design record notes that ADR
  0014 replaced its `Clone` bound, and `CONTEXT.md` states the one copy a
  reader makes.
- Changesets: one for this PR's `eql-bindings` changes, and the two
  pending ones that described Stack Encrypt's own date types now describe
  Vitamin C's.

Refs #1734
@coderdan

Copy link
Copy Markdown
Contributor Author

Replies to the three findings in the body of the agent review (6011019053). All three are fixed in 378bbf0.

  • Stale docs in target/operations.rs: corrected in three places. Encryption's docs no longer say zip asks for Clone. JsonDocument's docs say the document is read in place, and copied once only when the keyset is not loaded yet. KeysetCipher::run no longer says owned mode is how a value that is not Clone reaches an operation.
  • ADR 0009 names op::Ordered: the ADR has a dated amendment, "Amended 2026-11-22 (refactor(stack-encrypt,eql-bindings)!: read every plaintext by reference #1737)". It points to ADR 0014 decision 5 and vitaminc-ore's Orderable.
  • docs/target-directed-encryption.md: the "Superseded in part" note now says ADR 0014 replaced option 1 with option 2. Implementation notes 1 and 2 each say they are superseded.

From the open questions: CONTEXT.md's Reader entry now states its one exception, a borrowed JSON document sealed on a keyset that is not loaded yet. The six duplicated order Term impls were already collapsed into one macro in 163b5a0.

@coderdan
coderdan merged commit 5ee2a2c into next Nov 22, 2026
68 checks passed
@coderdan
coderdan deleted the refactor/stack-encrypt-plaintext-by-reference branch November 22, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants