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

panic: arithmetic underflow or overflow | VRFCoordinatorV2_5Mock::createSubscription function. #33

Open
alymurtazamemon opened this issue Jul 18, 2024 · 2 comments

Comments

@alymurtazamemon
Copy link

I am implementing a new version of VRFCoordinator v2.5 in my code and for local testing I am using VRFCoordinatorV2_5Mock contract. Unfortunately, while calling the createSubscription function of this contract (as instructed in the Local testing using a mock subscription contract) I am getting this error;

[⠢] Compiling...
[⠰] Compiling 2 files with 0.8.19
[⠔] Solc 0.8.19 finished in 1.20s
Compiler run successful!
0x4e487b710000000000000000000000000000000000000000000000000000000000000011
Traces:
  [4282228] → new DeploySubscriptionVRFV2_5@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
    └─ ← [Return] 21276 bytes of code

  [6225604] DeploySubscriptionVRFV2_5::run()
    ├─ [3279821] → new SubscriptionVRF_HelperConfig@0xC7f2Cf4845C6db0e1a1e91ED41Bcd0FcC1b0E141
    │   └─ ← [Return] 16160 bytes of code
    ├─ [2909757] SubscriptionVRF_HelperConfig::getConfig()
    │   ├─ [0] VM::startBroadcast()
    │   │   └─ ← [Return] 
    │   ├─ [2863541] → new VRFCoordinatorV2_5Mock@0x5FbDB2315678afecb367f032d93F642f64180aa3
    │   │   ├─ emit ConfigSet()
    │   │   └─ ← [Return] 13951 bytes of code
    │   ├─ [2616] VRFCoordinatorV2_5Mock::createSubscription()
    │   │   └─ ← [Revert] panic: arithmetic underflow or overflow (0x11)
    │   └─ ← [Revert] panic: arithmetic underflow or overflow (0x11)
    └─ ← [Revert] panic: arithmetic underflow or overflow (0x11)

After some debugging, I found that the error was caused by the subtraction of blockhash(block.number - 1) in the createSubscription function while generating subId in this contract

chainlink-brownie-contracts/contracts/src/v0.8/vrf/dev/SubscriptionAPI.sol

I removed the -1 from this line, and everything started working as expected. The modified line now looks like this:

subId = uint256(keccak256(abi.encodePacked(msg.sender, blockhash(block.number), address(this), currentSubNonce)));

The code may expect block.number > 1, but even after mining some blocks before this transaction, the issue persists.

Leaving this here so others can see the temporary solution and developers can work on a permanent fix for this issue.

here is the code;

function getOrCreateLocalBlockchainNetworkConfig()
    private
    returns (NetworkConfig memory)
{
    if (localNetworkConfig.vrfCoordinatorV2_5 != address(0)) {
        return localNetworkConfig;
    }

    vm.startBroadcast();

    VRFCoordinatorV2_5Mock vrfMock = new VRFCoordinatorV2_5Mock(
        MOCK_BASE_FEE,
        MOCK_GAS_PRICE_LINK,
        MOCK_WEI_PER_UINT_LINK
    );

    uint256 subscriptionId = vrfMock.createSubscription();
    vrfMock.fundSubscription(subscriptionId, FUND_AMOUNT);

    vm.stopBroadcast();

    localNetworkConfig = NetworkConfig({
        vrfCoordinatorV2_5: address(vrfMock),
        subscriptionId: subscriptionId,
        callbackGasLimit: 40000,
        gasLane: 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae
    });

    return localNetworkConfig;
}
@alymurtazamemon
Copy link
Author

This issue has been preview on the Pull Requests. To resolve, Contact the dAppNode page to initiate a chat with the live agent on the chat button to get more information about your request via dAppNode Thank you for posting @alymurtazamemon

Attention! Don't click on this link! It is malicious

@Kendo007
Copy link

Worked for Me!! Thank You!

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

No branches or pull requests

3 participants
@alymurtazamemon @Kendo007 and others