Skip to content

docs: Fix proof query example errors#1504

Merged
jcstein merged 3 commits intocelestiaorg:mainfrom
CryptoKass:fix/proof-query-example-errors
Apr 1, 2024
Merged

docs: Fix proof query example errors#1504
jcstein merged 3 commits intocelestiaorg:mainfrom
CryptoKass:fix/proof-query-example-errors

Conversation

@CryptoKass
Copy link
Copy Markdown
Contributor

@CryptoKass CryptoKass commented Mar 30, 2024

Overview

This PR fixes two errors/typos in the "Proof Queries" example code, making it easier to for readers to follow.

  1. toRowProofs missing return statement. This code cannot compile.
  2. Incorrect handling of dataRoot in submitFraudProof always leading to a slice bounds out of range error.
    • The example provides blockRes.Block.DataHash – which is always 32 bytes long, as the dataRoot to the submitFraudProof function. The submitFraudProof function then attempts to get slice that is out of bounds for i, b := range dataRoot[58:].

Missing return statement:

The function signature for toRowProofs claims it should return []client.BinaryMerkleProof, but there is no return statement.

func toRowProofs(proofs []*merkle.Proof) []client.BinaryMerkleProof {
	rowProofs := make([]client.BinaryMerkleProof, len(proofs))
	for i, proof := range proofs {
		sideNodes := make( [][32]byte, len(proof.Aunts))
		for j, sideNode :=  range proof.Aunts {
			var bzSideNode [32]byte
			for k, b := range sideNode {
				bzSideNode[k] = b
			}
			sideNodes[j] = bzSideNode
		}
 		rowProofs[i] = client.BinaryMerkleProof{
			SideNodes: sideNodes,
			Key:       big.NewInt(proof.Index),
			NumLeaves: big.NewInt(proof.Total),
		}
	}
	// missing return statement. 
	// this function must return type []client.BinaryMerkleProof
}

DataRoot slice bounds out of range

The example calls submitFraudProof, providing a 32 byte dataHash as the dataRoot, the called function then attempts to create a slice starting at the 58th byte, which is out of bounds.

func verify() error {
        // ...
	err = submitFraudProof(
		ctx,
		simpleRollupWrapper,
		sharesProof,
		event.ProofNonce.Uint64(),
		uint64(tx.Height),
		dcProof.Proof,
		blockRes.Block.DataHash, // DataHash is always 32 bytes
	)

	return nil
}

