Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVSVCS-147: link balance monitor updates #14108

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/.changeset/nasty-llamas-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/contracts': patch
---

DEVSVCS-147: add a reentrancy guard for balance monitor
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
error InvalidWatchList();
error InvalidChainSelector();
error DuplicateAddress(address duplicate);
error ReentrantCall();

struct MonitoredAddress {
uint96 minBalance;
Expand Down Expand Up @@ -94,6 +95,8 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
/// whenever a new one is deployed with the same dstChainSelector.
EnumerableMap.UintToAddressMap private s_onRampAddresses;

bool private reentrancyGuard;

/// @param admin is the administrator address of this contract
/// @param linkToken the LINK token address
/// @param minWaitPeriodSeconds represents the amount of time that has to wait a contract to be funded
Expand All @@ -116,6 +119,7 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
setMaxPerform(maxPerform);
setMaxCheck(maxCheck);
setUpkeepInterval(upkeepInterval);
reentrancyGuard = false;
}

/// @notice Sets the list of subscriptions to watch and their funding parameters
Expand Down Expand Up @@ -259,7 +263,7 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter

/// @notice tries to fund an array of target addresses, checking if they're underfunded in the process
/// @param targetAddresses is an array of contract addresses to be funded in case they're underfunded
function topUp(address[] memory targetAddresses) public whenNotPaused {
function topUp(address[] memory targetAddresses) public whenNotPaused nonReentrant {
MonitoredAddress memory contractToFund;
uint256 minWaitPeriod = s_minWaitPeriodSeconds;
uint256 localBalance = i_linkToken.balanceOf(address(this));
Expand Down Expand Up @@ -457,6 +461,13 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
_;
}

modifier nonReentrant() {
if (reentrancyGuard) revert ReentrantCall();
reentrancyGuard = true;
_;
reentrancyGuard = false;
}

/// @notice Pause the contract, which prevents executing performUpkeep
function pause() external onlyRole(ADMIN_ROLE) {
_pause();
Expand Down
Loading