restore trustedForwarders as an OZ override

This commit is contained in:
hueso 2025-10-24 21:50:21 -03:00
parent f56335d9b5
commit d9b93fe7d5
5 changed files with 58 additions and 7 deletions

View File

@ -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 {

View File

@ -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];
}
}

View File

@ -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,

View File

@ -29,7 +29,6 @@ const main = async () => {
reputation.target,
[deploysJson.token],
[true],
ethers.ZeroAddress,
]);
reputation = await reputation.waitForDeployment();

View File

@ -93,7 +93,6 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
reputation.target,
[erc20.target],
[true],
ethers.ZeroAddress,
]);
const multicall = await ethers.deployContract("Multicall");