Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle mocking #38

Merged
merged 19 commits into from
Feb 14, 2024
Merged

Oracle mocking #38

merged 19 commits into from
Feb 14, 2024

Conversation

arbaz-immunefi
Copy link
Contributor

Vulnerability Type

This template is designed for developing attack proof of concepts (PoCs) that exploit vulnerabilities which rely on data returned by an oracle. Please note: When crafting a PoC which manipulates oracle data, the oracle manipulation must be achievable independently from the attack. Oracle mocking allows for easier testing of situations where the mocked oracle data is known to be achievable by other means. If the data returned is not achievable in normal operation of the Oracle, the vulnerability is not considered valid. The template supports manipulation of the following oracles:

Ethereum

Network Oracle Provider Library
Ethereum Chainlink Chainlink
Ethereum Band Oracle Band
Ethereum Pyth Oracle Pyth

Usage

The following attack contract demonstrates simple oracle data manipulation:

Extend the MockOracleExample contract:

contract Attack is MockOracleExample { }

Please be aware that various oracles adhere to distinct mockOracleData structures and types.

To identify the specific naming parameters required, examine the library code. For instance, within Pyth, there exists a PriceFeeds library that contains all the bytes32 quotes for the pair.

For guidance on how to import and utilize the libraries, refer to the example provided below.

    import "../lib/MockPyth.sol";
    import "../lib/MockChainLink.sol";
    import "../lib/MockBand.sol";

    function initiateAttack() external {
        //1. PYTH ORACLE
        MockPyth.mockOracleData(PriceFeeds.Crypto_BNB_USD, 1337);

        //2. CHAINLINK ORACLE
        MockChainLink.mockOracleData(EthereumTokens.LINK, Fiat.USD, 1337);

        //3. BAND ORACLE
        MockBand.mockOracleData("STRK", "USD", 1337);
        _executeAttack();
    }

lib/openzeppelin-contracts Outdated Show resolved Hide resolved
Copy link
Collaborator

@janbro janbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arbaz-immunefi arbaz-immunefi merged commit c787db7 into main Feb 14, 2024
2 of 4 checks passed
@arbaz-immunefi arbaz-immunefi deleted the oracle_mocking branch February 14, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants