-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from hansstammler/feat_issue_145
feat #145: finished implementing monitors and exploits for cross-chai…
- Loading branch information
Showing
11 changed files
with
246 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
contracts/src/cross-chain/AvaxVaultOracleVulnerability2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
pragma solidity ^0.8.20; | ||
|
||
interface AvaxRouter { | ||
function avax_payOut( | ||
address payable to, | ||
address asset, | ||
uint amount, | ||
string memory memo | ||
) external payable; | ||
} | ||
|
||
interface Oracle { | ||
function getExchangeRate(uint amount, string memory sourceAsset, string memory targetAsset) external view returns (uint); | ||
function getPrice(string memory asset) external view returns (uint256); | ||
} | ||
|
||
contract AvaxVaultOracleVulnerability2 { | ||
address owner; | ||
AvaxRouter routerContract; | ||
Oracle oracleContract; | ||
|
||
constructor(address _routerContract, address _oracleContract) { | ||
owner = msg.sender; | ||
routerContract = AvaxRouter(_routerContract); | ||
oracleContract = Oracle(_oracleContract); | ||
} | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Only the owner of this contract can call this function"); | ||
_; | ||
} | ||
|
||
//Receive funds when msg.data is empty | ||
receive() external payable {} | ||
|
||
//Receive funds when msg.data is not empty | ||
fallback() external payable {} | ||
|
||
function fund() external payable {} | ||
|
||
function avax_bridgeForwards( | ||
address payable to, | ||
address asset, | ||
uint amountPaid, | ||
string memory sourceAsset, | ||
string memory memo, | ||
uint expiration | ||
) external onlyOwner { | ||
require(block.timestamp > expiration); | ||
uint amount = (oracleContract.getPrice(sourceAsset) * amountPaid)/1000; | ||
require( | ||
address(this).balance >= amount, | ||
"Vault has insufficient funds" | ||
); | ||
routerContract.avax_payOut{value: amount}( | ||
to, | ||
asset, | ||
amount, | ||
memo | ||
); | ||
} | ||
|
||
function avax_bridgeForwardsERC20( | ||
address payable to, | ||
address asset, //actual address of asset | ||
uint amountPaid, | ||
string memory sourceAsset, | ||
string memory targetAsset,//has format AVAX.0x12341... | ||
string memory memo, | ||
uint expiration | ||
) external onlyOwner { | ||
require(block.timestamp < expiration); | ||
uint amount = oracleContract.getExchangeRate(amountPaid, sourceAsset, targetAsset); | ||
routerContract.avax_payOut(to, asset, amount, memo); | ||
} | ||
} |
Oops, something went wrong.