@@ -14,6 +14,7 @@ import {AddressAliasHelper} from "../../libraries/common/AddressAliasHelper.sol"
1414import {IL1ERC20GatewayValidium} from "../../validium/IL1ERC20GatewayValidium.sol " ;
1515import {IL2ERC20GatewayValidium} from "../../validium/IL2ERC20GatewayValidium.sol " ;
1616import {L1ERC20GatewayValidium} from "../../validium/L1ERC20GatewayValidium.sol " ;
17+ import {L1WETHGatewayValidium} from "../../validium/L1WETHGatewayValidium.sol " ;
1718import {ScrollChainValidium} from "../../validium/ScrollChainValidium.sol " ;
1819
1920import {TransferReentrantToken} from "../mocks/tokens/TransferReentrantToken.sol " ;
@@ -46,6 +47,7 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
4647 ScrollStandardERC20 private template;
4748 ScrollStandardERC20Factory private factory;
4849 L2StandardERC20Gateway private counterpartGateway;
50+ L1WETHGatewayValidium private wethGateway = L1WETHGatewayValidium (address (1 )); // placeholder for tests
4951
5052 MockERC20 private l1Token;
5153 MockERC20 private l2Token;
@@ -120,23 +122,43 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
120122 _deposit (address (this ), amount, recipient, gasLimit);
121123 }
122124
123- function testDepositERC20WithSender (
124- address sender ,
125+ function testDepositERC20WrongKey (
125126 uint256 amount ,
126127 bytes memory recipient ,
127128 uint256 gasLimit
128129 ) public {
129- _deposit (sender, amount, recipient, gasLimit);
130+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
131+ hevm.expectRevert (ScrollChainValidium.ErrorUnknownEncryptionKey.selector );
132+ gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId + 1 );
130133 }
131134
132- function testDepositERC20WrongKey (
135+ function testDepositERC20WithRealSenderUnauthorized (
136+ address attacker ,
137+ address victim ,
133138 uint256 amount ,
134139 bytes memory recipient ,
135140 uint256 gasLimit
136141 ) public {
142+ hevm.assume (attacker != address (0 ));
143+ hevm.assume (attacker != address (wethGateway));
144+
145+ amount = bound (amount, 1 , l1Token.balanceOf (address (this )));
146+ gasLimit = bound (gasLimit, defaultGasLimit / 2 , defaultGasLimit);
137147 (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
138- hevm.expectRevert (ScrollChainValidium.ErrorUnknownEncryptionKey.selector );
139- gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId + 1 );
148+
149+ // Transfer tokens to attacker
150+ l1Token.transfer (attacker, amount);
151+
152+ // Attacker approves gateway
153+ hevm.startPrank (attacker);
154+ l1Token.approve (address (gateway), amount);
155+
156+ // Attacker tries to call depositERC20 with victim as _realSender
157+ // This should revert with ErrorCallerNotWethGateway
158+ hevm.expectRevert (L1ERC20GatewayValidium.ErrorCallerNotWethGateway.selector );
159+ gateway.depositERC20 (address (l1Token), victim, recipient, amount, gasLimit, keyId);
160+
161+ hevm.stopPrank ();
140162 }
141163
142164 function testDepositReentrantToken (uint256 amount ) public {
@@ -407,12 +429,11 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
407429 if (amount == 0 ) {
408430 (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
409431 hevm.expectRevert (L1ERC20GatewayValidium.ErrorAmountIsZero.selector );
410- if (from == address (this )) {
411- gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId);
412- } else {
413- gateway.depositERC20 (address (l1Token), from, recipient, amount, gasLimit, keyId);
414- }
432+ gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId);
415433 } else {
434+ // Note: from parameter is only used in event expectations, not in actual calls
435+ // The depositERC20 function always uses msg.sender for actual deposits
436+
416437 // emit QueueTransaction from L1MessageQueueV2
417438 {
418439 hevm.expectEmit (true , true , false , true );
@@ -434,11 +455,7 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
434455 uint256 feeVaultBalance = address (feeVault).balance;
435456 assertEq (l1Messenger.messageSendTimestamp (keccak256 (xDomainCalldata)), 0 );
436457 (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
437- if (from == address (this )) {
438- gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId);
439- } else {
440- gateway.depositERC20 (address (l1Token), from, recipient, amount, gasLimit, keyId);
441- }
458+ gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId);
442459 assertEq (amount + gatewayBalance, l1Token.balanceOf (address (gateway)));
443460 assertEq (feeVaultBalance, address (feeVault).balance);
444461 assertGt (l1Messenger.messageSendTimestamp (keccak256 (xDomainCalldata)), 0 );
@@ -456,7 +473,8 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
456473 address (messenger),
457474 address (template),
458475 address (factory),
459- address (rollup)
476+ address (rollup),
477+ address (wethGateway)
460478 )
461479 )
462480 );
0 commit comments