Skip to content

Commit

Permalink
Unify trusted forwarder checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bennoprice committed Aug 28, 2023
1 parent b2974a5 commit b98f882
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 50 deletions.
8 changes: 0 additions & 8 deletions contracts/__mocks__/MockGelatoRelayContextERC2771.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,4 @@ contract MockGelatoRelayContextERC2771 is GelatoRelayContextERC2771 {

// solhint-disable-next-line no-empty-blocks
function testOnlyGelatoRelayERC2771() external onlyGelatoRelayERC2771 {}

function testOnlyGelatoRelayConcurrentERC2771()
external
onlyGelatoRelayConcurrentERC2771
// solhint-disable-next-line no-empty-blocks
{

}
}
8 changes: 0 additions & 8 deletions contracts/__mocks__/MockGelatoRelayFeeCollectorERC2771.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,4 @@ contract MockGelatoRelayFeeCollectorERC2771 is GelatoRelayFeeCollectorERC2771 {

// solhint-disable-next-line no-empty-blocks
function testOnlyGelatoRelayERC2771() external onlyGelatoRelayERC2771 {}

function testOnlyGelatoRelayConcurrentERC2771()
external
onlyGelatoRelayConcurrentERC2771
// solhint-disable-next-line no-empty-blocks
{

}
}
26 changes: 4 additions & 22 deletions contracts/base/GelatoRelayERC2771Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,17 @@ abstract contract GelatoRelayERC2771Base {
_;
}

modifier onlyGelatoRelayConcurrentERC2771() {
require(
_isGelatoRelayConcurrentERC2771(msg.sender),
"onlyGelatoRelayConcurrentERC2771"
);
_;
}

function _isGelatoRelayERC2771(address _forwarder)
internal
view
returns (bool)
{
// Use another address on zkSync
if (block.chainid == 324 || block.chainid == 280) {
return _forwarder == GELATO_RELAY_ERC2771_ZKSYNC;
}
return _forwarder == GELATO_RELAY_ERC2771;
}

function _isGelatoRelayConcurrentERC2771(address _forwarder)
internal
view
returns (bool)
{
// Use another address on zkSync
if (block.chainid == 324 || block.chainid == 280) {
return _forwarder == GELATO_RELAY_CONCURRENT_ERC2771_ZKSYNC;
return (_forwarder == GELATO_RELAY_ERC2771_ZKSYNC ||
_forwarder == GELATO_RELAY_CONCURRENT_ERC2771_ZKSYNC);
}
return _forwarder == GELATO_RELAY_CONCURRENT_ERC2771;
return (_forwarder == GELATO_RELAY_ERC2771 ||
_forwarder == GELATO_RELAY_CONCURRENT_ERC2771);
}
}
6 changes: 0 additions & 6 deletions test/MockRelayContextERC2771.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,4 @@ describe("Test MockGelatoRelayContextERC2771 Smart Contract", function () {
mockRelayContextERC2771.testOnlyGelatoRelayERC2771()
).to.be.revertedWith("onlyGelatoRelayERC2771");
});

it("#7: testOnlyGelatoRelayConcurrentERC2771 reverts if not GelatoRelay", async () => {
await expect(
mockRelayContextERC2771.testOnlyGelatoRelayConcurrentERC2771()
).to.be.revertedWith("onlyGelatoRelayConcurrentERC2771");
});
});
6 changes: 0 additions & 6 deletions test/MockRelayFeeCollectorERC2771.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,4 @@ describe("Test MockGelatoRelayFeeCollectorERC2771 Smart Contract", function () {
mockRelayFeeCollectorERC2771.testOnlyGelatoRelayERC2771()
).to.be.revertedWith("onlyGelatoRelayERC2771");
});

it("#3: testOnlyGelatoRelayConcurrentERC2771 reverts if not GelatoRelay", async () => {
await expect(
mockRelayFeeCollectorERC2771.testOnlyGelatoRelayConcurrentERC2771()
).to.be.revertedWith("onlyGelatoRelayConcurrentERC2771");
});
});

0 comments on commit b98f882

Please sign in to comment.