import ECDSA, ERC2771, ERC20, MerkleProofLib from @openzeppelin
This commit is contained in:
@@ -3,7 +3,7 @@ pragma solidity ^0.8.19;
|
||||
|
||||
import { ERC20, OwnerSettings } from "contracts/core/OwnerSettings.sol";
|
||||
|
||||
import { ECDSA } from "contracts/lib/utils/ECDSA.sol";
|
||||
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
||||
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
|
||||
import { MerkleProof as Merkle } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
|
||||
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||
@@ -44,7 +44,7 @@ abstract contract BaseUtils is
|
||||
if (
|
||||
!validBacenSigners(
|
||||
_castAddrToKey(
|
||||
ECDSA.recoverCalldata(
|
||||
ECDSA.recover(
|
||||
MessageHashUtils.toEthSignedMessageHash(
|
||||
_message
|
||||
),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import { ERC2771Context as ERC2771 } from "contracts/lib/metatx/ERC2771Context.sol";
|
||||
import { ERC2771Context as ERC2771 } from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
||||
import { ERC20, SafeTransferLib } from "contracts/lib/utils/SafeTransferLib.sol";
|
||||
import { IReputation } from "contracts/lib/interfaces/IReputation.sol";
|
||||
import { EventAndErrors } from "contracts/core/EventAndErrors.sol";
|
||||
@@ -42,48 +42,6 @@ abstract contract OwnerSettings is
|
||||
|
||||
/// ███ Owner Only █████████████████████████████████████████████████████████
|
||||
|
||||
function setTrustedFowarders(
|
||||
address[] memory forwarders,
|
||||
bool[] memory states
|
||||
) external onlyOwner {
|
||||
assembly ("memory-safe") {
|
||||
// first 32 bytes eq to array's length
|
||||
let fLen := mload(forwarders)
|
||||
// halts execution if forwarders.length eq 0
|
||||
if iszero(fLen) {
|
||||
invalid()
|
||||
}
|
||||
// revert with `LengthMismatch()`
|
||||
if iszero(eq(fLen, mload(states))) {
|
||||
mstore(0x00, 0xff633a38)
|
||||
revert(0x1c, 0x04)
|
||||
}
|
||||
let fLoc := add(forwarders, 0x20)
|
||||
let sLoc := add(states, 0x20)
|
||||
for {
|
||||
let end := add(fLoc, shl(5, fLen))
|
||||
} iszero(eq(fLoc, end)) {
|
||||
fLoc := add(fLoc, 0x20)
|
||||
sLoc := add(sLoc, 0x20)
|
||||
} {
|
||||
// cache hashmap entry in scratch space
|
||||
mstore(0x20, trustedForwarders.slot)
|
||||
mstore(0x00, mload(fLoc))
|
||||
// let mapSlot := keccak256(0x00, 0x40)
|
||||
sstore(keccak256(0x00, 0x40), mload(sLoc))
|
||||
|
||||
// emit TrustedForwarderUpdated(address, bool)
|
||||
log3(
|
||||
0,
|
||||
0,
|
||||
_TRUSTED_FORWARDER_UPDATED_EVENT_SIGNATURE,
|
||||
mload(fLoc),
|
||||
mload(sLoc)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Contract's underlying balance withdraw method.
|
||||
/// @dev Function sighash: 0x5fd8c710.
|
||||
function withdrawBalance() external onlyOwner {
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity >=0.8.4;
|
||||
|
||||
/// @author OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
|
||||
/// (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Context.sol)
|
||||
|
||||
/// @dev Provides information about the current execution context, including the
|
||||
/// sender of the transaction and its data. While these are generally available
|
||||
/// via msg.sender and msg.data, they should not be accessed in such a direct
|
||||
/// manner, since when dealing with meta-transactions the account sending and
|
||||
/// paying for execution may not be the actual sender (as far as an application
|
||||
/// is concerned).
|
||||
///
|
||||
/// This contract is only required for intermediate, library-like contracts.
|
||||
abstract contract Context {
|
||||
function _msgSender()
|
||||
internal
|
||||
view
|
||||
virtual
|
||||
returns (address)
|
||||
{
|
||||
return msg.sender;
|
||||
}
|
||||
|
||||
function _msgData()
|
||||
internal
|
||||
view
|
||||
virtual
|
||||
returns (bytes calldata)
|
||||
{
|
||||
return msg.data;
|
||||
}
|
||||
}
|
||||
|
||||
/// @author Modified from OpenZeppelin Contracts (last updated v4.7.0) (metatx/ERC2771Context.sol)
|
||||
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/metatx/ERC2771Context.sol
|
||||
|
||||
/// @dev Context variant with ERC2771 support.
|
||||
abstract contract ERC2771Context is Context {
|
||||
// address private immutable _trustedForwarder;
|
||||
mapping(address => bool) public trustedForwarders;
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
// constructor(address trustedForwarder) {
|
||||
// _trustedForwarder = trustedForwarder;
|
||||
// }
|
||||
|
||||
function _msgSender()
|
||||
internal
|
||||
view
|
||||
virtual
|
||||
override
|
||||
returns (address sender)
|
||||
{
|
||||
if (trustedForwarders[msg.sender]) {
|
||||
// The assembly code is more direct than the Solidity version using `abi.decode`.
|
||||
/// @solidity memory-safe-assembly
|
||||
assembly {
|
||||
sender := shr(
|
||||
96,
|
||||
calldataload(sub(calldatasize(), 20))
|
||||
)
|
||||
}
|
||||
} else {
|
||||
return super._msgSender();
|
||||
}
|
||||
}
|
||||
|
||||
function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
|
||||
return trustedForwarders[forwarder];
|
||||
}
|
||||
|
||||
function _msgData()
|
||||
internal
|
||||
view
|
||||
virtual
|
||||
override
|
||||
returns (bytes calldata)
|
||||
{
|
||||
if (isTrustedForwarder(msg.sender)) {
|
||||
return msg.data[:msg.data.length - 20];
|
||||
} else {
|
||||
return super._msgData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ pragma solidity ^0.8.19;
|
||||
///
|
||||
|
||||
import { OwnerSettings, ERC20, SafeTransferLib } from "contracts/core/OwnerSettings.sol";
|
||||
import { ERC2771Context as ERC2771 } from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
||||
import { BaseUtils } from "contracts/core/BaseUtils.sol";
|
||||
import { DataTypes as DT } from "contracts/core/DataTypes.sol";
|
||||
|
||||
@@ -33,8 +34,10 @@ contract P2PIX is BaseUtils {
|
||||
address[] memory validSigners,
|
||||
address _reputation,
|
||||
ERC20[] memory tokens,
|
||||
bool[] memory tokenStates
|
||||
bool[] memory tokenStates,
|
||||
address trustedForwarder
|
||||
)
|
||||
ERC2771(trustedForwarder)
|
||||
OwnerSettings(
|
||||
defaultBlocks,
|
||||
validSigners,
|
||||
|
||||
Reference in New Issue
Block a user