Skip to content

Commit 655bee1

Browse files
Add eth get logs precompile specific types to a library and generate bindings for it in solidity-sdk
1 parent 7f57080 commit 655bee1

File tree

12 files changed

+353
-313
lines changed

12 files changed

+353
-313
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ jobs:
128128
forge test -vvv
129129
id: test
130130
working-directory: solidity-sdk
131+
132+
- name: Check bindings
133+
run: |
134+
make check
135+
working-directory: solidity-sdk
136+
id: bindings
131137

132138
optimistic-auction:
133139
name: optimistic-auction

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"examples/solidity/bindings",
44
"types",
55
"rust-sdk",
6+
"solidity-sdk/bindings",
67
"examples/notary",
78
"examples/optimistic-auction",
89
"examples/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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {Bridge} from "../src/abstract/Bridge.sol";
99
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1010
import {WrappedToken} from "../src/WrappedToken.sol";
1111
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
12+
import {EthGetLogsPrecompileHelperTypes} from "pod-sdk/types/EthGetLogsPrecompileHelperTypes.sol";
1213

1314
contract BridgeMintBurnTest is BridgeBehaviorTest {
1415
BridgeMintBurn private _bridge;
@@ -49,7 +50,7 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
4950
}
5051

5152
function test_Claim_SingleLog_MintsToRecipient() public {
52-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
53+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
5354
logs[0] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
5455
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
5556
assertEq(_token.balanceOf(recipient), 0);
@@ -68,15 +69,15 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
6869
}
6970

7071
function test_Claim_RevertIfDailyLimitExhausted() public {
71-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
72+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
7273
logs[0] = _makeLog(0, _mirror, tokenLimits.claim + 1, recipient);
7374
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
7475
vm.expectRevert(abi.encodeWithSelector(IBridge.DailyLimitExhausted.selector));
7576
_bridge.claim(0, _mirror, bytes("0x1"));
7677
}
7778

7879
function test_Claim_RevertIfDailyLimitExhausted_ButSucceedAfterOneDay() public {
79-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
80+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
8081
logs[0] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
8182
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
8283
_bridge.claim(0, _mirror, bytes("0x1"));
@@ -90,14 +91,14 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
9091
}
9192

9293
function test_Claim_RevertIfNoDepositsFound() public {
93-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](0);
94+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](0);
9495
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
9596
vm.expectRevert(abi.encodeWithSelector(IBridgeMintBurn.NoDepositsFound.selector));
9697
_bridge.claim(0, _mirror, bytes("0x1"));
9798
}
9899

99100
function test_Claim_RevertIfMultipleDepositsFound() public {
100-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](2);
101+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](2);
101102
logs[0] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
102103
logs[1] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
103104
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
@@ -108,7 +109,7 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
108109
function test_Claim_RevertIfMirrorTokenNotFound() public {
109110
// Use a token not mapped in mirrorTokens
110111
address unknownMirror = address(0xBEEF);
111-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
112+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
112113
logs[0] = _makeLog(0, unknownMirror, DEPOSIT_AMOUNT, recipient);
113114
_mockEthGetLogs(0, bytes("0x1"), unknownMirror, logs);
114115

@@ -117,7 +118,7 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
117118
}
118119

119120
function test_Claim_RevertIfAlreadyProcessed() public {
120-
BridgeMintBurn.RpcLog[] memory logs = new BridgeMintBurn.RpcLog[](1);
121+
EthGetLogsPrecompileHelperTypes.RpcLog[] memory logs = new EthGetLogsPrecompileHelperTypes.RpcLog[](1);
121122
logs[0] = _makeLog(0, _mirror, DEPOSIT_AMOUNT, recipient);
122123
_mockEthGetLogs(0, bytes("0x1"), _mirror, logs);
123124
_bridge.claim(0, _mirror, bytes("0x1"));
@@ -136,7 +137,7 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
136137
}
137138

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

142143
vm.expectRevert(abi.encodeWithSelector(IBridgeMintBurn.PrecompileCallFailed.selector));
@@ -171,22 +172,25 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
171172
function _buildArgs(uint256 id, bytes memory fromBlock, address tokenAddr)
172173
internal
173174
pure
174-
returns (BridgeMintBurn.ExternalEthGetLogsArgs memory)
175+
returns (EthGetLogsPrecompileHelperTypes.PrecompileArgs memory)
175176
{
176-
BridgeMintBurn.EthGetLogsArgs memory inner = BridgeMintBurn.EthGetLogsArgs({
177+
EthGetLogsPrecompileHelperTypes.RpcArgs memory inner = EthGetLogsPrecompileHelperTypes.RpcArgs({
177178
fromBlock: fromBlock,
178179
toBlock: hex"66696e616c697a6564",
179180
addr: tokenAddr,
180181
blockHash: bytes32(0),
181182
topics: _buildTopics(id, tokenAddr)
182183
});
183-
return BridgeMintBurn.ExternalEthGetLogsArgs({chainId: 1, ethGetLogsArgs: inner});
184+
return EthGetLogsPrecompileHelperTypes.PrecompileArgs({chainId: 1, ethGetLogsArgs: inner});
184185
}
185186

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

@@ -200,9 +204,9 @@ contract BridgeMintBurnTest is BridgeBehaviorTest {
200204
function _makeLog(uint256 id, address tokenAddr, uint256 amount, address to)
201205
internal
202206
pure
203-
returns (BridgeMintBurn.RpcLog memory)
207+
returns (EthGetLogsPrecompileTypes.RpcLog memory)
204208
{
205-
return BridgeMintBurn.RpcLog({
209+
return EthGetLogsPrecompileTypes.RpcLog({
206210
addr: tokenAddr,
207211
topics: _buildTopics(id, tokenAddr),
208212
data: abi.encode(amount, to),

solidity-sdk/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generate:
2+
forge bind --crate-name pod-solidity-sdk-types --bindings-path ./bindings --alloy-version 1.0.24 --force --no-metadata --select ".*HelperTypes$$" --overwrite
3+
4+
check:
5+
forge bind --crate-name pod-solidity-sdk-types --bindings-path ./bindings --alloy-version 1.0.24 --force --no-metadata --select ".*HelperTypes$$"
6+
7+
.PHONY: generate
8+
.PHONY: check

solidity-sdk/bindings/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "pod-solidity-sdk-types"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
alloy = { version = "1.0.24", features = ["sol-types", "contract"] }
8+
serde = { version = "1.0", features = ["derive"] }

0 commit comments

Comments
 (0)