Skip to content

stack-encrypt: a value with a ciphertext and terms is copied, so Stack Encrypt keeps its own copies of Vitamin C's Date, Timestamp and Decimal — read plaintext by reference #1734

Closed

Description

@coderdan

How Stack Encrypt handles plaintext today

Stack Encrypt (packages/stack-encrypt) is the Rust engine that every CipherStash language SDK runs on. It encrypts values with Vitamin C (cipherstash/vitaminc), CipherStash's Rust cryptography library.

A plaintext type in Vitamin C is deliberately not Clone. A copy that nobody tracks is a copy nobody wipes. Vitamin C 0.10 gives Stack Encrypt what it needs to read a plaintext by reference instead of copying it:

Stack Encrypt moves to Vitamin C 0.10 in #1732. It does not use these yet.

Problem: Stack Encrypt still copies plaintext, and keeps its own copies of Vitamin C's types

Stack Encrypt still needs a plaintext to be Clone wherever one value feeds more than one output. A date field with a ciphertext and an order term is one example. These are the places, at the top of the stack that ends in #1687:

  • target/source.rs: ShareSource for Owned clones a value for every output but the last. ConsumeSource for Borrowed clones before each output.
  • op/mod.rs: an equality query copies its value to check it, and again to derive the term.
  • dynamic/term.rs: the term the Go SDK asks for copies its value for two checks.
  • eql-bindings: the Ciphertext and Hmac256 targets (encryption.rs), and the query targets (encryption/query.rs), bound their plaintext on Clone.

#1666 removes the plan builder and chain, where most of the bounds were. The list above is what remains.

Because of that bound, Stack Encrypt keeps its own value::Date, value::Timestamp, and value::Decimal. They duplicate Vitamin C's types, only so that they can be Clone. value.rs says so. That has two effects:

  • Each copy of a plaintext is one more thing to wipe. Some of these copies are wiped, but the design depends on every clone being wiped correctly.
  • vitaminc-ore's Orderable is sealed. It covers Vitamin C's Date, Timestamp, and Decimal, but not Stack Encrypt's copies. So fix(stack-encrypt)!: a data plan refuses an order index on bytes #1611 cannot use it, and keeps two traits of its own: sem::Orderable and op::Ordered.

Proposal: read every plaintext by reference

  1. No public bound in Stack Encrypt or eql-bindings requires a plaintext to be Clone. This covers the typed path, field markers, the EQL types, and the dynamic engine.
  2. One value that feeds several outputs is read in place, or taken once and wiped once. It is not copied.
  3. Stack Encrypt's Date, Timestamp, and Decimal are removed. Callers use Vitamin C's types.
  4. An order index is bounded by vitaminc-ore's Orderable. Stack Encrypt's own sem::Orderable and op::Ordered are removed.
  5. The stored format does not change. The frozen vectors, the stored-row fixtures, and the conformance corpus pass unchanged.
  6. A test shows that a value with a ciphertext and several terms is not copied.

Relationship to other work

Activity

  1. added
    enhancement
    rust
    on Nov 20, 2026
  2. self-assigned this
    on Nov 20, 2026
  3. coderdan commented on Nov 21, 2026

    @coderdan
    ContributorAuthor

    A design for this is proposed as ADR-0014 in #1739 (draft, stacked on #1687).

    In short: an operation reads the plaintext through a reference (a "reader"), at most one operation takes it by value (a "taker"), and the compiler checks that. Nothing in the library turns "take" into "clone", so a declaration that would copy the plaintext does not compile. The idea comes from how axum checks the order of a handler's extractors.

    Three places that copy are not in the list above. They were found while reviewing #1664 and #1687:

    • The default owned form. EncryptTarget::owned_encryption defaults to "guard the value, then run the borrowed form over a reference". So every target that writes only encryption() clones on each encrypt_into, and nothing in its declaration says so. This is how the same copy reached three different types.
    • Types with one ciphertext and no term. JsonTreeDocument, the storage-only Json, and a Go JsonSearch write (encrypt_document in eql-bindings) each hold two copies of the whole document while it is sealed. The other ten storage-only EQL types (Integer, Text, and so on) hold two copies of a small value. feat(stack-encrypt,eql-bindings): typed JSON queries from a field reference #1687 fixes these one type at a time, with owned overrides.
    • A plain encrypt field of a data plan. Verb::Encrypt in dynamic/planned.rs runs ciphertext::<ValueFrame, K, Borrowed>, which clones the field's value. feat(stack-encrypt,eql-bindings): typed JSON queries from a field reference #1687 does not fix this one. It falls under item 1 of the proposal here ("the dynamic engine").

    The ADR lists four questions for a prototype to answer before it is accepted.

  4. 4 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

SDKenhancementrust

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions