Extended Randomness Callback

You will need to extend the randomness callback in the following way to integrate the verification of the proof.

function randomnessCallback(
        bytes32 randomNumber,
        uint256 requestId,
        bytes memory proof
    ) external {
        // Ensure the caller is the VRFConsumer contract
        require(
            msg.sender == address(0x7efDa6beA0e3cE66996FA3D82953FF232650ea67),
            "Only the VRFConsumer can call this function"
        );

    // Retrieve the randomness request details from the VRFConsumer contract
    RandomnessRequest memory request = vrfConsumer.getRequestById(requestId);
        
    // Verify the proof to ensure the random number was generated correctly
    require(
        _verifyProof(
            request.userProvidedSeed,
            requestId,
            randomNumber,
            proof
        ),
        "Invalid proof"
    );

    // Check if the requestId matches the lastRequestId stored in the contract
    require(requestId == lastRequestId, "Request ID does not match the last request");

    // Store the random number and proof in the contract state
    lastRandomNumber = randomNumber;
    lastProof = proof;

    // Additional logic using the random number can be added here
}

In this function we can see an example of how we call the getRequestById function with the requestId and retrieve the entire request details on chain in the form of the RandomnessRequest struct.

Here we grab the provided seed to show how this can all be done without storing anything in the calling contract.

Now let's go to the verifyProof function.

Last updated