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

docs: validate public input first version #648

Merged

Conversation

NicolasRampoldi
Copy link
Contributor

@NicolasRampoldi NicolasRampoldi commented Jul 18, 2024

Description

  • This PR adds an example of validating public input of a Risc0 proof in a smart contract.

To Test

  • Follow the examples guide in the docs. Remember, to send the required arguments to the verifyBatchInclusion method in the contract, you first need to encode them to hex.
    To do so, you can use the following nodejs function:
function bytesToHex(bytes) {
    let hex = [];
    for (let i = 0; i < bytes.length; i++) {
        let current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];
        hex.push((current >>> 4).toString(16));
        hex.push((current & 0xF).toString(16));
    }
    return hex.join("");
}

You will also need to encode the pubInputBytes to hex. This is the risc_zero_fibonacci.pub file generated with the proof. For the proof we are generating, it is 0xf404000086070000 so you can use that value.
-Then, use cast to interact with the contract:

cast send --rpc-url https://ethereum-holesky-rpc.publicnode.com <CONTRACT_ADDRESS> "verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256,bytes)" <proofCommitment> <pubInputCommitment> <programIdCommitment> <proofGeneratorAddr> <batchMerkleRoot> <merkleProof> <verificationDataBatchIndex> <pubInputBytes> --private-key <PRIVATE_KEY>
  • This transaction should take a little time, after that, you can check the contract address in Etherscan Holesky and you will see the event emitted with the two hex values corresponding to the two last numbers of the Fibonacci sequence.

@NicolasRampoldi NicolasRampoldi self-assigned this Jul 18, 2024
@NicolasRampoldi NicolasRampoldi linked an issue Jul 18, 2024 that may be closed by this pull request
@NicolasRampoldi NicolasRampoldi marked this pull request as ready for review July 18, 2024 19:58
Copy link
Contributor

@taturosati taturosati left a comment

Choose a reason for hiding this comment

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

Need to update sdk to work with new version + minor comments

@NicolasRampoldi NicolasRampoldi merged commit 1f2242b into main Aug 8, 2024
10 checks passed
@NicolasRampoldi NicolasRampoldi deleted the 640-docs-create-example-that-checks-public-input branch August 8, 2024 20:33
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.

docs: create example that checks public input
3 participants