11// SPDX-License-Identifier: MIT
22pragma solidity ^ 0.8.28 ;
33
4- contract GenericRecipient {
4+ import {IMessageRelayer} from "src/protocol/IMessageRelayer.sol " ;
5+
6+ interface IGenericRecipient {
7+ function setSuccess (bool _callWillSucceed ) external ;
8+ function setReentrancyAttack (bool _shouldAttack ) external ;
9+ }
10+
11+ contract GenericRecipient is IGenericRecipient {
512 bool private callWillSucceed = true ;
13+ bool private shouldReenterAttack = false ;
14+ address private relayer;
15+ uint256 private reentrancyCounter = 0 ;
616
717 error CallFailed ();
818
919 event FunctionCalled ();
20+ event ReentrancyAttempt (uint256 counter );
21+
22+ constructor (address _relayer ) {
23+ relayer = _relayer;
24+ }
1025
1126 function setSuccess (bool _callWillSucceed ) external {
1227 callWillSucceed = _callWillSucceed;
1328 }
1429
30+ function setReentrancyAttack (bool _shouldAttack ) external {
31+ shouldReenterAttack = _shouldAttack;
32+ }
33+
1534 fallback () external payable {
1635 _simulateFunctionCall ();
1736 }
@@ -23,5 +42,12 @@ contract GenericRecipient {
2342 function _simulateFunctionCall () internal {
2443 require (callWillSucceed, CallFailed ());
2544 emit FunctionCalled ();
45+
46+ if (shouldReenterAttack) {
47+ reentrancyCounter++ ;
48+ emit ReentrancyAttempt (reentrancyCounter);
49+
50+ IMessageRelayer (relayer).receiveMessage (address (this ), 0 , address (this ), 0 , "0x " );
51+ }
2652 }
2753}
0 commit comments