Skip to content

✨ Add TBytes32Stack to LibTransient (issue #1185)#1542

Open
BhariGowda wants to merge 1 commit into
Vectorized:mainfrom
BhariGowda:feat/transient-bytes32-stack
Open

✨ Add TBytes32Stack to LibTransient (issue #1185)#1542
BhariGowda wants to merge 1 commit into
Vectorized:mainfrom
BhariGowda:feat/transient-bytes32-stack

Conversation

@BhariGowda

Copy link
Copy Markdown
Contributor

Closes #1185

Adds TBytes32Stack a transient storage value stack for bytes32.

Unlike TStack (which generates typed pointers), this stores values directly.

API

  • tBytes32Stack(bytes32/uint256) → pointer
  • push(ptr, bytes32) store value
  • pop(ptr) → remove and return top (reverts if empty)
  • top(ptr) → peek top (reverts if empty)
  • top(ptr, uint256 i) → i-th from top, 0=top
  • size(ptr) → element count
  • clear(ptr) → reset stack

Design

  • Pure assembly, TSTORE/TLOAD
  • Reuses existing StackIsEmpty error
  • Element stride: _STACK_BASE_SALT * slot + ((i+1) << 32)
  • clear() zeroes size only — push always writes before read, no stale values

Tests

7 new tests concrete, fuzz, collision, 3 revert cases
Run: FOUNDRY_PROFILE=post_osaka forge test --match-path test/LibTransient.t.sol
29 passed, 0 failed

@github-actions

Copy link
Copy Markdown

Gas Snapshot Comparison Report

Generated at commit : a723db1, Compared to commit : ab96a83

Contract Name Test Name Main Gas PR Gas Diff
LibRLPWithCLZTest testComputeAddressForLargeNonces() 1750 - -
testComputeAddressForSmallNonces() 997 - -
testComputeAddressOriginalForLargeNonces() 3495 - -
testComputeAddressOriginalForSmallNonces() 2088 - -
testRLPEncodeBytes() 250090 - -
testRLPEncodeBytes2() 155904 - -
testRLPEncodeList() 735942 - -
testRLPEncodeList2() 810708 - -
testRLPEncodeListEdgeCases() 1807743 - -
testRLPEncodeStringEdgeCases() 20424 - -
testRLPEncodeUint() 1175570 - -
testRLPPUint256() 363834 - -
test__codesize() 18292 - -
LibTransientTest testEmptyStackPopReverts() 3908 3942 34
testEmptyStackTopReverts() 3879 3946 67
testRegistryAB() 429436 429381 -55
testRegistryNotDeployed() 72369 72391 22
testSetAndGetBytesTransient() 51071 51115 44
testStackPlacePopBytes() 37865 37909 44
testUint256IncDecTransient() 123992 124436 444
test__codesize() 23261 25345 2084
testBytes32StackPushPop() - 4544 -
testEmptyBytes32StackPopReverts() - 3933 -
testEmptyBytes32StackTopIndexReverts() - 4362 -
testEmptyBytes32StackTopReverts() - 3939 -

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.

✨ LibTransient TStack

1 participant