Skip to content
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
4 changes: 2 additions & 2 deletions src/GuardedExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ abstract contract GuardedExecutor is ERC7821 {
error CannotSelfExecute();

/// @dev Unauthorized to perform the action.
error Unauthorized();
error UnauthorizedOnlySelf();

/// @dev Not authorized to perform the call.
error UnauthorizedCall(bytes32 keyHash, address target, bytes data);
Expand Down Expand Up @@ -680,7 +680,7 @@ abstract contract GuardedExecutor is ERC7821 {

/// @dev Guards a function such that it can only be called by `address(this)`.
modifier onlyThis() virtual {
if (msg.sender != address(this)) revert Unauthorized();
if (msg.sender != address(this)) revert UnauthorizedOnlySelf();
_;
}

Expand Down
25 changes: 20 additions & 5 deletions src/IthacaAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor {
/// @dev The paymaster nonce has already been used.
error PaymasterNonceError();

/// @dev Unauthorized orchestrator in checkAndIncrementNonce.
error UnauthorizedOrchestrator();

/// @dev Unauthorized payer in pay function.
error UnauthorizedPayer();

/// @dev Invalid paymaster signature. in pay()
error InvalidPaymasterSig();

/// @dev Unauthorized sender in _execute function.
error UnauthorizedSender();

/// @dev Invalid signature in _execute.
error InvalidSig();

////////////////////////////////////////////////////////////////////////
// Events
////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -593,7 +608,7 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor {
/// @dev Checks current nonce and increments the sequence for the `seqKey`.
function checkAndIncrementNonce(uint256 nonce) public payable virtual {
if (msg.sender != ORCHESTRATOR) {
revert Unauthorized();
revert UnauthorizedOrchestrator();
}
LibNonce.checkAndIncrement(_getAccountStorage().nonceSeqs, nonce);
}
Expand Down Expand Up @@ -626,7 +641,7 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor {
msg.sender == ORCHESTRATOR,
LibBit.or(intent.eoa == address(this), intent.payer == address(this))
)) {
revert Unauthorized();
revert UnauthorizedPayer();
}

// If this account is the paymaster, validate the paymaster signature.
Expand All @@ -650,7 +665,7 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor {
}

if (!isValid) {
revert Unauthorized();
revert InvalidPaymasterSig();
}
}

Expand Down Expand Up @@ -691,7 +706,7 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor {

// Simple workflow without `opData`.
if (opData.length == uint256(0)) {
if (msg.sender != address(this)) revert Unauthorized();
if (msg.sender != address(this)) revert UnauthorizedSender();
return _execute(calls, bytes32(0));
}

Expand All @@ -704,7 +719,7 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor {
(bool isValid, bytes32 keyHash) = unwrapAndValidateSignature(
computeDigest(calls, nonce), LibBytes.sliceCalldata(opData, 0x20)
);
if (!isValid) revert Unauthorized();
if (!isValid) revert InvalidSig();

// TODO: Figure out where else to add these operations, after removing delegate call.
LibTStack.TStack(_KEYHASH_STACK_TRANSIENT_SLOT).push(keyHash);
Expand Down
2 changes: 1 addition & 1 deletion test/Account.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract AccountTest is BaseTest {
signature = _sig(_randomEIP7702DelegatedEOA(), d.d.computeDigest(t.calls, t.nonce));
t.opData = abi.encodePacked(t.nonce, signature);
t.executionData = abi.encode(t.calls, t.opData);
vm.expectRevert(bytes4(keccak256("Unauthorized()")));
vm.expectRevert(bytes4(keccak256("InvalidSig()")));
d.d.execute(_ERC7821_BATCH_EXECUTION_MODE, t.executionData);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions test/GuardedExecutor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ contract GuardedExecutorTest is BaseTest {
DelegatedEOA memory d = _randomEIP7702DelegatedEOA();
PassKey memory k = _randomSecp256r1PassKey();

vm.expectRevert(bytes4(keccak256("Unauthorized()")));
vm.expectRevert(bytes4(keccak256("UnauthorizedOnlySelf()")));
d.d.setCanExecute(k.keyHash, target, fnSel, true);

vm.startPrank(d.eoa);
Expand Down Expand Up @@ -310,7 +310,7 @@ contract GuardedExecutorTest is BaseTest {
ERC7821.execute.selector, _ERC7821_BATCH_EXECUTION_MODE, abi.encode(innerCalls)
);

vm.expectRevert(bytes4(keccak256("Unauthorized()")));
vm.expectRevert(bytes4(keccak256("UnauthorizedSender()")));
d.d.execute(_ERC7821_BATCH_EXECUTION_MODE, abi.encode(calls));

vm.prank(d.eoa);
Expand Down
2 changes: 1 addition & 1 deletion test/Orchestrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ contract OrchestratorTest is BaseTest {
t.withSignature.setApprovedOrchestrator(address(oc), false);
}
if ((t.unapprovedOrchestrator && u.paymentAmount != 0)) {
assertEq(oc.execute(abi.encode(u)), bytes4(keccak256("Unauthorized()")));
assertEq(oc.execute(abi.encode(u)), bytes4(keccak256("UnapprovedOrchestrator()")));

if (u.paymentAmount != 0) {
assertEq(t.d.d.getNonce(0), u.nonce);
Expand Down
5 changes: 4 additions & 1 deletion test/utils/mocks/MockPayerWithSignature.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {IOrchestrator} from "../../../src/interfaces/IOrchestrator.sol";
/// Do NOT copy anything here into production code unless you really know what you are doing.

contract MockPayerWithSignature is Ownable {
/// @dev Unauthorized orchestrator in pay function.
error UnapprovedOrchestrator();

error InvalidSignature();
/// @dev The paymaster nonce has already been used.
error PaymasterNonceError();
Expand Down Expand Up @@ -64,7 +67,7 @@ contract MockPayerWithSignature is Ownable {
bytes32 digest,
bytes calldata encodedIntent
) public virtual {
if (!isApprovedOrchestrator[msg.sender]) revert Unauthorized();
if (!isApprovedOrchestrator[msg.sender]) revert UnapprovedOrchestrator();

// Check and set nonce to prevent replay attacks
if (paymasterNonces[digest]) {
Expand Down
5 changes: 4 additions & 1 deletion test/utils/mocks/MockPayerWithSignatureOptimized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {IOrchestrator} from "../../../src/interfaces/IOrchestrator.sol";
/// Do NOT copy anything here into production code unless you really know what you are doing.

contract MockPayerWithSignatureOptimized is Ownable {
/// @dev Unauthorized orchestrator in pay function.
error UnapprovedOrchestrator();

error InvalidSignature();

address public signer;
Expand Down Expand Up @@ -56,7 +59,7 @@ contract MockPayerWithSignatureOptimized is Ownable {
bytes32 digest,
bytes calldata encodedIntent
) public virtual {
if (msg.sender != APPROVED_ORCHESTRATOR) revert Unauthorized();
if (msg.sender != APPROVED_ORCHESTRATOR) revert UnapprovedOrchestrator();

ICommon.Intent calldata u;
assembly {
Expand Down
5 changes: 4 additions & 1 deletion test/utils/mocks/MockPayerWithState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ contract MockPayerWithState is Ownable {
/// @dev Nonce management when acting as paymaster.
mapping(bytes32 => bool) public paymasterNonces;

/// @dev Unauthorized orchestrator in pay function.
error UnapprovedOrchestrator();

/// @dev The paymaster nonce has already been used.
error PaymasterNonceError();

Expand Down Expand Up @@ -67,7 +70,7 @@ contract MockPayerWithState is Ownable {
bytes32 digest,
bytes calldata encodedIntent
) public virtual {
if (!isApprovedOrchestrator[msg.sender]) revert Unauthorized();
if (!isApprovedOrchestrator[msg.sender]) revert UnapprovedOrchestrator();

// Check and set nonce to prevent replay attacks
if (paymasterNonces[digest]) {
Expand Down