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

fix AcceptAdmin deploy script for resumes #1056

Open
wants to merge 3 commits into
base: release-v25-protocol-defense
Choose a base branch
from
Open
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
73 changes: 52 additions & 21 deletions l1-contracts/deploy-scripts/AcceptAdmin.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,70 @@
// This function should be called by the owner to accept the admin role
function governanceAcceptOwner(address governor, address target) public {
Ownable2Step adminContract = Ownable2Step(target);
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: abi.encodeCall(adminContract.acceptOwnership, ()),
_value: 0,
_delay: 0
});
bytes memory data = abi.encodeCall(adminContract.acceptOwnership, ());
//Only execute if the operation does not exist yet
if (!Utils.governanceOperationExists(governor, target, 0, data, bytes32(0), bytes32(0))) {

Check failure on line 36 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 36 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 36 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: data,
_value: 0,
_delay: 0
});
}
}

// This function should be called by the owner to accept the admin role
function governanceAcceptAdmin(address governor, address target) public {
IZkSyncHyperchain adminContract = IZkSyncHyperchain(target);
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: abi.encodeCall(adminContract.acceptAdmin, ()),
_value: 0,
_delay: 0
});
bytes memory data = abi.encodeCall(adminContract.acceptAdmin, ());
//Only execute if the operation does not exist yet
if (!Utils.governanceOperationExists(governor, target, 0, data, bytes32(0), bytes32(0))) {

Check failure on line 53 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 53 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 53 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: data,
_value: 0,
_delay: 0
});
}
}

// This function should be called by the owner to accept the admin role
function chainAdminAcceptAdmin(ChainAdmin chainAdmin, address target) public {
IZkSyncHyperchain adminContract = IZkSyncHyperchain(target);
address currentAdmin;

IChainAdmin.Call[] memory calls = new IChainAdmin.Call[](1);
calls[0] = IChainAdmin.Call({target: target, value: 0, data: abi.encodeCall(adminContract.acceptAdmin, ())});
// Attempt to call admin() using a low-level call
(bool success, bytes memory result) = target.call(abi.encodeWithSignature("admin()"));

vm.startBroadcast();
chainAdmin.multicall(calls, true);
vm.stopBroadcast();
if (success) {
// Decode the result to get the current admin address
currentAdmin = abi.decode(result, (address));
} else {
// If admin() fails, try calling getAdmin() instead
(success, result) = target.call(abi.encodeWithSignature("getAdmin()"));
require(success, "Both admin() and getAdmin() calls failed");

Check failure on line 79 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Error message for require is too long: 40 counted / 32 allowed

Check failure on line 79 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 79 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Error message for require is too long: 40 counted / 32 allowed

Check failure on line 79 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 79 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Error message for require is too long: 40 counted / 32 allowed

Check failure on line 79 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

// Decode the result to get the current admin address
currentAdmin = abi.decode(result, (address));
}

// Proceed with multicall if the admin is different
if (currentAdmin != address(chainAdmin)) {
IChainAdmin.Call[] memory calls = new IChainAdmin.Call[](1);
calls[0] = IChainAdmin.Call({
target: target,
value: 0,
data: abi.encodeCall(adminContract.acceptAdmin, ())
});

vm.startBroadcast();
chainAdmin.multicall(calls, true);
vm.stopBroadcast();
}
}

// This function should be called by the owner to update token multiplier setter role
Expand Down
23 changes: 23 additions & 0 deletions l1-contracts/deploy-scripts/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,27 @@ library Utils {
vm.stopBroadcast();
}
}

function governanceOperationExists(
address _governance,
address _target,
uint256 _value,
bytes memory _data,
bytes32 _predecessor,
bytes32 _salt
) internal view returns (bool) {
IGovernance governance = IGovernance(_governance);

IGovernance.Call[] memory calls = new IGovernance.Call[](1);
calls[0] = IGovernance.Call({target: _target, value: _value, data: _data});

IGovernance.Operation memory operation = IGovernance.Operation({
calls: calls,
predecessor: _predecessor,
salt: _salt
});

bytes32 operationHash = governance.hashOperation(operation);
return governance.isOperation(operationHash);
}
}
Loading