Skip to content

solidity: mark generated assembly block as memory-safe#99

Merged
ma2bd merged 1 commit into
zefchain:mainfrom
afck:solidity-memory-safe-assembly
May 18, 2026
Merged

solidity: mark generated assembly block as memory-safe#99
ma2bd merged 1 commit into
zefchain:mainfrom
afck:solidity-memory-safe-assembly

Conversation

@afck
Copy link
Copy Markdown
Contributor

@afck afck commented May 18, 2026

Summary

The BytesN codegen path emits a one-line mload inside an assembly block to read a fixed-size byte array out of a bytes memory argument. The block reads memory only, does not touch the free memory pointer (0x40) or the zero slot (0x60), and never writes outside the function's allocated memory — so it satisfies the Solidity memory-safety contract documented at
https://docs.soliditylang.org/en/latest/assembly.html#memory-safety.

Annotating it accordingly lets the IR optimizer spill registers freely. Without the annotation, callers that inline the deserializer tree can hit "stack too deep" once the input contract grows; we observed this in linera-io/linera-protocol#6294.

This is the only assembly { ... } emission in the Solidity backend.

Test Plan

linera-io/linera-protocol#6294 works with this branch of serde-refliection.

The `BytesN` codegen path emits a one-line `mload` inside an `assembly`
block to read a fixed-size byte array out of a `bytes memory` argument.
The block reads memory only, does not touch the free memory pointer
(`0x40`) or the zero slot (`0x60`), and never writes outside the
function's allocated memory — so it satisfies the Solidity memory-safety
contract documented at
https://docs.soliditylang.org/en/latest/assembly.html#memory-safety.

Annotating it accordingly lets the IR optimizer spill registers freely.
Without the annotation, callers that inline the deserializer tree can
hit "stack too deep" once the input contract grows; we observed this
in a downstream project where a verifier function inlined enough of the
generated deserialization helpers to exceed the 16-slot stack.

This is the only `assembly { ... }` emission in the Solidity backend.
@afck afck requested a review from ma2bd as a code owner May 18, 2026 12:18
@ma2bd ma2bd merged commit d307272 into zefchain:main May 18, 2026
14 checks passed
@afck afck deleted the solidity-memory-safe-assembly branch May 18, 2026 13:40
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.

3 participants