Skip to content

Rewrite concat using tuples - #563

Draft
axic wants to merge 7 commits into
argotorg:mainfrom
axic:concat-tuple
Draft

Rewrite concat using tuples#563
axic wants to merge 7 commits into
argotorg:mainfrom
axic:concat-tuple

Conversation

@axic

@axic axic commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

No description provided.

axic and others added 7 commits August 25, 2026 12:01
Memory-store wrappers (std.opcodes mstore/mstore8) have bodies of the form
`assembly { mstore(a, b) }`. asmIsInterpretable whitelists mstore/mstore8 so
comptime scratch-memory blocks stay foldable, which caused computePureFuns to
classify the mstore wrapper — and therefore any caller whose only effect is a
call to it — as pure.

The concat rewrite exposed the resulting unsoundness: the new MemoryEncode
instances for bytes32/uint256 do their work via `mstore(target, rep(v))` and
`return 32` (a compile-time constant). Being "pure", these encodeInto calls
were folded by tryInline/evalFunBody to their constant byte count, and the
mstore statement was silently dropped (evalFunBody skips MastStmtExp). concat
then wrote the correct length but left the payload zeroed — e.g.
concat_b32_b32 returned 64 zero bytes instead of the two operands. The
memory(bytes) instances were unaffected because they use mcopy, which is not
whitelisted as interpretable.

Mark the mstore/mstore8 wrappers impure so their callers stay out of pureFuns
and the writes survive partial evaluation. This is narrow: asmIsInterpretable
is untouched (direct comptime asm folding and the comptime-check read-exclusion
are unchanged), and mcopy/sstore/log* wrappers were already impure — only the
two whitelisted store ops needed correcting.

Co-Authored-By: Alex Beregszaszi <alex@rtfs.hu>
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