Skip to content

Commit

Permalink
mocks: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
arbaz-immunefi committed Feb 13, 2024
1 parent d58a529 commit 8f50e28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
48 changes: 20 additions & 28 deletions src/oracle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,41 @@ This template is designed for developing attack proof of concepts (PoCs) that ex

| Network | Oracle Provider | Library |
| ------- | --------------- | ------- |
| Ethereum | Chainlink | [Chainlink](./lib/ChainlinkOracle.sol) |
| Ethereum | Chainlink | [Chainlink](./lib/MockChainLink.sol) |
| Ethereum | Band Oracle | [Band](./lib/MockBand.sol) |
| Ethereum | Pyth Oracle | [Pyth](./lib/MockPyth.sol) |

</details>

## Usage
The following attack contract demonstrates simple oracle data manipulation:
* [OracleManipulationExample](./examples/OracleManipulationExample.sol)
* [OracleManipulationExample](./examples/MockOracleExample.sol)

Extend the `OracleMock` contract:
Extend the `MockOracleExample` contract:
```Solidity
contract Attack is OracleMock { }
contract Attack is MockOracleExample { }
```

Call mockOracleData(OracleProviders op, bytes memory data) to manipulate the data returned by the oracle. This function will simulate oracle data, which can be used in _executeAttack() to carry out the attack logic.
Please be aware that various oracles adhere to distinct `mockOracleData` structures and types.

```Solidity
pragma solidity ^0.8.0;
To identify the specific naming parameters required, examine the library code. For instance, within [Pyth](./lib/MockPyth.sol), there exists a `PriceFeeds` library that contains all the `bytes32` quotes for the pair.

import "@immunefi/src/oracle/OracleMock.sol";
import { OracleProviders } from "@immunefi/src/oracle/OracleProvider.sol";
For guidance on how to import and utilize the libraries, refer to the example provided below.

contract Attack is PoC, OracleMock {
// Other contract details...
```Solidity
import "../lib/MockPyth.sol";
import "../lib/MockChainLink.sol";
import "../lib/MockBand.sol";
function initiateAttack() external {
// Call initiateAttack to start the attack process
// This could include setting up necessary state variables
}
//1. PYTH ORACLE
MockPyth.mockOracleData(PriceFeeds.Crypto_BNB_USD, 1337);
function _executeAttack() internal override {
// Example data to be used for the mock oracle
bytes memory data = abi.encodePacked(/* encoded data here */);
// Mocking oracle data for the Chainlink provider
mockOracleData(OracleProviders.CHAINLINK, data);
// Implement your attack logic here, using the mocked data
// ...
}
//2. CHAINLINK ORACLE
MockChainLink.mockOracleData(EthereumTokens.LINK, Fiat.USD, 1337);
function _completeAttack() internal override {
// Complete the attack logic, clean up, etc.
// ...
//3. BAND ORACLE
MockBand.mockOracleData("STRK", "USD", 1337);
_executeAttack();
}
}
```
3 changes: 0 additions & 3 deletions test/mocks/oracles/oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ contract MockOracleExampleTest is Test {

function setUp() public {
vm.createSelectFork("https://rpc.ankr.com/eth");

// vm.mockCall(0x4305FB66699C3B2702D4d05CF36551390A4c69C6, hex"96834ad3", abi.encode(1));

mockOracleExample = new MockOracleExample();
}

Expand Down

0 comments on commit 8f50e28

Please sign in to comment.