Skip to content

Commit cf0b6b8

Browse files
authored
fix: add check to ensure depositor is a valid EVM address (#874)
Signed-off-by: Matt Rice <[email protected]>
1 parent 6aeb480 commit cf0b6b8

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

contracts/SpokePool.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,9 @@ abstract contract SpokePool is
13111311
**************************************/
13121312

13131313
function _depositV3(DepositV3Params memory params) internal {
1314+
// Verify depositor is a valid EVM address.
1315+
params.depositor.checkAddress();
1316+
13141317
// Check that deposit route is enabled for the input token. There are no checks required for the output token
13151318
// which is pulled from the relayer at fill time and passed through this contract atomically to the recipient.
13161319
if (!enabledDepositRoutes[params.inputToken.toAddress()][params.destinationChainId]) revert DisabledRoute();

contracts/libraries/AddressConverters.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ library Bytes32ToAddress {
88
error InvalidBytes32();
99

1010
function toAddress(bytes32 _bytes32) internal pure returns (address) {
11-
if (uint256(_bytes32) >> 160 != 0) {
12-
revert InvalidBytes32();
13-
}
11+
checkAddress(_bytes32);
1412
return address(uint160(uint256(_bytes32)));
1513
}
1614

1715
function toAddressUnchecked(bytes32 _bytes32) internal pure returns (address) {
1816
return address(uint160(uint256(_bytes32)));
1917
}
18+
19+
function checkAddress(bytes32 _bytes32) internal pure {
20+
if (uint256(_bytes32) >> 160 != 0) {
21+
revert InvalidBytes32();
22+
}
23+
}
2024
}
2125

2226
library AddressToBytes32 {

test/evm/hardhat/SpokePool.Deposit.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,15 @@ describe("SpokePool Depositor Logic", async function () {
853853
const functionCalldata = spokePool.interface.encodeFunctionData("deposit", [...depositArgs]);
854854
await expect(spokePool.connect(depositor).callback(functionCalldata)).to.be.reverted;
855855
});
856+
it("depositor must be valid evm address", async function () {
857+
const functionCalldata = spokePool.interface.encodeFunctionData("deposit", [
858+
...getDepositArgsFromRelayData({
859+
...relayData,
860+
depositor: "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d",
861+
}),
862+
]);
863+
await expect(spokePool.connect(depositor).callback(functionCalldata)).to.be.reverted;
864+
});
856865
it("unsafe deposit ID", async function () {
857866
// new deposit ID should be the uint256 equivalent of the keccak256 hash of packed {msg.sender, depositor, forcedDepositId}.
858867
const forcedDepositId = "99";

0 commit comments

Comments
 (0)