Skip to content

Conversation

@nicholaspai
Copy link
Member

No description provided.

// Since _exchangeRateCurrent() reads this contract's balance and updates contract state using it, it must be
// first before transferring any tokens to this contract to ensure synchronization.
uint256 lpTokensToMint = (l1TokenAmount * 1e18) / _exchangeRateCurrent(l1Token);
ExpandedIERC20(pooledTokens[l1Token].lpToken).mint(msg.sender, lpTokensToMint);
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved token transfer "interaction" after any effects to follow CEI

Copy link
Member

Choose a reason for hiding this comment

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

nice. doing this + having the guard is best posible. importantly, you are doing this after the calls that modify tracking state so no risk in this change.

// If they try access more funds than available (i.e l1TokensToReturn > liquidReserves) this will underflow.
pooledTokens[l1Token].liquidReserves -= l1TokensToReturn;

ExpandedIERC20(pooledTokens[l1Token].lpToken).burnFrom(msg.sender, lpTokenAmount);
Copy link
Member Author

Choose a reason for hiding this comment

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

rearranging for CEI

});

// Finally, delete the state pertaining to the active proposal so that another proposer can submit a new bundle.
delete rootBundleProposal;
Copy link
Member Author

Choose a reason for hiding this comment

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

rearranging for CEI

@nicholaspai nicholaspai changed the title improve: Add reentrancy guards to all public methods improve: [L06] Add reentrancy guards to all public methods Mar 15, 2022

// Apply AVM-specific transformation to cross domain admin address on L1.
function _requireAdminSender() internal override onlyFromCrossDomainAdmin {}
function _requireAdminSender() internal override onlyFromCrossDomainAdmin nonReentrant {}
Copy link
Member

Choose a reason for hiding this comment

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

so this is an internal method. why add it here? dont we only need it on the external/public functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes i'll add a comment. Basically we don't add the nonReentrant modifier to onlyAdmin functions in the base SpokePool contract because the Polygon_SpokePool will call these methods internally via the processMessageFromRoot. The other spoke pools like Optimism_SpokePool and Arbitrum_SpokePool have their admin functions triggered by an external contract so we should be reentrancy guarding those methods. However, in the Polygon_SpokePool case we need to reentrancy guard at the processMessageFromRoot method instead of at the admin functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

But this isn't equivalent to adding a re-entrancy guard to the admin function, right? It guarantees that this function wasn't re-entered, but it doesn't help us if that admin function re-enters a different function since it doesn't wrap the entire method, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah good point

Copy link
Contributor

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

I think it's going to be difficult to make all the spoke pool admin methods non-reentrant when they're all called in such different ways.

The issue raised by OZ specifically applies to the HubPool, not the SpokePool right? So are these changes beyond the scope of the changes being requested?


// Apply AVM-specific transformation to cross domain admin address on L1.
function _requireAdminSender() internal override onlyFromCrossDomainAdmin {}
function _requireAdminSender() internal override onlyFromCrossDomainAdmin nonReentrant {}
Copy link
Contributor

Choose a reason for hiding this comment

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

But this isn't equivalent to adding a re-entrancy guard to the admin function, right? It guarantees that this function wasn't re-entered, but it doesn't help us if that admin function re-enters a different function since it doesn't wrap the entire method, no?

Copy link
Contributor

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

4 participants