@@ -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 {ScrollChainValidium} from "../../validium/ScrollChainValidium.sol " ;
1718
1819import {TransferReentrantToken} from "../mocks/tokens/TransferReentrantToken.sol " ;
1920import {FeeOnTransferToken} from "../mocks/tokens/FeeOnTransferToken.sol " ;
@@ -128,47 +129,63 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
128129 _deposit (sender, amount, recipient, gasLimit);
129130 }
130131
132+ function testDepositERC20WrongKey (
133+ uint256 amount ,
134+ bytes memory recipient ,
135+ uint256 gasLimit
136+ ) public {
137+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
138+ hevm.expectRevert (ScrollChainValidium.ErrorUnknownEncryptionKey.selector );
139+ gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId + 1 );
140+ }
141+
131142 function testDepositReentrantToken (uint256 amount ) public {
143+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
144+
132145 // should revert, reentrant before transfer
133146 reentrantToken.setReentrantCall (
134147 address (gateway),
135148 0 ,
136149 abi.encodeWithSignature (
137- "depositERC20(address,bytes,uint256,uint256) " ,
150+ "depositERC20(address,bytes,uint256,uint256,uint256 ) " ,
138151 address (reentrantToken),
139152 new bytes (0 ),
140153 amount,
141- defaultGasLimit
154+ defaultGasLimit,
155+ keyId
142156 ),
143157 true
144158 );
145159 amount = bound (amount, 1 , reentrantToken.balanceOf (address (this )));
146160 hevm.expectRevert ("ReentrancyGuard: reentrant call " );
147- gateway.depositERC20 (address (reentrantToken), new bytes (0 ), amount, defaultGasLimit);
161+
162+ gateway.depositERC20 (address (reentrantToken), new bytes (0 ), amount, defaultGasLimit, keyId);
148163
149164 // should revert, reentrant after transfer
150165 reentrantToken.setReentrantCall (
151166 address (gateway),
152167 0 ,
153168 abi.encodeWithSignature (
154- "depositERC20(address,bytes,uint256,uint256) " ,
169+ "depositERC20(address,bytes,uint256,uint256,uint256 ) " ,
155170 address (reentrantToken),
156171 new bytes (0 ),
157172 amount,
158- defaultGasLimit
173+ defaultGasLimit,
174+ keyId
159175 ),
160176 false
161177 );
162178 amount = bound (amount, 1 , reentrantToken.balanceOf (address (this )));
163179 hevm.expectRevert ("ReentrancyGuard: reentrant call " );
164- gateway.depositERC20 (address (reentrantToken), new bytes (0 ), amount, defaultGasLimit);
180+ gateway.depositERC20 (address (reentrantToken), new bytes (0 ), amount, defaultGasLimit, keyId );
165181 }
166182
167183 function testFeeOnTransferTokenFailed (uint256 amount ) public {
168184 feeToken.setFeeRate (1e9 );
169185 amount = bound (amount, 1 , feeToken.balanceOf (address (this )));
186+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
170187 hevm.expectRevert (L1ERC20GatewayValidium.ErrorAmountIsZero.selector );
171- gateway.depositERC20 (address (feeToken), new bytes (0 ), amount, defaultGasLimit);
188+ gateway.depositERC20 (address (feeToken), new bytes (0 ), amount, defaultGasLimit, keyId );
172189 }
173190
174191 function testFeeOnTransferTokenSucceed (uint256 amount , uint256 feeRate ) public {
@@ -179,7 +196,8 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
179196 // should succeed, for valid amount
180197 uint256 balanceBefore = feeToken.balanceOf (address (gateway));
181198 uint256 fee = (amount * feeRate) / 1e9 ;
182- gateway.depositERC20 (address (feeToken), new bytes (0 ), amount, defaultGasLimit);
199+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
200+ gateway.depositERC20 (address (feeToken), new bytes (0 ), amount, defaultGasLimit, keyId);
183201 uint256 balanceAfter = feeToken.balanceOf (address (gateway));
184202 assertEq (balanceBefore + amount - fee, balanceAfter);
185203 }
@@ -245,7 +263,8 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
245263 amount = bound (amount, 1 , l1Token.balanceOf (address (this )));
246264
247265 // deposit some token to L1ERC20GatewayValidium
248- gateway.depositERC20 (address (l1Token), new bytes (0 ), amount, defaultGasLimit);
266+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
267+ gateway.depositERC20 (address (l1Token), new bytes (0 ), amount, defaultGasLimit, keyId);
249268
250269 // do finalize withdraw token
251270 bytes memory message = abi.encodeWithSelector (
@@ -302,7 +321,8 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
302321 amount = bound (amount, 1 , l1Token.balanceOf (address (this )));
303322
304323 // deposit some token to L1ERC20GatewayValidium
305- gateway.depositERC20 (address (l1Token), new bytes (0 ), amount, defaultGasLimit);
324+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
325+ gateway.depositERC20 (address (l1Token), new bytes (0 ), amount, defaultGasLimit, keyId);
306326
307327 // do finalize withdraw token
308328 bytes memory message = abi.encodeWithSelector (
@@ -385,11 +405,12 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
385405 );
386406
387407 if (amount == 0 ) {
408+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
388409 hevm.expectRevert (L1ERC20GatewayValidium.ErrorAmountIsZero.selector );
389410 if (from == address (this )) {
390- gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit);
411+ gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId );
391412 } else {
392- gateway.depositERC20 (address (l1Token), from, recipient, amount, gasLimit);
413+ gateway.depositERC20 (address (l1Token), from, recipient, amount, gasLimit, keyId );
393414 }
394415 } else {
395416 // emit QueueTransaction from L1MessageQueueV2
@@ -412,10 +433,11 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
412433 uint256 gatewayBalance = l1Token.balanceOf (address (gateway));
413434 uint256 feeVaultBalance = address (feeVault).balance;
414435 assertEq (l1Messenger.messageSendTimestamp (keccak256 (xDomainCalldata)), 0 );
436+ (uint256 keyId , ) = rollup.getLatestEncryptionKey ();
415437 if (from == address (this )) {
416- gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit);
438+ gateway.depositERC20 (address (l1Token), recipient, amount, gasLimit, keyId );
417439 } else {
418- gateway.depositERC20 (address (l1Token), from, recipient, amount, gasLimit);
440+ gateway.depositERC20 (address (l1Token), from, recipient, amount, gasLimit, keyId );
419441 }
420442 assertEq (amount + gatewayBalance, l1Token.balanceOf (address (gateway)));
421443 assertEq (feeVaultBalance, address (feeVault).balance);
@@ -433,7 +455,8 @@ contract L1ERC20GatewayValidiumTest is ValidiumTestBase {
433455 address (counterpartGateway),
434456 address (messenger),
435457 address (template),
436- address (factory)
458+ address (factory),
459+ address (rollup)
437460 )
438461 )
439462 );
0 commit comments