func submitFraudProof(
	ctx context.Context,
	simpleRollup *client.Wrappers,
	sharesProof types.ShareProof,
	nonce uint64,
	height uint64,
	dataRootInclusionProof merkle.Proof,
	dataRoot []byte,
) error {
	var blockDataRoot [32]byte
	for i, b := range dataRoot[58:] {  // slice out of bounds as dataRoot/dataHash is always 32 bytes
		blockDataRoot[i] = b
	}

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Summary by CodeRabbit

  • New Features
    • Introduced a copy operation for more efficient data handling in fraud proof submissions.
  • Refactor
    • Improved clarity in the fraud proof process by explicitly returning rowProofs from a function.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2024

Walkthrough

The recent update introduces enhancements to the blockchain's fraud proof mechanisms. A notable addition is the copy operation, which streamlines the process of copying dataRoot into blockDataRoot within the submitFraudProof function. Furthermore, the toRowProofs function has been refined to explicitly return rowProofs, improving clarity and functionality in handling fraud proofs.

Changes

Files Change Summaries
developers/.../proof-queries.md - Added copy operation in submitFraudProof.
- toRowProofs now explicitly returns rowProofs.

🐇✨
In the realm of code, where proofs doth lie,
A rabbit hopped, beneath the digital sky.
With a copy and return, it made its mark,
Lighting up the blockchain, with a spark.
"To secure and to verify," it sang with glee,
A whimsical ode, to data integrity.
🌟🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d809af6 and cdc151f.
Files selected for processing (1)
  • developers/blobstream-proof-queries.md (3 hunks)
Additional Context Used
Additional comments not posted (1)
developers/blobstream-proof-queries.md (1)

1003-1003: The copy operation in the submitFraudProof function is correctly implemented, but it's important to ensure that the source slice (dataRoot) is not shorter than the destination array (blockDataRoot). This is crucial to avoid runtime panics due to slice bounds out of range.

Verification successful

To verify the length of dataRoot before the copy operation, we need to examine the code more closely around the copy operation for any length checks or assignments ensuring dataRoot has at least 32 bytes. Let's proceed with a new script to gather this information.


The verification process has confirmed that there's no explicit length check or assignment ensuring dataRoot has at least 32 bytes before the copy operation in the provided context. This aligns with the concern raised in the review comment about the potential risk of runtime panics if dataRoot is shorter than the destination array blockDataRoot. Therefore, the review comment is accurate.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that dataRoot slice has a length of at least 32 bytes before the copy operation.
grep -B 5 "copy(blockDataRoot\[:\], dataRoot)" developers/blobstream-proof-queries.md | grep "dataRoot \[\]byte"

Length of output: 132



Script:

#!/bin/bash
# Look for any length checks or assignments to `dataRoot` ensuring it has at least 32 bytes before the copy operation.
grep -B 10 "copy(blockDataRoot\[:\], dataRoot)" developers/blobstream-proof-queries.md

Length of output: 355

Comment thread developers/blobstream-proof-queries.md
@CryptoKass
Copy link
Copy Markdown
Contributor Author

DataRoot slice bounds out of range fixed

DataRoot slice bounds out of range fixed

missing return fixed
missing return fixed

@jcstein
Copy link
Copy Markdown
Member

jcstein commented Apr 1, 2024

thank you for fixing this and for the PR @CryptoKass

@jcstein jcstein requested a review from rach-id April 1, 2024 14:23
for i, b := range dataRoot[58:] {
blockDataRoot[i] = b
}
copy(blockDataRoot[:], dataRoot)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use the data root directly without making a copy. For some reason, I thought that the data root would also contain the min-max namespace. Good catch 🙏

@jcstein jcstein merged commit cdbfb7d into celestiaorg:main Apr 1, 2024
jcstein pushed a commit that referenced this pull request Apr 16, 2024
* Add missing return statement in toRowProofs function

* fix dataRoot slice out of range error

* fixes another missing return in toRowProofs
rach-id added a commit that referenced this pull request Apr 18, 2024
…stream (#1489)

* docs: add documentation on how to build rollups on Celestia

* docs: remove question

* docs: one -> value

* docs: explain more the proofs + reformating

* docs: set ETA

* docs: expand on protobuf deserialisation

* docs: expand on protobuf deserialisation

* docs: rewrite, reorganise, explain

* docs: review feedback

* docs: grammar

* docs: remove new lines

* docs: add links to inclusion proofs

* docs: update blobstream contract addresses (#1485)

Replaces #1482

* ci: test removing the CNAME file for clean up of previews. (#1493)

* docs: update blobstream (#1495)

* docs: update bubs-testnet.md with new URIs

* docs: add status page and bridge

* docs: comment out thirdweb bc chain is different now

* docs: update gm portal and contract guides for bubs

* docs: add mocha and namespace

* docs: add bridging context

* [GH Action] Update release tags and commit SHAs for arabica (#1497)

* [automated GH action] update latest release tags & commit sha (arabica)

* Update .vitepress/constants/arabica_versions.js

---------

Co-authored-by: jcstein <jcstein@users.noreply.github.com>
Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com>

* [GH Action] Update release tags and commit SHAs for mocha (#1498)

* [automated GH action] update latest release tags & commit sha (mocha)

* Update .vitepress/constants/mocha_versions.js

---------

Co-authored-by: jcstein <jcstein@users.noreply.github.com>
Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com>

* docs: update go constants for arabiac and mocha

* docs: update to make install for all types of machines (#1502)

* feat: Update node-tutorial.md (#1478)

this is live in v0.13.0 i think, cc @vgonkivs for review

* feat: split consensus node page (#1472)

* docs: split consensus node page

* docs: setup to set up

* docs: setup to set up 2

* docs: coderabbit reviews

* docs: change to  everywhere

* docs: add backlink

---------

Co-authored-by: jcstein <mail@jcstein.dev>

* docs: rollup available link Vitalik (#1505)

* docs: rollup link Vitalik

* docs: changes follow suggestion for example giving comma

* docs: Fix proof query example errors (#1504)

* Add missing return statement in toRowProofs function

* fix dataRoot slice out of range error

* fixes another missing return in toRowProofs

* docs: fix blobstream proof queries code (#1506)

* docs: initial commit, needs revision

* docs: remove old light node config

* docs: edits and refactor page

* docs: minor copy edit

* docs: cleanup for new deployment guide

* docs: todos for deployment guide

* docs: edit intro

* docs: step 1-2

* docs: deploy steps and table

* docs: remainder of deploy steps draft

* docs: change style of quickstart to Quickstart: Deploy an Orbit rollup

* docs: add todos

* docs: update contract addresses

* docs: using light node, namespace, auth token

* docs: add link to arb doc

* docs: add todo

* docs: resolve build errs

* docs: add bridging guide

* docs: small revisions

* docs: copy edits

* docs: deploy revision

* docs: fix blobstream address

* docs: add alchemy rpc section

* docs: note about opening ports in docker

* docs: bump celestia-node version

* docs: edit l1 to l2

* docs: add newer success logs

* feat: add full node page to docs for orbit

* feat: write out full node page

* docs: more info on validatorfn page

* docs: update wasm root

* docs: update nitro release

* docs: use v2.3.1-rc.1 everywhere for nitro

* docs: edit out 'click heres'

* fix: links

* docs: add eth-rpc variable

* docs: coderabbit suggestions

* docs: clarify wss

* docs: swap steps 6 and 7 for deploy doc

* docs: edit wss section

* docs: add more context for wss

* docs: improve md readabliity in table

* docs: update deployui url

* docs: update ui url

* docs: we'll use in next step

* docs: updates

* docs: add fn

* [GH Action] Update release tags and commit SHAs for mainnet (#1507)

* [automated GH action] update latest release tags & commit sha (mainnet)

* Update .vitepress/constants/mainnet_versions.js

---------

Co-authored-by: jcstein <jcstein@users.noreply.github.com>
Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com>

* docs: update newmetric endpoints

Resolves #1501

* docs: update orbit URL

* docs: coderabbit suggestions

* docs: add op raspberry testnet

* [GH Action] Update release tags and commit SHAs for arabica (#1511)

* [automated GH action] update latest release tags & commit sha (arabica)

* Apply suggestions from code review

---------

Co-authored-by: jcstein <jcstein@users.noreply.github.com>
Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com>

* docs: add sepolia -> mocha (#1512)

* fix typo in arabica-devnet page (#1513)

* [WIP] docs: add audits for blobstream x (#1491)

* docs: add audits for blobstream x

* docs: add veridise audit

* Update rollup-overview.md (#1516)

* feat: restructure developers category (#1515)

* feat: drafting buttons

* fix: color of btn

* feat: add note text optional

* feat: rename to build-whatever.md

* fix: copy

* feat: category shuffle

* fix: suggestions from code review

* feat: add vistara

* Apply suggestions from code review

* fix: typo

* feat: add alt texts

* fix: typo

* feat: aria-labels

* docs: shuffle intro

* feat: add celestia-node.sh script

* fix: clarify section vs. tutorial

* feat: exit if dir change fails

* Update mocha_versions.js (#1529)

* Update mocha_versions.js

* Update mocha_versions.js

* Add Grove archival endpoints to `nodes/mainnet.md` (#1525)

* Add Grove to nodes/mainnet.md

* Apply suggestions from code review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update nodes/mainnet.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Store image in src code

* Add description of archival nodes

* Apply suggestions from code review

* Apply suggestions from code review

* Update nodes/mainnet.md

---------

Co-authored-by: joshcs.eth <46639943+jcstein@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* docs: fix typos (#1526)

* fix typo

* fix typo

* fix typo

* fix typo

* fix typos

* fix typo

* fix typo

* fix typos

* fix typos

* fix typos

* fix typos

* fix typo

* fix typo

* fix typo

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Apply suggestions from code review

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: joshcs.eth <46639943+jcstein@users.noreply.github.com>

* Update mainnet.md (#1527)

Add noders endpoints

* Update mocha-testnet.md (#1528)

* Update mocha-testnet.md

Add noders endpoints

* Fixed link to endpoint

* Apply suggestions from code review

---------

Co-authored-by: joshcs.eth <46639943+jcstein@users.noreply.github.com>

* fix: veridise path

* feat: add to menu

* docs: begin lint

* docs: remove duplicate headings

* docs: clarify duplicate headings

* docs: better headings

* docs: mention blobstream rollups docs in the blobstream overview

---------

Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com>
Co-authored-by: Matthew Sevey <mjsevey@gmail.com>
Co-authored-by: jcstein <mail@jcstein.dev>
Co-authored-by: celestia-bot <136652805+celestia-bot@users.noreply.github.com>
Co-authored-by: jcstein <jcstein@users.noreply.github.com>
Co-authored-by: Levai Mackenzie Ágbàrà <levaiagbara@gmail.com>
Co-authored-by: Guspan Tanadi <36249910+guspan-tanadi@users.noreply.github.com>
Co-authored-by: Kassius <34594014+CryptoKass@users.noreply.github.com>
Co-authored-by: Ratan Kaliani <ratankaliani@berkeley.edu>
Co-authored-by: Callum Waters <cmwaters19@gmail.com>
Co-authored-by: Alex Beckett <75361908+alex-beckett@users.noreply.github.com>
Co-authored-by: mindstyle85 <55639830+mindstyle85@users.noreply.github.com>
Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: omahs <73983677+omahs@users.noreply.github.com>
Co-authored-by: Alex Moskaleu (SeptimA) <dudava45@gmail.com>
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