Skip to content

README: drop the free memory pointer alignment claim - #40

Merged
thedavidmeister merged 2 commits into
mainfrom
2026-09-03-issue-38-fmp-alignment-claim
Sep 3, 2026
Merged

thedavidmeister merged 2 commits into
mainfrom
2026-09-03-issue-38-fmp-alignment-claim

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Closes #38

README stated in three places that the allocator keeps the free memory pointer at a multiple of 32:

  • "The pattern", top: It is optimised so that the allocator always has the free memory pointer at a multiple of 32.
  • "The pattern", after the three buckets: Note that in the last case, the allocator will still move the free memory pointer to a multiple of 32 bytes even if that points past the end of the data structure.
  • "Hashing dynamic length byte strings": Even though the allocator retains a multiple of 0x20 on the free memory pointer, we MUST respect the true length ...

Alignment of the free memory pointer is not a Solidity guarantee (issue Ruling, confirmed by the Solidity team). Under this repo's own build (solc 0.8.25, legacy pipeline) bytes.concat, string.concat and abi.encodePacked allocate at exact byte size and leave the pointer unaligned; only new bytes(n) / new string(n) round up. Per the ruling the sentences are removed, not qualified per allocation form or pipeline. The issue names two sentences; the first bullet above is the title's claim verbatim ("always has the free memory pointer at a multiple of 32"), so all three go.

The hex"01" / hex"0100" example in "Hashing dynamic length byte strings" leaned on the removed premise ("they both have 0x20 bytes allocated to them"). It is reworded so the injectivity argument rests on the read length (rounding the length up to whole words would hash the same word for both when nothing has been written past them), and it now states what the pattern actually relies on: it hashes exactly length bytes and reads nothing past the data, so what the allocator does beyond it, including where it leaves the free memory pointer, is irrelevant. On the rewritten line, "whole-world lengths" is corrected to "whole-word lengths".

test/MemoryLayout.t.sol: testBytesAllocationRoundsUpToWords, testBytesAllocationRoundsUpToWordsForAnyLength and testNewStringAllocatesLikeNewBytes pin new bytes(n) / new string(n) rounding, which stays true, and their NatSpec does not cite the removed README sentences; unchanged. No source or test files change.

Also reworded two NatSpec lines in test/MemoryLayout.t.sol that restated the removed claim: the contract doc no longer says the tests pin "claims README.md makes", and the rounding test says new bytes(n) allocates whole words rather than "the allocator rounds bytes up".

QA

  • Discriminating tests: n/a — docs-only PR; no code or test changes to discriminate.
  • Mutations applied: n/a — docs-only PR; nothing to mutate.
  • Oracle: the issue's measured table (legacy pipeline: bytes.concat(hex"01", hex"02") moves the free memory pointer by 34, abi.encodePacked(uint8(7)) by 33, new bytes(2) by 64, pointer mod 32 = 2 after the concat; --via-ir 64/64/64/0) and the Solidity team's statement quoted in the issue's Ruling that free memory pointer alignment is not a guarantee. The legacy row is reproduced on this branch in the CI sol-shell (rainix dbcd9d3, solc 0.8.25): 34 / 33 / 64 / mod 32 = 2; memory literals hex"01" and hex"0100" each move the pointer by 64, so the old example's "0x20 bytes allocated" was true for literals only. The repro test is not committed: it would pin an implementation detail the compiler does not promise.
  • Category check: issue asks to remove the README's allocator-alignment claim (two sentences named, ruling: remove rather than qualify); covered all three occurrences of the claim and the one example sentence that depended on it, and checked the committed new bytes(n) tests' NatSpec for citations of the removed text (none).

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvfmeRQKubdbFW1GL3kmib

Alignment of the free memory pointer is not a Solidity guarantee: under
the legacy pipeline bytes.concat, string.concat and abi.encodePacked
allocate at exact size and leave the pointer unaligned. Remove the three
sentences that stated the allocator keeps it at a multiple of 32, and
reword the hex"01"/hex"0100" example so the injectivity argument rests on
the read length rather than on allocation rounding. The pattern hashes
exactly `length` bytes and never reads past the data.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FvfmeRQKubdbFW1GL3kmib
@thedavidmeister thedavidmeister self-assigned this Sep 3, 2026
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: be9650cd-5a42-4458-81a2-d1f8a10b093f

📥 Commits

Reviewing files that changed from the base of the PR and between f1342db and 8fb53b7.

📒 Files selected for processing (2)
  • README.md
  • test/MemoryLayout.t.sol

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

1 participant