Skip to content

Commit 6f7badb

Browse files
Add eth get logs precompile specific types
1 parent 953ecb2 commit 6f7badb

File tree

6 files changed

+92
-314
lines changed

6 files changed

+92
-314
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
forge test -vvv
129129
id: test
130130
working-directory: solidity-sdk
131+
131132

132133
optimistic-auction:
133134
name: optimistic-auction

protocol/src/BridgeMintBurn.sol

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
88
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
99
import {IERC20MintableAndBurnable} from "./interfaces/IERC20MintableAndBurnable.sol";
1010
import {WrappedToken} from "./WrappedToken.sol";
11+
import {EthGetLogsPrecompileHelperTypes} from "pod-sdk/types/EthGetLogsPrecompileHelperTypes.sol";
1112

1213
/**
1314
* @title BridgeMintBurn
@@ -23,12 +24,6 @@ contract BridgeMintBurn is Bridge, IBridgeMintBurn {
2324
*/
2425
bytes32 constant MINTER_ROLE = keccak256("MINTER_ROLE");
2526

26-
/**
27-
* @dev The address of the external eth get logs precompile.
28-
*/
29-
address constant ETH_EXTERNAL_ETH_GET_LOGS_PRECOMPILE =
30-
address(uint160(uint256(keccak256("ETH_EXTERNAL_ETH_GET_LOGS"))));
31-
3227
/**
3328
* @dev The source chain id.
3429
*/
@@ -39,56 +34,6 @@ contract BridgeMintBurn is Bridge, IBridgeMintBurn {
3934
*/
4035
bytes constant FINALIZED_BLOCK_BYTES = hex"66696e616c697a6564";
4136

42-
/**
43-
* @dev The arguments for the external eth get logs precompile.
44-
* @param fromBlock The block number to start searching from.
45-
* @param toBlock The block number to stop searching at.
46-
* @param addr The address to search logs for.
47-
* @param blockHash The block hash to search logs for.
48-
* @param topics The topics to search logs for.
49-
*/
50-
struct EthGetLogsArgs {
51-
bytes fromBlock;
52-
bytes toBlock;
53-
address addr;
54-
bytes32 blockHash;
55-
bytes32[] topics;
56-
}
57-
58-
/**
59-
* @dev The arguments for the external eth get logs precompile.
60-
* @param chainId The chain id to search logs for.
61-
* @param ethGetLogsArgs The arguments for the external eth get logs precompile.
62-
*/
63-
struct ExternalEthGetLogsArgs {
64-
uint256 chainId;
65-
EthGetLogsArgs ethGetLogsArgs;
66-
}
67-
68-
/**
69-
* @dev The response from the external eth get logs precompile.
70-
* @param addr The address of the log.
71-
* @param topics The topics of the log.
72-
* @param data The data of the log.
73-
* @param blockNumber The block number of the log.
74-
* @param transactionHash The transaction hash of the log.
75-
* @param transactionIndex The transaction index of the log.
76-
* @param blockHash The block hash of the log.
77-
* @param logIndex The log index of the log.
78-
* @param removed Whether the log was removed.
79-
*/
80-
struct RpcLog {
81-
address addr;
82-
bytes32[] topics;
83-
bytes data;
84-
bytes blockNumber;
85-
bytes32 transactionHash;
86-
bytes transactionIndex;
87-
bytes32 blockHash;
88-
bytes logIndex;
89-
bool removed;
90-
}
91-
9237
/**
9338
* @dev Constructor.
9439
*/
@@ -112,17 +57,20 @@ contract BridgeMintBurn is Bridge, IBridgeMintBurn {
11257
topics[1] = bytes32(id);
11358
topics[2] = bytes32(uint256(uint160(token)));
11459

115-
(bool success, bytes memory output) = ETH_EXTERNAL_ETH_GET_LOGS_PRECOMPILE.staticcall(
60+
(bool success, bytes memory output) = EthGetLogsPrecompileHelperTypes.PRECOMPILE_ADDRESS.staticcall(
11661
abi.encode(
117-
ExternalEthGetLogsArgs(
62+
EthGetLogsPrecompileHelperTypes.PrecompileArgs(
11863
SOURCE_CHAIN_ID,
119-
EthGetLogsArgs(blockNumberFrom, FINALIZED_BLOCK_BYTES, address(token), bytes32(0), topics)
64+
EthGetLogsPrecompileHelperTypes.RpcArgs(
65+
blockNumberFrom, FINALIZED_BLOCK_BYTES, address(token), bytes32(0), topics
66+
)
12067
)
12168
)
12269
);
12370
if (!success) revert PrecompileCallFailed();
12471

125-
RpcLog[] memory logs = abi.decode(output, (RpcLog[]));
72+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs =
73+
abi.decode(output, (EthGetLogsPrecompileHelperTypes.RpcLog[]));
12674

12775
if (logs.length == 0) revert NoDepositsFound();
12876
if (logs.length > 1) revert MultipleDepositsWithSameId();

protocol/test/BridgeMintBurn.t.sol

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {IBridge} from "../src/interfaces/IBridge.sol";
88
import {Bridge} from "../src/abstract/Bridge.sol";
99
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1010
import {WrappedToken} from "../src/WrappedToken.sol";
11-
import {MerkleTree} from "pod-sdk/verifier/MerkleTree.sol";
1211
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
12+
import {EthGetLogsPrecompileHelperTypes} from "pod-sdk/types/EthGetLogsPrecompileHelperTypes.sol";
1313

1414
contract BridgeMintBurnTest is BridgeBehaviorTest {
1515
BridgeMintBurn private _bridge;
@@ -50,7 +50,7 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
5050
}
5151

5252
function test_Claim_SingleLog_MintsToRecipient() public {
53-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
53+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
5454
logs[0] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
5555
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
5656
assertEq(_token.balanceOf(recipient), 0);
@@ -69,15 +69,15 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
6969
}
7070

7171
function test_Claim_RevertIfDailyLimitExhausted() public {
72-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
72+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
7373
logs[0] = _makeLog(0, _mirror, tokenLimits.claim + 1, recipient);
7474
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
7575
vm.expectRevert(abi.encodeWithSelector(IBridge.DailyLimitExhausted.selector));
7676
_bridge.claim(0, _mirror, bytes("0x1"));
7777
}
7878

7979
function test_Claim_RevertIfDailyLimitExhausted_ButSucceedAfterOneDay() public {
80-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
80+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
8181
logs[0] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
8282
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
8383
_bridge.claim(0, _mirror, bytes("0x1"));
@@ -91,14 +91,14 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
9191
}
9292

9393
function test_Claim_RevertIfNoDepositsFound() public {
94-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](0);
94+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](0);
9595
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
9696
vm.expectRevert(abi.encodeWithSelector(IBridgeMintBurn.NoDepositsFound.selector));
9797
_bridge.claim(0, _mirror, bytes("0x1"));
9898
}
9999

100100
function test_Claim_RevertIfMultipleDepositsFound() public {
101-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](2);
101+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](2);
102102
logs[0] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
103103
logs[1] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
104104
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
@@ -109,7 +109,7 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
109109
function test_Claim_RevertIfMirrorTokenNotFound() public {
110110
// Use a token not mapped in mirrorTokens
111111
address unknownMirror = address(0xBEEF);
112-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
112+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
113113
logs[0] = _makeLog(0, unknownMirror, DEPOSIT_AMOUNT, recipient);
114114
_mockEthGetLogs(0, bytes("0x1"), unknownMirror, logs);
115115

@@ -118,7 +118,7 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
118118
}
119119

120120
function test_Claim_RevertIfAlreadyProcessed() public {
121-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
121+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
122122
logs[0] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
123123
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
124124
_bridge.claim(0, _mirror, bytes("0x1"));
@@ -137,7 +137,7 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
137137
}
138138

139139
function test_Claim_RevertIfPrecompileCallFails() public {
140-
BridgeMintBurn.ExternalEthGetLogsArgs memory args = _buildArgs(0, bytes("0x1"), _mirror);
140+
EthGetLogsPrecompileHelperTypes.PrecompileArgs memory args = _buildArgs(0, bytes("0x1"), _mirror);
141141
podMockEthGetLogsRevert(abi.encode(args));
142142

143143
vm.expectRevert(abi.encodeWithSelector(IBridgeMintBurn.PrecompileCallFailed.selector));
@@ -172,22 +172,25 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
172172
function _buildArgs(uint256 id, bytes memory fromBlock, address tokenAddr)
173173
internal
174174
pure
175-
returns (BridgeMintBurn.ExternalEthGetLogsArgs memory)
175+
returns (EthGetLogsPrecompileHelperTypes.PrecompileArgs memory)
176176
{
177-
BridgeMintBurn.EthGetLogsArgs memory inner = BridgeMintBurn.EthGetLogsArgs({
177+
EthGetLogsPrecompileHelperTypes.RpcArgs memory inner = EthGetLogsPrecompileHelperTypes.RpcArgs({
178178
fromBlock: fromBlock,
179179
toBlock: hex"66696e616c697a6564",
180180
addr: tokenAddr,
181181
blockHash: bytes32(0),
182182
topics: _buildTopics(id, tokenAddr)
183183
});
184-
return BridgeMintBurn.ExternalEthGetLogsArgs({chainId: 1, ethGetLogsArgs: inner});
184+
return EthGetLogsPrecompileHelperTypes.PrecompileArgs({chainId: 1, ethGetLogsArgs: inner});
185185
}
186186

187-
function _mockEthGetLogs(uint256 id, bytes memory fromBlock, address tokenAddr, BridgeMintBurn.RpcLog[] memory logs)
188-
internal
189-
{
190-
BridgeMintBurn.ExternalEthGetLogsArgs memory args = _buildArgs(id, fromBlock, tokenAddr);
187+
function _mockEthGetLogs(
188+
uint256 id,
189+
bytes memory fromBlock,
190+
address tokenAddr,
191+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs
192+
) internal {
193+
EthGetLogsPrecompileHelperTypes.PrecompileArgs memory args = _buildArgs(id, fromBlock, tokenAddr);
191194
podMockEthGetLogs(abi.encode(args), abi.encode(logs));
192195
}
193196

@@ -201,9 +204,9 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
201204
function _makeLog(uint256 id, address tokenAddr, uint256 amount, address to)
202205
internal
203206
pure
204-
returns (BridgeMintBurn.RpcLog memory)
207+
returns (EthGetLogsPrecompileHelperTypes.RpcLog memory)
205208
{
206-
return BridgeMintBurn.RpcLog({
209+
return EthGetLogsPrecompileHelperTypes.RpcLog({
207210
addr: tokenAddr,
208211
topics: _buildTopics(id, tokenAddr),
209212
data: abi.encode(amount, to),

0 commit comments

Comments
 (0)