Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"rules": {
"compiler-version": ["error", "^0.8"],
"import-path-check": "off",
"use-natspec": "warn"
"use-natspec": "warn",
"func-visibility": ["error", { "ignoreConstructors": true }],
"no-complex-fallback": "off",
"no-inline-assembly": "off"
Comment on lines +7 to +9
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these are necessary:

  • "func-visibility": ["error", { "ignoreConstructors": true }] -> constructor doesn't require explicit visibility modifier since Solidity 0.7
  • "no-complex-fallback": "off" -> we explicitly need our fallback to be complex
  • "no-inline-assembly": "off" -> we explicitly need assembly for gas efficiency

}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.34+commit.80d5c536"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit requirement for latest Solidity version

}
4 changes: 2 additions & 2 deletions dev/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "contracts-template-dev",
"name": "solver-7702-delegate",
"version": "0.0.0",
"private": true,
"description": "Local development dependencies for the contracts template.",
"description": "Local development dependencies for the Solver7702Delegate contract.",
"license": "(MIT OR Apache-2.0)",
"packageManager": "pnpm@10.33.2",
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ solc = "0.8.34" # See latest release at: https://github.com/argotorg/solidity/re
[fmt]
sort_imports = true
number_underscore = "thousands"
wrap_comments = true
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, lines can extend without wrapping.


[profile.ci]
deny = "warnings" # Why not always: sometimes you just want to code and see what comes out
Expand Down
20 changes: 0 additions & 20 deletions script/Counter.s.sol

This file was deleted.

2 changes: 1 addition & 1 deletion slither.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"detectors_to_exclude": "solc-version",
"detectors_to_exclude": "solc-version,naming-convention,assembly",
Comment thread
igorroncevic marked this conversation as resolved.
"filter_paths": "/(lib|test|script)/"
}
21 changes: 0 additions & 21 deletions src/Counter.sol

This file was deleted.

87 changes: 87 additions & 0 deletions src/Solver7702Delegate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.34;

/// @title Solver7702Delegate
/// @author CoW DAO Developers
/// @notice ERC-7702 delegation target for solver EOAs
contract Solver7702Delegate {
/// @notice Error thrown when a caller is unauthorized
error Unauthorized(address sender);

/// @notice Address of the first approved caller
address private immutable APPROVED_CALLER_0;

/// @notice Address of the second approved caller
address private immutable APPROVED_CALLER_1;

/// @notice Address of the third approved caller
address private immutable APPROVED_CALLER_2;

/// @notice Address of the fourth approved caller
address private immutable APPROVED_CALLER_3;

/// @notice Address of the fifth approved caller
address private immutable APPROVED_CALLER_4;

/// @notice Constructor to initialize the approved callers
/// @param approvedCallers The addresses of the approved callers
constructor(address[5] memory approvedCallers) {
APPROVED_CALLER_0 = approvedCallers[0];
APPROVED_CALLER_1 = approvedCallers[1];
APPROVED_CALLER_2 = approvedCallers[2];
APPROVED_CALLER_3 = approvedCallers[3];
APPROVED_CALLER_4 = approvedCallers[4];
}

/// @notice Fallback function to handle calls to the delegate
fallback() external payable {
// Simply receive ETH
if (msg.data.length < 20) return;

// Possibly short circuit by recognizing one of the approved callers
if (msg.sender == APPROVED_CALLER_0) return _callThrough();
if (msg.sender == APPROVED_CALLER_1) return _callThrough();
if (msg.sender == APPROVED_CALLER_2) return _callThrough();
if (msg.sender == APPROVED_CALLER_3) return _callThrough();
if (msg.sender == APPROVED_CALLER_4) return _callThrough();

// Revert if caller is unauthorized
revert Unauthorized(msg.sender);
}

function _callThrough() internal {
// For our purposes, the target address is encoded as the first 20 bytes of the input data
address target = address(bytes20(msg.data[0:20]));
Comment thread
igorroncevic marked this conversation as resolved.

assembly {
// Extract calldata in range (target, len(msg.data)).
// We take full control of memory in this inline assembly block because it will not return to Solidity code.
// This is why we overwrite the Solidity scratch pad at memory position 0.
calldatacopy(0x00, 20, sub(calldatasize(), 20))

// Call the implementation
let result :=
call(
gas(), // gas - forward all of it
target, // target to call
callvalue(), // value - forward all Ether
0x00, // input offset - pointer to calldata
sub(calldatasize(), 20), // input size - length of calldata
0x00, // output offset - 0 because we don't know the size yet
0x00 // output size - 0 because we don't know the size yet
)

// Copy return data into memory
returndatacopy(0x00, 0x00, returndatasize())

// Handle return data, 0 = revert / 1 = success
switch result
case 0 {
revert(0x00, returndatasize())
}
default {
return(0x00, returndatasize())
}
}
}
}
25 changes: 0 additions & 25 deletions test/Counter.t.sol

This file was deleted.

Loading