Skip to content

Utility lib#162

Open
mgretzke wants to merge 20 commits intomainfrom
utility-lib
Open

Utility lib#162
mgretzke wants to merge 20 commits intomainfrom
utility-lib

Conversation

@mgretzke
Copy link
Copy Markdown
Collaborator

@mgretzke mgretzke commented Nov 5, 2025

Added the UtilityLib:

  • Allows checking if the current chain supports eip-1153 (transient storage).
  • Adds settledBalanceOf to retrieve an ERC6909 balance from the compact. The function reverts in case the compacts reentrancy guard is active.

@mgretzke mgretzke requested review from 0age and ccashwell November 5, 2025 12:49
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 87.87879% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/utility/Utility.sol 87.87% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!


/// @notice Returns the users balance only if reentrancy protection is not active on the Compact. This eliminates in flight balances before the ERC6909 tokens were burned.
/// @dev Only if eip-1153 (transient storage) is not available.
function settledBalanceOf_nonTransient(address owner, uint256 id) internal view returns (uint256 amount) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this one, if we want to go try-hard on it we could derive the balance slot and use the batch extsload function to get both values in one call

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Not sure how much more efficient this will be though? it will at least lead to higher revert costs, since both values will be read from storage not knowing, if we even need the balance.

Copy link
Copy Markdown
Contributor

@0age 0age left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good! left some comments, the major thing i think this is still missing is a helper function for handling the case where tstore isn't supported yet but may become supported, and probably also a helper that makes it dead-simple for integrators (basically giving them a "settledBalanceOf" function that will select the appropriate function under the hood)

effectively, you'd have:

  • logic in the constructor to check if tstore is supported (which already has a helper implemented) and if so just assign the current settledBalanceOf as the balance check fn from the get-go
  • logic in the alternative balance check contract to handle cases where tstore got activated at a later point; I feel like the most straightforward move here is to just read both the tstore slot and the sstore slot and if either is set to revert (IMHO you'd be hard-pressed to find a chain that doesn't support tstore yet where execution isn't dirt-cheap)

@mgretzke mgretzke requested a review from 0age November 6, 2025 14:15
0age
0age previously approved these changes Nov 13, 2025
@mgretzke mgretzke requested a review from 0age January 5, 2026 16:56
Copy link
Copy Markdown
Contributor

@0age 0age left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny comment suggestion

pop(staticcall(gas(), THE_COMPACT, 0x1c, 0x24, 0, 0x20))
reentrancySlotContent := mload(0)

// We do not need to check for success.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit on comments: the convention is to avoid "we" and instead just be declarative / talk about what is happening

revert BalanceNotSettled();
}

// If we get here, the balance is settled, so returning the balance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

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