-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
173f7b1
commit 5f6dcc8
Showing
16 changed files
with
116 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,74 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
import "../common/lib/LibHasForwarder.sol"; | ||
import "./lib/LibHasForwarder.sol"; | ||
// import "@opengsn/contracts/src/ERC2771Recipient.sol"; | ||
import "@opengsn/contracts/src/interfaces/IERC2771Recipient.sol"; | ||
|
||
import "@opengsn/contracts/src/ERC2771Recipient.sol"; | ||
import "hardhat/console.sol"; | ||
|
||
/** | ||
* @title The Forwarder Smart Contract. | ||
* @notice The HasForwarder abstract contract is in charge of... | ||
*/ | ||
abstract contract AHasForwarder is ERC2771Recipient { | ||
abstract contract AHasForwarder is IERC2771Recipient { | ||
/** | ||
* @notice ERC2771Recipient stuff... | ||
* FIX THE MODIFIER !!!!!!!!!!!!!!!!!!!!!! | ||
* @notice ERC2771Recipient implementation. | ||
* TODO: FIX MODIFIER | ||
*/ | ||
function setTrustedForwarder(address _forwarderAddress) external { | ||
LibHasForwarder.Data storage ds = LibHasForwarder.data(); | ||
ds.forwarderAddress = _forwarderAddress; | ||
_setTrustedForwarder(_forwarderAddress); | ||
} | ||
|
||
/* | ||
* Forwarder singleton we accept calls from | ||
*/ | ||
address private _trustedForwarder; | ||
|
||
/** | ||
* :warning: **Warning** :warning: The Forwarder can have a full control over your Recipient. Only trust verified Forwarder. | ||
* @notice Method is not a required method to allow Recipients to trust multiple Forwarders. Not recommended yet. | ||
* @return forwarder The address of the Forwarder contract that is being used. | ||
*/ | ||
function getTrustedForwarder() public view virtual returns (address forwarder) { | ||
return _trustedForwarder; | ||
} | ||
|
||
function _setTrustedForwarder(address _forwarder) internal { | ||
_trustedForwarder = _forwarder; | ||
} | ||
|
||
/// @inheritdoc IERC2771Recipient | ||
function isTrustedForwarder(address forwarder) public view virtual override returns (bool) { | ||
return forwarder == _trustedForwarder; | ||
} | ||
|
||
/// @inheritdoc IERC2771Recipient | ||
function _msgSender() internal view virtual override returns (address ret) { | ||
console.log("msg.sender %s", msg.sender); | ||
console.log("original msg.data"); | ||
console.logBytes(msg.data); | ||
if (msg.data.length >= 20 && isTrustedForwarder(msg.sender)) { | ||
// At this point we know that the sender is a trusted forwarder, | ||
// so we trust that the last bytes of msg.data are the verified sender address. | ||
// extract sender address from the end of msg.data | ||
assembly { | ||
ret := shr(96, calldataload(sub(calldatasize(), 20))) | ||
} | ||
console.log("last 20 bytes from msg.data %s", ret); | ||
} else { | ||
ret = msg.sender; | ||
} | ||
} | ||
|
||
/// @inheritdoc IERC2771Recipient | ||
function _msgData() internal view virtual override returns (bytes calldata ret) { | ||
if (msg.data.length >= 20 && isTrustedForwarder(msg.sender)) { | ||
return msg.data[0:msg.data.length - 20]; | ||
} else { | ||
return msg.data; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters