-
Notifications
You must be signed in to change notification settings - Fork 124
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
(chore): Parameterize the BalanceTracker version #123
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ contract BalanceTrackerTest is CommonTest { | |
event SentProfit(address indexed _profitWallet, bool indexed _success, uint256 _balanceSent); | ||
event ReceivedFunds(address indexed _sender, uint256 _amount); | ||
|
||
uint8 constant VERSION = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to set it to 2 to match what was in the contract previously? |
||
uint256 constant MAX_SYSTEM_ADDRESS_COUNT = 20; | ||
uint256 constant INITIAL_BALANCE_TRACKER_BALANCE = 2_000 ether; | ||
|
||
|
@@ -58,7 +59,7 @@ contract BalanceTrackerTest is CommonTest { | |
function test_initializer_fail_systemAddresses_zeroLength() external { | ||
delete systemAddresses; | ||
vm.expectRevert("BalanceTracker: systemAddresses cannot have a length of zero"); | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
} | ||
|
||
function test_initializer_fail_systemAddresses_greaterThanMaxLength() external { | ||
|
@@ -67,32 +68,32 @@ contract BalanceTrackerTest is CommonTest { | |
} | ||
|
||
vm.expectRevert("BalanceTracker: systemAddresses cannot have a length greater than 20"); | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
} | ||
|
||
function test_initializer_fail_systemAddresses_lengthNotEqualToTargetBalancesLength() external { | ||
systemAddresses.push(payable(address(0))); | ||
|
||
vm.expectRevert("BalanceTracker: systemAddresses and targetBalances length must be equal"); | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
} | ||
|
||
function test_initializer_fail_systemAddresses_containsZeroAddress() external { | ||
systemAddresses[1] = payable(address(0)); | ||
|
||
vm.expectRevert("BalanceTracker: systemAddresses cannot contain address(0)"); | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
} | ||
|
||
function test_initializer_fail_targetBalances_containsZero() external { | ||
targetBalances[1] = ZERO_VALUE; | ||
|
||
vm.expectRevert("BalanceTracker: targetBalances cannot contain 0 target"); | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
} | ||
|
||
function test_initializer_success() external { | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
|
||
assertEq(balanceTracker.systemAddresses(0), systemAddresses[0]); | ||
assertEq(balanceTracker.systemAddresses(1), systemAddresses[1]); | ||
|
@@ -105,7 +106,7 @@ contract BalanceTrackerTest is CommonTest { | |
uint256 expectedProfitWalletBalance = INITIAL_BALANCE_TRACKER_BALANCE - l2OutputProposerTargetBalance; | ||
address payable reentrancySystemAddress = payable(address(new ReenterProcessFees())); | ||
systemAddresses[0] = reentrancySystemAddress; | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
|
||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
emit ProcessedFunds(reentrancySystemAddress, false, batchSenderTargetBalance, batchSenderTargetBalance); | ||
|
@@ -131,7 +132,7 @@ contract BalanceTrackerTest is CommonTest { | |
function test_processFees_success_continuesWhenSystemAddressReverts() external { | ||
vm.deal(address(balanceTracker), INITIAL_BALANCE_TRACKER_BALANCE); | ||
uint256 expectedProfitWalletBalance = INITIAL_BALANCE_TRACKER_BALANCE - l2OutputProposerTargetBalance; | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
vm.mockCallRevert(batchSender, bytes(""), abi.encode("revert message")); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
emit ProcessedFunds(batchSender, false, batchSenderTargetBalance, batchSenderTargetBalance); | ||
|
@@ -152,7 +153,7 @@ contract BalanceTrackerTest is CommonTest { | |
vm.deal(address(balanceTracker), INITIAL_BALANCE_TRACKER_BALANCE); | ||
uint256 expectedProfitWalletBalance = | ||
INITIAL_BALANCE_TRACKER_BALANCE - batchSenderTargetBalance - l2OutputProposerTargetBalance; | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
emit ProcessedFunds(batchSender, true, batchSenderTargetBalance, batchSenderTargetBalance); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
|
@@ -169,7 +170,7 @@ contract BalanceTrackerTest is CommonTest { | |
} | ||
|
||
function test_processFees_success_noFunds() external { | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
emit ProcessedFunds(batchSender, true, batchSenderTargetBalance, ZERO_VALUE); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
|
@@ -188,7 +189,7 @@ contract BalanceTrackerTest is CommonTest { | |
function test_processFees_success_partialFunds() external { | ||
uint256 partialBalanceTrackerBalance = INITIAL_BALANCE_TRACKER_BALANCE / 3; | ||
vm.deal(address(balanceTracker), partialBalanceTrackerBalance); | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
emit ProcessedFunds(batchSender, true, batchSenderTargetBalance, partialBalanceTrackerBalance); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
|
@@ -208,7 +209,7 @@ contract BalanceTrackerTest is CommonTest { | |
vm.deal(address(balanceTracker), INITIAL_BALANCE_TRACKER_BALANCE); | ||
vm.deal(batchSender, batchSenderTargetBalance); | ||
vm.deal(l2OutputProposer, l2OutputProposerTargetBalance); | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
emit ProcessedFunds(batchSender, false, ZERO_VALUE, ZERO_VALUE); | ||
vm.expectEmit(true, true, true, true, address(balanceTracker)); | ||
|
@@ -232,7 +233,7 @@ contract BalanceTrackerTest is CommonTest { | |
systemAddresses.push(payable(address(uint160(i + 100)))); | ||
targetBalances.push(l2OutputProposerTargetBalance); | ||
} | ||
balanceTracker.initialize(systemAddresses, targetBalances); | ||
balanceTracker.initialize(systemAddresses, targetBalances, VERSION); | ||
|
||
balanceTracker.processFees(); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not see any access control on the
initialize()
function. Now that_version
is a user-supplied parameter, this seems to allow arbitrary reinitialization by any caller who provides a higher version number.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, perhaps we want a way to just change the addresses without having to call initialize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if this was hardcoded (like before this PR), it'd have to be incremented every time we need to update the addresses, but nothing about the core implementation actually changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is that the previous
reinitializer(2)
prevented it from being reinitialized. Now that it usesreinitializer(_version)
, I think anyone could reinitialize the contract.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would still need to enforce access control on who can update those addresses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow yeah good catch. So you think we should make it ownable and add a setter function instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not worth the trouble actually - inheriting a new contract could screw up the storage layout making it not feasible to upgrade. We'd have to add custom logic