-
Notifications
You must be signed in to change notification settings - Fork 311
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
Create nmt inclusion proofs for transactions in a given block #615
Conversation
This pull request introduces 1 alert when merging 72273fd into 863a00a - view on LGTM.com new alerts:
|
Typo in file name. Currently ‘postion.go’, but I guess should be ‘position.go’ |
func NewErasuredNamespacedMerkleTree(squareSize uint64, setters ...nmt.Option) ErasuredNamespacedMerkleTree { | ||
if squareSize == 0 { | ||
func NewErasuredNamespacedMerkleTree(origSquareSize uint64, setters ...nmt.Option) ErasuredNamespacedMerkleTree { | ||
if origSquareSize == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed for clarity
@@ -91,6 +91,7 @@ message Data { | |||
IntermediateStateRoots intermediate_state_roots = 2 [(gogoproto.nullable) = false]; | |||
EvidenceList evidence = 3 [(gogoproto.nullable) = false]; | |||
Messages messages = 4 [(gogoproto.nullable) = false]; | |||
uint64 original_square_size = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't store the data in the format that we commit to or the square size for each block, we cash the original square size in the data after we generate it. This is then saved and loaded when loading the block to serve a TxProof request.
We can change this in the future by saving adding things to BlockMeta
or something similar.
message TxProof { | ||
bytes root_hash = 1; | ||
bytes data = 2; | ||
tendermint.crypto.Proof proof = 3; | ||
repeated bytes row_roots = 1; | ||
repeated bytes data = 2; | ||
repeated NMTProof proofs = 3; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible for a transaction to span multiple rows, and therefore we now need to potentially prove two or more proofs
func (msgs *Messages) sortMessages() { | ||
sort.Slice(msgs.MessagesList, func(i, j int) bool { | ||
return bytes.Compare(msgs.MessagesList[i].NamespaceID, msgs.MessagesList[j].NamespaceID) < 0 | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must have forgot to pull this from #546, which is very important to stop the node from panicking when attempting to generate the data availability header. Otherwise, it's possible to to order message so that their namespaces are not in lexicographical order. tbh, idek how devnet is still alive
@@ -52,105 +49,6 @@ func TestTxIndexByHash(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestValidTxProof(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted this because I also deleted the old way to create proofs for txs. We can keep both though if we want.
// Code generated by protoc-gen-gogo. DO NOT EDIT. | ||
// source: tendermint/abci/types.proto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk how this was 15,098 loc. looking into this
return nil | ||
} | ||
|
||
func (tp TxProof) ToProto() tmproto.TxProof { | ||
func (tp *TxProof) VerifyProof() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will change this to take a slice of row roots as args, and not use the roots already stored in the TxProof
Co-authored-by: John Adler <[email protected]>
Co-authored-by: John Adler <[email protected]>
Co-authored-by: John Adler <[email protected]>
…org/celestia-core into evan/prove-tx-inclusion
* add ability to create nmt proofs by progressively generating the square * rename var to be more specific * fix file name change * core logic and testing * export needed function * export needed function * generate nmtProof proto files * update remaining tests * update proto files * update test to use new format for verifying proofs * make tx proofs more ergonomic and handle multiple proofs * integrate into rpc core * cache original square size * move proving logic to pkg * add original square size * change name of function to TxInclusion * typo * linter * better docs Co-authored-by: John Adler <[email protected]> * use passed codec arg instead of using the default Co-authored-by: John Adler <[email protected]> * use already existing constant * return error for txSharePosition * bubble error instead of panicking * use uint cause it's the right thing to do even tho go fights you * include the lengths of bytes in the nmt proofs * use passed codec Co-authored-by: John Adler <[email protected]> * add comment to better explain division * linter Co-authored-by: John Adler <[email protected]>
* add ability to create nmt proofs by progressively generating the square * rename var to be more specific * fix file name change * core logic and testing * export needed function * export needed function * generate nmtProof proto files * update remaining tests * update proto files * update test to use new format for verifying proofs * make tx proofs more ergonomic and handle multiple proofs * integrate into rpc core * cache original square size * move proving logic to pkg * add original square size * change name of function to TxInclusion * typo * linter * better docs Co-authored-by: John Adler <[email protected]> * use passed codec arg instead of using the default Co-authored-by: John Adler <[email protected]> * use already existing constant * return error for txSharePosition * bubble error instead of panicking * use uint cause it's the right thing to do even tho go fights you * include the lengths of bytes in the nmt proofs * use passed codec Co-authored-by: John Adler <[email protected]> * add comment to better explain division * linter Co-authored-by: John Adler <[email protected]>
* add ability to create nmt proofs by progressively generating the square * rename var to be more specific * fix file name change * core logic and testing * export needed function * export needed function * generate nmtProof proto files * update remaining tests * update proto files * update test to use new format for verifying proofs * make tx proofs more ergonomic and handle multiple proofs * integrate into rpc core * cache original square size * move proving logic to pkg * add original square size * change name of function to TxInclusion * typo * linter * better docs Co-authored-by: John Adler <[email protected]> * use passed codec arg instead of using the default Co-authored-by: John Adler <[email protected]> * use already existing constant * return error for txSharePosition * bubble error instead of panicking * use uint cause it's the right thing to do even tho go fights you * include the lengths of bytes in the nmt proofs * use passed codec Co-authored-by: John Adler <[email protected]> * add comment to better explain division * linter Co-authored-by: John Adler <[email protected]>
* add ability to create nmt proofs by progressively generating the square * rename var to be more specific * fix file name change * core logic and testing * export needed function * export needed function * generate nmtProof proto files * update remaining tests * update proto files * update test to use new format for verifying proofs * make tx proofs more ergonomic and handle multiple proofs * integrate into rpc core * cache original square size * move proving logic to pkg * add original square size * change name of function to TxInclusion * typo * linter * better docs Co-authored-by: John Adler <[email protected]> * use passed codec arg instead of using the default Co-authored-by: John Adler <[email protected]> * use already existing constant * return error for txSharePosition * bubble error instead of panicking * use uint cause it's the right thing to do even tho go fights you * include the lengths of bytes in the nmt proofs * use passed codec Co-authored-by: John Adler <[email protected]> * add comment to better explain division * linter Co-authored-by: John Adler <[email protected]>
…iaorg#615) * add ability to create nmt proofs by progressively generating the square * rename var to be more specific * fix file name change * core logic and testing * export needed function * export needed function * generate nmtProof proto files * update remaining tests * update proto files * update test to use new format for verifying proofs * make tx proofs more ergonomic and handle multiple proofs * integrate into rpc core * cache original square size * move proving logic to pkg * add original square size * change name of function to TxInclusion * typo * linter * better docs Co-authored-by: John Adler <[email protected]> * use passed codec arg instead of using the default Co-authored-by: John Adler <[email protected]> * use already existing constant * return error for txSharePosition * bubble error instead of panicking * use uint cause it's the right thing to do even tho go fights you * include the lengths of bytes in the nmt proofs * use passed codec Co-authored-by: John Adler <[email protected]> * add comment to better explain division * linter Co-authored-by: John Adler <[email protected]>
Proving transactions are included in a block using nmt proofs
How this is currently done
celestia-core/rpc/core/tx.go
Lines 39 to 42 in 863a00a
What we changed
celestia-core/rpc/core/tx.go
Lines 40 to 47 in 4c7092e
celestia-core doesn't store block data in the format that we commit to, so we have to regenerate that data if we want to use it to generate a proof. Since the transactions are always in the beginning of the square, we don't have to regenerate the entire extended data square, we only have to regenerate the row that the transaction is in. We do this by calculating the position of the transaction in the square, and then progressively filling in the rest of the row by using the other block data.
celestia-core/pkg/prove/proof.go
Lines 137 to 178 in 4c7092e
we also switched to using nmt proofs
celestia-core/proto/tendermint/types/types.pb.go
Lines 1606 to 1624 in 62e497a
celestia-core/types/tx.go
Lines 111 to 130 in 62e497a
Closes #416