Blockchain / Global / Address

Contract

0x8dA19f56174aCe229c5e914EBa7DBe81a31d99C3

Balance
0 SOMI
Transactions sent
1
Type
Contract · 2,435 bytes of code

BatchVRFCoordinatorV2Plus Verified

Compiler
solc 0.8.19+commit.7dd6d404
Language
Solidity
Optimization
Yes, 200 runs
EVM version
—
License
—
Verified
2026-10-12

contracts/v0.8/BatchVRFCoordinatorV2plus.sol

Solidity


// Sources flattened with hardhat v2.20.1 https://hardhat.org

// SPDX-License-Identifier: MIT

// File src/v0.8/vrf/VRFTypes.sol

// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.6;

/**
 * @title VRFTypes
 * @notice The VRFTypes library is a collection of types that is required to fulfill VRF requests
 * 	on-chain. They must be ABI-compatible with the types used by the coordinator contracts.
 */
library VRFTypes {
  // ABI-compatible with VRF.Proof.
  // This proof is used for VRF V2 and V2Plus.
  struct Proof {
    uint256[2] pk;
    uint256[2] gamma;
    uint256 c;
    uint256 s;
    uint256 seed;
    address uWitness;
    uint256[2] cGammaWitness;
    uint256[2] sHashWitness;
    uint256 zInv;
  }

  // ABI-compatible with VRFCoordinatorV2.RequestCommitment.
  // This is only used for VRF V2.
  struct RequestCommitment {
    uint64 blockNum;
    uint64 subId;
    uint32 callbackGasLimit;
    uint32 numWords;
    address sender;
  }

  // ABI-compatible with VRFCoordinatorV2Plus.RequestCommitment.
  // This is only used for VRF V2Plus.
  struct RequestCommitmentV2Plus {
    uint64 blockNum;
    uint256 subId;
    uint32 callbackGasLimit;
    uint32 numWords;
    address sender;
    bytes extraArgs;
  }
}


// File src/v0.8/vrf/dev/BatchVRFCoordinatorV2Plus.sol

// Original license: SPDX_License_Identifier: MIT
// solhint-disable-next-line one-contract-per-file
pragma solidity 0.8.19;

/**
 * @title BatchVRFCoordinatorV2Plus
 * @notice The BatchVRFCoordinatorV2Plus contract acts as a proxy to write many random responses to the
 * @notice provided VRFCoordinatorV2Plus contract efficiently in a single transaction.
 */
contract BatchVRFCoordinatorV2Plus {
  // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i
  IVRFCoordinatorV2PlusFulfill public immutable COORDINATOR;

  event ErrorReturned(uint256 indexed requestId, string reason);
  event RawErrorReturned(uint256 indexed requestId, bytes lowLevelData);

  constructor(address coordinatorAddr) {
    COORDINATOR = IVRFCoordinatorV2PlusFulfill(coordinatorAddr);
  }

  /**
   * @notice fulfills multiple randomness requests with the provided proofs and commitments.
   * @param proofs the randomness proofs generated by the VRF provider.
   * @param rcs the request commitments corresponding to the randomness proofs.
   */
  function fulfillRandomWords(
    VRFTypes.Proof[] calldata proofs,
    VRFTypes.RequestCommitmentV2Plus[] calldata rcs
  ) external {
    // solhint-disable-next-line gas-custom-errors
    require(proofs.length == rcs.length, "input array arg lengths mismatch");
    for (uint256 i = 0; i < proofs.length; ++i) {
      try COORDINATOR.fulfillRandomWords(proofs[i], rcs[i], false) returns (uint96 /* payment */) {
        continue;
      } catch Error(string memory reason) {
        uint256 requestId = _getRequestIdFromProof(proofs[i]);
        emit ErrorReturned(requestId, reason);
      } catch (bytes memory lowLevelData) {
        uint256 requestId = _getRequestIdFromProof(proofs[i]);
        emit RawErrorReturned(requestId, lowLevelData);
      }
    }
  }

  /**
   * @notice Returns the proving key hash associated with this public key.
   * @param publicKey the key to return the hash of.
   */
  function _hashOfKey(uint256[2] memory publicKey) internal pure returns (bytes32) {
    return keccak256(abi.encode(publicKey));
  }

  /**
   * @notice Returns the request ID of the request associated with the given proof.
   * @param proof the VRF proof provided by the VRF oracle.
   */
  function _getRequestIdFromProof(VRFTypes.Proof memory proof) internal pure returns (uint256) {
    bytes32 keyHash = _hashOfKey(proof.pk);
    return uint256(keccak256(abi.encode(keyHash, proof.seed)));
  }
}

interface IVRFCoordinatorV2PlusFulfill {
  function fulfillRandomWords(
    VRFTypes.Proof calldata proof,
    VRFTypes.RequestCommitmentV2Plus calldata rc,
    bool onlyPremium
  ) external returns (uint96);
}
ABI · 5 entries
json
[
  {
    "type": "constructor",
    "inputs": [
      {
        "name": "coordinatorAddr",
        "type": "address",
        "internalType": "address"
      }
    ],
    "stateMutability": "nonpayable"
  },
  {
    "name": "ErrorReturned",
    "type": "event",
    "inputs": [
      {
        "name": "requestId",
        "type": "uint256",
        "indexed": true,
        "internalType": "uint256"
      },
      {
        "name": "reason",
        "type": "string",
        "indexed": false,
        "internalType": "string"
      }
    ],
    "anonymous": false
  },
  {
    "name": "RawErrorReturned",
    "type": "event",
    "inputs": [
      {
        "name": "requestId",
        "type": "uint256",
        "indexed": true,
        "internalType": "uint256"
      },
      {
        "name": "lowLevelData",
        "type": "bytes",
        "indexed": false,
        "internalType": "bytes"
      }
    ],
    "anonymous": false
  },
  {
    "name": "COORDINATOR",
    "type": "function",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "address",
        "internalType": "contract IVRFCoordinatorV2PlusFulfill"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "fulfillRandomWords",
    "type": "function",
    "inputs": [
      {
        "name": "proofs",
        "type": "tuple[]",
        "components": [
          {
            "name": "pk",
            "type": "uint256[2]",
            "internalType": "uint256[2]"
          },
          {
            "name": "gamma",
            "type": "uint256[2]",
            "internalType": "uint256[2]"
          },
          {
            "name": "c",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "s",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "seed",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "uWitness",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "cGammaWitness",
            "type": "uint256[2]",
            "internalType": "uint256[2]"
          },
          {
            "name": "sHashWitness",
            "type": "uint256[2]",
            "internalType": "uint256[2]"
          },
          {
            "name": "zInv",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "internalType": "struct VRFTypes.Proof[]"
      },
      {
        "name": "rcs",
        "type": "tuple[]",
        "components": [
          {
            "name": "blockNum",
            "type": "uint64",
            "internalType": "uint64"
          },
          {
            "name": "subId",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "callbackGasLimit",
            "type": "uint32",
            "internalType": "uint32"
          },
          {
            "name": "numWords",
            "type": "uint32",
            "internalType": "uint32"
          },
          {
            "name": "sender",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "extraArgs",
            "type": "bytes",
            "internalType": "bytes"
          }
        ],
        "internalType": "struct VRFTypes.RequestCommitmentV2Plus[]"
      }
    ],
    "outputs": [],
    "stateMutability": "nonpayable"
  }
]