Skip to content

Fix slice offset semantics in pointers-react mockState#178

Merged
gnidan merged 1 commit into
mainfrom
debugger-fix-mockstate-slice
Mar 9, 2026
Merged

Fix slice offset semantics in pointers-react mockState#178
gnidan merged 1 commit into
mainfrom
debugger-fix-mockstate-slice

Conversation

@gnidan

@gnidan gnidan commented Mar 9, 2026

Copy link
Copy Markdown
Member

The createMockState adapter in packages/pointers-react/src/utils/mockState.ts used a right-aligned big-endian calculation (32 - offset - length) for stack, storage, and transient slice offsets. This is incorrect — the Machine.State interface treats slice.offset as a direct byte offset from the start of the 32-byte word.

Changed all three locations (stack peek, storage read, transient read) to use data.slice(offset, offset + length), matching the convention used by:

The createMockState adapter used a right-aligned big-endian
calculation (32 - offset - length) for stack, storage, and
transient slice offsets. The correct convention is direct
byte offset from the start of the word, matching the
ganache test adapter and evm machine adapter.
@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-03-09 20:31 UTC

@gnidan

gnidan commented Mar 9, 2026

Copy link
Copy Markdown
Member Author

Reviewed — this looks correct. The fix changes from right-aligned big-endian calculation (32 - offset - length) to direct byte offset (slice(offset, offset + length)).

Verified this matches the convention in all other Machine.State adapters:

  • packages/pointers/test/ganache.tsdata.slice(Number(offset), Number(offset + length)) for stack, memory, and storage
  • packages/evm/src/machine.ts — same pattern in all 4 slice locations (stack, memory, storage, code)
  • packages/programs-react/src/utils/traceState.ts — fixed in PR Wire TraceProvider variable resolution to @ethdebug/pointers #175

All three locations in mockState.ts (stack peek, storage read, transient read) are consistently fixed. No issues found.

@gnidan
gnidan merged commit aaed7fb into main Mar 9, 2026
4 checks passed
@gnidan
gnidan deleted the debugger-fix-mockstate-slice branch March 9, 2026 20:26
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