Skip to content

std: add evm::packed — tightly packed byte encoding (abi.encodePacked…#1512

Merged
sbillig merged 2 commits into
argotorg:masterfrom
cburgdorf:packed
Jul 10, 2026
Merged

std: add evm::packed — tightly packed byte encoding (abi.encodePacked…#1512
sbillig merged 2 commits into
argotorg:masterfrom
cburgdorf:packed

Conversation

@cburgdorf

@cburgdorf cburgdorf commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

std: add evm::packed — tightly packed byte encoding (abi.encodePacked parity)
Adds std::evm::packed with two layers:

  • A declarative tuple API: an EncodePacked trait with encode_packed /
    keccak_packed entry points, implemented for u8-u256, i8-i256 (two's
    complement), bool, Address, String (effective len() bytes),
    [u8; N], FixedBytes, Bytes, BytesView, and tuples of
    arity 1..=16, so keccak_packed((token0, token1)) covers CREATE2
    salts and EIP-712 digests with zero size bookkeeping.
  • An imperative Packed builder for runtime-shaped payloads, with
    byte-precise writes (full-word mstore fast path only when a whole
    word fits below the buffer limit, mstore8 fallback otherwise) and
    copy-on-grow doubling, plus keccak256/sha256/as_bytes terminals.

Also adds crypto::eip712_digest built on the tuple API.

Fixes a codegen bug this exposed: a tuple/struct const region holding
a String literal of 16 bytes or fewer crashed Sonatina emission
("global initializer immediate type does not match global type") —
the aggregate field type is always I256 while the immediate was typed
from the literal's byte length. gv_initializer_for_const now threads
the layout's per-field RuntimeClass down to immediate_for_const, which
types FixedBytes immediates from the declared class width. As a side
effect, string constants emit as direct .i256 immediates instead of a
small immediate plus zext (two sonatina_ir snapshots updated).

The packed_encoding fixture's expected values are all precomputed with
Foundry (cast abi-encode --packed / cast keccak), so the tests are not
their own oracle. string_in_tuple is a minimal regression fixture for
the codegen fix.

@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 1f35a3e008

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ut class

A tuple/struct const region holding a String<N> literal of 16 bytes or
fewer crashed Sonatina emission ("global initializer immediate type
does not match global type") — the aggregate field type is always I256
while the immediate was typed from the literal's byte length.
gv_initializer_for_const now threads the layout's per-field
RuntimeClass down to immediate_for_const, which types FixedBytes
immediates from the declared class width.

As a side effect, string constants emit as direct .i256 immediates
instead of a small immediate plus zext (two sonatina_ir snapshots
updated). string_in_tuple is a minimal regression fixture.
@cburgdorf cburgdorf marked this pull request as ready for review July 8, 2026 16:32
@cburgdorf cburgdorf requested a review from sbillig July 8, 2026 16:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b44de4c3eb

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ingots/std/src/evm/packed.fe
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4b14b8793

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ingots/std/src/evm/packed.fe
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 372f37d4d1

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ingots/std/src/evm/packed.fe
… parity)

Adds std::evm::packed with two layers:

- A declarative tuple API: an EncodePacked trait with encode_packed /
  keccak_packed entry points, implemented for u8-u256, i8-i256 (two's
  complement), bool, Address, String<N> (effective len() bytes),
  [u8; N], FixedBytes<N>, Bytes, BytesView<MemoryInput>, and tuples of
  arity 1..=16, so `keccak_packed((token0, token1))` covers CREATE2
  salts and EIP-712 digests with zero size bookkeeping.
- An imperative Packed builder for runtime-shaped payloads, with
  byte-precise writes (full-word mstore fast path only when a whole
  word fits below the buffer limit, mstore8 fallback otherwise) and
  copy-on-grow doubling, plus keccak256/sha256/as_bytes terminals.

Also adds crypto::eip712_digest built on the tuple API.

Builds on the preceding codegen fix for String<N> literals in const
tuple regions, which this module's tests exposed.

The packed_encoding fixture's expected values are all precomputed with
Foundry (cast abi-encode --packed / cast keccak), so the tests are not
their own oracle.
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d0a6648037

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@sbillig ready to review now. There's a codegen fix in a separate commit

@sbillig sbillig merged commit d1ee9eb into argotorg:master Jul 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants