Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zerodevapp/contracts",
"description": "ZeroDev Account Abstraction (EIP 4337) contracts",
"main": "./dist/index.js",
"version": "4.0.0-beta.13",
"version": "4.0.0-beta.14",
"scripts": {
"prepack": "./scripts/prepack-contracts-package.sh",
"postpack": "./scripts/postpack-contracts-package.sh"
Expand Down
23 changes: 17 additions & 6 deletions src/executor/KillSwitchAction.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
pragma solidity ^0.8.18;

import "src/validator/IValidator.sol";
import "src/validator/KillSwitchValidator.sol";
import "src/abstract/KernelStorage.sol";

contract KillSwitchAction {
IKernelValidator public immutable killSwitchValidator;
KillSwitchValidator public immutable killSwitchValidator;

constructor(IKernelValidator _killswitchValidator) {
constructor(KillSwitchValidator _killswitchValidator) {
killSwitchValidator = _killswitchValidator;
}

Expand All @@ -16,10 +19,18 @@ contract KillSwitchAction {
}
}

function activateKillSwitch() external {
function toggleKillSwitch() external {
WalletKernelStorage storage ws = getKernelStorage();
ws.defaultValidator = killSwitchValidator;
getKernelStorage().disabledMode = bytes4(0xffffffff);
getKernelStorage().lastDisabledTime = uint48(block.timestamp);
if(address(ws.defaultValidator) != address(killSwitchValidator)) {
// this means it is not activated
ws.defaultValidator = killSwitchValidator;
getKernelStorage().disabledMode = bytes4(0xffffffff);
getKernelStorage().lastDisabledTime = uint48(block.timestamp);
} else {
(address guardian, IKernelValidator prevValidator, , bytes4 prevDisableMode) = killSwitchValidator.killSwitchValidatorStorage(address(this));
// this means it is activated
ws.defaultValidator = prevValidator;
getKernelStorage().disabledMode = prevDisableMode;
}
}
}
3 changes: 3 additions & 0 deletions src/validator/KillSwitchValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct KillSwitchValidatorStorage {
address guardian;
IKernelValidator validator;
uint48 pausedUntil;
bytes4 disableMode;
}

contract KillSwitchValidator is IKernelValidator {
Expand All @@ -37,6 +38,7 @@ contract KillSwitchValidator is IKernelValidator {
uint256 delayedData = _packValidationData(false, 0, pausedUntil);
return _packValidationData(_intersectTimeRange(res, delayedData));
}
return SIG_VALIDATION_FAILED;
}

function validateUserOp(UserOperation calldata _userOp, bytes32 _userOpHash, uint256)
Expand Down Expand Up @@ -64,6 +66,7 @@ contract KillSwitchValidator is IKernelValidator {
// save data to this storage
validatorStorage.pausedUntil = uint48(bytes6(_userOp.signature[0:6]));
validatorStorage.validator = KernelStorage(msg.sender).getDefaultValidator();
validatorStorage.disableMode = KernelStorage(msg.sender).getDisabledMode();
bytes32 hash = ECDSA.toEthSignedMessageHash(keccak256(bytes.concat(_userOp.signature[0:6],_userOpHash)));
address recovered = ECDSA.recover(hash, _userOp.signature[6:]);
if (validatorStorage.guardian != recovered) {
Expand Down
4 changes: 2 additions & 2 deletions test/foundry/KillSwitch.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract KernelExecutionTest is Test {

op = entryPoint.fillUserOp(
address(kernel),
abi.encodeWithSelector(KillSwitchAction.activateKillSwitch.selector)
abi.encodeWithSelector(KillSwitchAction.toggleKillSwitch.selector)
);
address guardianKeyAddr;
uint256 guardianKeyPriv;
Expand All @@ -68,7 +68,7 @@ contract KernelExecutionTest is Test {
{
bytes32 digest = getTypedDataHash(
address(kernel),
KillSwitchAction.activateKillSwitch.selector,
KillSwitchAction.toggleKillSwitch.selector,
0,
0,
address(killSwitch),
Expand Down