From d9b93fe7d596387ec19bb54257133888e4e51707 Mon Sep 17 00:00:00 2001 From: hueso Date: Fri, 24 Oct 2025 21:50:21 -0300 Subject: [PATCH] restore trustedForwarders as an OZ override --- contracts/core/OwnerSettings.sol | 44 ++++++++++++++++++++++++- contracts/lib/metatx/ERC2771Context.sol | 14 ++++++++ contracts/p2pix.sol | 5 +-- scripts/2-deploy-p2pix.ts | 1 - test/utils/fixtures.ts | 1 - 5 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 contracts/lib/metatx/ERC2771Context.sol diff --git a/contracts/core/OwnerSettings.sol b/contracts/core/OwnerSettings.sol index be40baa..ea92d9c 100644 --- a/contracts/core/OwnerSettings.sol +++ b/contracts/core/OwnerSettings.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.19; -import { ERC2771Context as ERC2771 } from "@openzeppelin/contracts/metatx/ERC2771Context.sol"; +import { ERC2771 } from "contracts/lib/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,6 +42,48 @@ 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 { diff --git a/contracts/lib/metatx/ERC2771Context.sol b/contracts/lib/metatx/ERC2771Context.sol new file mode 100644 index 0000000..a6d45cf --- /dev/null +++ b/contracts/lib/metatx/ERC2771Context.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.20; + +import { ERC2771Context } from "@openzeppelin/contracts/metatx/ERC2771Context.sol"; + +abstract contract ERC2771 is ERC2771Context(address(0)) { + mapping(address => bool) public trustedForwarders; + + function isTrustedForwarder(address forwarder) public view override returns (bool) { + return trustedForwarders[forwarder]; + } + +} diff --git a/contracts/p2pix.sol b/contracts/p2pix.sol index 9608027..641da79 100644 --- a/contracts/p2pix.sol +++ b/contracts/p2pix.sol @@ -9,7 +9,6 @@ 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"; @@ -34,10 +33,8 @@ contract P2PIX is BaseUtils { address[] memory validSigners, address _reputation, ERC20[] memory tokens, - bool[] memory tokenStates, - address trustedForwarder + bool[] memory tokenStates ) - ERC2771(trustedForwarder) OwnerSettings( defaultBlocks, validSigners, diff --git a/scripts/2-deploy-p2pix.ts b/scripts/2-deploy-p2pix.ts index 57bea46..a6d1f1a 100644 --- a/scripts/2-deploy-p2pix.ts +++ b/scripts/2-deploy-p2pix.ts @@ -29,7 +29,6 @@ const main = async () => { reputation.target, [deploysJson.token], [true], - ethers.ZeroAddress, ]); reputation = await reputation.waitForDeployment(); diff --git a/test/utils/fixtures.ts b/test/utils/fixtures.ts index 1cda9c3..8fb483a 100644 --- a/test/utils/fixtures.ts +++ b/test/utils/fixtures.ts @@ -93,7 +93,6 @@ export async function p2pixFixture(): Promise { reputation.target, [erc20.target], [true], - ethers.ZeroAddress, ]); const multicall = await ethers.deployContract("Multicall");