Skip to content

Blake2f: compress a copy of the state, not the caller's Bytes - #220

Open
anvacaru wants to merge 2 commits into
masterfrom
blake2f-copy-state
Open

Blake2f: compress a copy of the state, not the caller's Bytes#220
anvacaru wants to merge 2 commits into
masterfrom
blake2f-copy-state

Conversation

@anvacaru

Copy link
Copy Markdown
Contributor

Changes:

  • plugin-c/crypto.cpp: copy the 64-byte blake2 state to a local buffer before compressing.

  • krypto/src/tests/integration: regression test that fails when the hook mutates its argument.

    • The new Blake2CompressNoAliasing case fails against the pre-fix hook and passes after it; the other Blake2 cases pass in both states, since the return value was never wrong.

anvacaru and others added 2 commits July 27, 2026 19:04
…ler's Bytes

blake2b_compress updates the state vector h in place; hook_KRYPTO_blake2compress
pointed h straight into params->data, mutating the K Bytes object passed to the
hook. Bytes terms can be structure-shared on the LLVM backend heap, so the
in-place update corrupted unrelated terms sharing the buffer (observed as
BLAKE2b IV bytes appearing inside a transaction's calldata term in
evm-semantics conformance runs). Copy the 64-byte state to a local buffer and
compress that.
…iasing

The existing Blake2Compress test only checks the hook's return value, which
was correct even while the hook mutated the Bytes it was given. blake2NoAlias
passes one Bytes term to Blake2Compress and to the check that follows it, so
an in-place update of the argument is observable: it is false before
996c251 and true after.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant