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

[DONT MERGE] AmbireAccount7702 added: accepts signatures from address(this) #914

Open
wants to merge 1 commit into
base: v2
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
21 changes: 15 additions & 6 deletions contracts/AmbireAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ contract AmbireAccount is IAmbireAccount {
emit LogPrivilegeChanged(addr, priv);
}

/**
* @notice Returns the privilege level of a certain address (key)
* @param key the address we want to check the privileges to
* @return bytes4 is it a success or a failure
*/
function privilegeLevel(address key) internal virtual view returns (uint256) {
return uint256(privileges[key]);
}

/**
* @notice Useful when we need to do multiple operations but ignore failures in some of them
* @param to address we're sending value to
Expand Down Expand Up @@ -162,13 +171,13 @@ contract AmbireAccount is IAmbireAccount {
signature,
true
);
require(privileges[signerKey] != bytes32(0), 'INSUFFICIENT_PRIVILEGE');
require(privilegeLevel(signerKey) != 0, 'INSUFFICIENT_PRIVILEGE');
}

executeBatch(calls);

// The actual anti-bricking mechanism - do not allow a signerKey to drop their own privileges
require(privileges[signerKey] != bytes32(0), 'PRIVILEGE_NOT_DOWNGRADED');
require(privilegeLevel(signerKey) != 0, 'PRIVILEGE_NOT_DOWNGRADED');
}

/**
Expand All @@ -185,10 +194,10 @@ contract AmbireAccount is IAmbireAccount {
* @param calls the transaction we're executing
*/
function executeBySender(Transaction[] calldata calls) external payable {
require(privileges[msg.sender] != bytes32(0), 'INSUFFICIENT_PRIVILEGE');
require(privilegeLevel(msg.sender) != 0, 'INSUFFICIENT_PRIVILEGE');
executeBatch(calls);
// again, anti-bricking
require(privileges[msg.sender] != bytes32(0), 'PRIVILEGE_NOT_DOWNGRADED');
require(privilegeLevel(msg.sender) != 0, 'PRIVILEGE_NOT_DOWNGRADED');
}

/**
Expand Down Expand Up @@ -253,7 +262,7 @@ contract AmbireAccount is IAmbireAccount {
*/
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4) {
(address recovered, bool usedUnprotected) = SignatureValidator.recoverAddrAllowUnprotected(hash, signature, false);
if (uint256(privileges[recovered]) > (usedUnprotected ? 1 : 0)) {
if (privilegeLevel(recovered) > (usedUnprotected ? 1 : 0)) {
// bytes4(keccak256("isValidSignature(bytes32,bytes)")
return 0x1626ba7e;
} else {
Expand Down Expand Up @@ -348,7 +357,7 @@ contract AmbireAccount is IAmbireAccount {

// this is replay-safe because userOpHash is retrieved like this: keccak256(abi.encode(userOp.hash(), address(this), block.chainid))
address signer = SignatureValidator.recoverAddr(userOpHash, op.signature, true);
if (privileges[signer] == bytes32(0)) return SIG_VALIDATION_FAILED;
if (privilegeLevel(signer) == 0) return SIG_VALIDATION_FAILED;

return SIG_VALIDATION_SUCCESS;
}
Expand Down
12 changes: 12 additions & 0 deletions contracts/AmbireAccount7702.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: agpl-3.0

pragma solidity 0.8.19;
import "./AmbireAccount.sol";


contract AmbireAccount7702 is AmbireAccount {
function privilegeLevel(address key) internal override view returns (uint256) {
if (key == address(this)) return 2;
return uint256(privileges[key]);
}
}
Loading