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

fix(proto): align Proofs serialization with go tendermint #31

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.abci.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Request {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.blockchain.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// BlockRequest requests a block for a specific height
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.consensus.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// NewRoundStep is sent for every step taken in the ConsensusState.
/// For every height/round/step transition
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
3 changes: 1 addition & 2 deletions proto/src/prost/v0_34/tendermint.crypto.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// This file is @generated by prost-build.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Proof {
#[prost(int64, tag = "1")]
#[serde(with = "crate::serializers::from_str")]
pub total: i64,
#[prost(int64, tag = "2")]
#[serde(with = "crate::serializers::from_str")]
pub index: i64,
#[prost(bytes = "vec", tag = "3")]
#[serde(with = "crate::serializers::bytes::base64string")]
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.libs.bits.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.mempool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Txs {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.p2p.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PacketPing {}
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.privval.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RemoteSignerError {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.rpc.grpc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RequestPing {}
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// ABCIResponses retains the responses
/// of the various ABCI calls during block processing.
/// It is persisted to disk for each height before calling Commit.
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.statesync.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Message {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.store.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BlockStoreState {
Expand Down
12 changes: 12 additions & 0 deletions proto/src/prost/v0_34/tendermint.types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -333,14 +334,17 @@ pub struct BlobTx {
}
/// ShareProof is an NMT proof that a set of shares exist in a set of rows and a
/// Merkle proof that those rows exist in a Merkle tree with a given data root.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ShareProof {
#[prost(bytes = "vec", repeated, tag = "1")]
#[serde(with = "crate::serializers::bytes::vec_base64string")]
pub data: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
#[prost(message, repeated, tag = "2")]
pub share_proofs: ::prost::alloc::vec::Vec<NmtProof>,
#[prost(bytes = "vec", tag = "3")]
#[serde(with = "crate::serializers::bytes::base64string")]
pub namespace_id: ::prost::alloc::vec::Vec<u8>,
#[prost(message, optional, tag = "4")]
pub row_proof: ::core::option::Option<RowProof>,
Expand All @@ -349,14 +353,18 @@ pub struct ShareProof {
}
/// RowProof is a Merkle proof that a set of rows exist in a Merkle tree with a
/// given data root.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[serde(default)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RowProof {
#[prost(bytes = "vec", repeated, tag = "1")]
#[serde(with = "crate::serializers::bytes::vec_hexstring")]
pub row_roots: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
#[prost(message, repeated, tag = "2")]
pub proofs: ::prost::alloc::vec::Vec<super::crypto::Proof>,
#[prost(bytes = "vec", tag = "3")]
#[serde(with = "crate::serializers::bytes::base64string")]
pub root: ::prost::alloc::vec::Vec<u8>,
#[prost(uint32, tag = "4")]
pub start_row: u32,
Expand All @@ -367,6 +375,8 @@ pub struct RowProof {
/// In case this proof proves the absence of a namespace.ID
/// in a tree it also contains the leaf hashes of the range
/// where that namespace would be.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[serde(default)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct NmtProof {
Expand All @@ -381,13 +391,15 @@ pub struct NmtProof {
/// and min namespaces along with the actual hash, resulting in each being 48
/// bytes each
#[prost(bytes = "vec", repeated, tag = "3")]
#[serde(with = "crate::serializers::bytes::vec_base64string")]
pub nodes: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
/// leafHash are nil if the namespace is present in the NMT. In case the
/// namespace to be proved is in the min/max range of the tree but absent, this
/// will contain the leaf hash necessary to verify the proof of absence. Leaf
/// hashes should consist of the namespace along with the actual hash,
/// resulting 40 bytes total.
#[prost(bytes = "vec", tag = "4")]
#[serde(with = "crate::serializers::bytes::base64string")]
pub leaf_hash: ::prost::alloc::vec::Vec<u8>,
}
/// BlockIdFlag indicates which BlcokID the signature is for
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_34/tendermint.version.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// App includes the protocol and software version for the application.
/// This information is included in ResponseInfo. The App.Protocol can be
/// updated in ResponseEndBlock.
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.abci.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Request {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.blocksync.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// BlockRequest requests a block for a specific height
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.consensus.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// NewRoundStep is sent for every step taken in the ConsensusState.
/// For every height/round/step transition
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
3 changes: 1 addition & 2 deletions proto/src/prost/v0_37/tendermint.crypto.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// This file is @generated by prost-build.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Proof {
#[prost(int64, tag = "1")]
#[serde(with = "crate::serializers::from_str")]
pub total: i64,
#[prost(int64, tag = "2")]
#[serde(with = "crate::serializers::from_str")]
pub index: i64,
#[prost(bytes = "vec", tag = "3")]
#[serde(with = "crate::serializers::bytes::base64string")]
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.libs.bits.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.mempool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Txs {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.p2p.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PacketPing {}
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.privval.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RemoteSignerError {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.rpc.grpc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RequestPing {}
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// ABCIResponses retains the responses
/// of the various ABCI calls during block processing.
/// It is persisted to disk for each height before calling Commit.
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.statesync.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Message {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.store.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BlockStoreState {
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(::serde::Deserialize, ::serde::Serialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/prost/v0_37/tendermint.version.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// App includes the protocol and software version for the application.
/// This information is included in ResponseInfo. The App.Protocol can be
/// updated in ResponseEndBlock.
Expand Down
36 changes: 36 additions & 0 deletions proto/src/serializers/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,42 @@ pub mod hexstring {
}
}

/// Serialize into and deserialize from a sequence of _hexstring_.
pub mod vec_hexstring {
use serde::{Deserialize, Deserializer, Serializer};
use subtle_encoding::hex;

use crate::prelude::*;
use crate::serializers::cow_str::CowStr;

/// Deserialize array into `Vec<Vec<u8>>`
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<Vec<u8>>, D::Error>
where
D: Deserializer<'de>,
{
Option::<Vec<CowStr>>::deserialize(deserializer)?
.unwrap_or_default()
.into_iter()
.map(|s| hex::decode_upper(s).map_err(serde::de::Error::custom))
.collect()
}

/// Serialize from `Vec<T>` into `Vec<hexstring>`
pub fn serialize<S, T>(value: &[T], serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: AsRef<[u8]>,
{
let hexstrings = value
.iter()
.map(|v| {
String::from_utf8(hex::encode_upper(v.as_ref())).map_err(serde::ser::Error::custom)
})
.collect::<Result<Vec<String>, S::Error>>()?;
serializer.serialize_some(&hexstrings)
}
}

/// Serialize into base64string, deserialize from base64string
pub mod base64string {
use serde::{Deserialize, Deserializer, Serializer};
Expand Down
2 changes: 1 addition & 1 deletion proto/src/tendermint/v0_34.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ pub mod version {

pub mod meta {
pub const REPOSITORY: &str = "https://github.com/celestiaorg/celestia-core";
pub const COMMITISH: &str = "v0.34.x-celestia";
pub const COMMITISH: &str = "a1b07a1e6c77595466da9c61b37c83b4769b47e7";
}
8 changes: 1 addition & 7 deletions tendermint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(
warnings,
trivial_casts,
trivial_numeric_casts,
unused_import_braces,
unused_qualifications
oblique marked this conversation as resolved.
Show resolved Hide resolved
)]
#![deny(warnings, trivial_casts, trivial_numeric_casts, unused_import_braces)]
#![forbid(unsafe_code)]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/informalsystems/tendermint-rs/master/img/logo-tendermint-rs_3961x4001.png"
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ mod tests {
let empty_tree_root_hex =
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
let empty_tree_root = &hex::decode(empty_tree_root_hex).unwrap();
let empty_tree: Vec<Vec<u8>> = vec![vec![]; 0];
let empty_tree: Vec<Vec<u8>> = vec![];

let root = simple_hash_from_byte_vectors::<Sha256>(&empty_tree);
assert_eq!(empty_tree_root, &root);
Expand Down
14 changes: 12 additions & 2 deletions tools/proto-compiler/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const QUOTED: &str = r#"#[serde(with = "crate::serializers::from_str")]"#;
const QUOTED_WITH_DEFAULT: &str = r#"#[serde(with = "crate::serializers::from_str", default)]"#;
const DEFAULT: &str = r#"#[serde(default)]"#;
const HEXSTRING: &str = r#"#[serde(with = "crate::serializers::bytes::hexstring")]"#;
const VEC_HEXSTRING: &str = r#"#[serde(with = "crate::serializers::bytes::vec_hexstring")]"#;
const BASE64STRING: &str = r#"#[serde(with = "crate::serializers::bytes::base64string")]"#;
const VEC_BASE64STRING: &str = r#"#[serde(with = "crate::serializers::bytes::vec_base64string")]"#;
const OPTIONAL: &str = r#"#[serde(with = "crate::serializers::optional")]"#;
Expand Down Expand Up @@ -107,6 +108,11 @@ pub static CUSTOM_TYPE_ATTRIBUTES: &[(&str, &str)] = &[
(".tendermint.types.BlockMeta", SERIALIZED),
(".tendermint.types.TxProof", SERIALIZED),
(".tendermint.crypto.Proof", SERIALIZED),
(".tendermint.types.RowProof", SERIALIZED),
(".tendermint.types.RowProof", DEFAULT),
(".tendermint.types.ShareProof", SERIALIZED),
(".tendermint.types.NMTProof", SERIALIZED),
(".tendermint.types.NMTProof", DEFAULT),
];

/// Custom field attributes applied on top of protobuf fields in (a) struct(s)
Expand Down Expand Up @@ -219,8 +225,12 @@ pub static CUSTOM_FIELD_ATTRIBUTES: &[(&str, &str)] = &[
),
(".tendermint.types.TxProof.data", BASE64STRING),
(".tendermint.types.TxProof.root_hash", HEXSTRING),
(".tendermint.crypto.Proof.index", QUOTED),
(".tendermint.crypto.Proof.total", QUOTED),
(".tendermint.crypto.Proof.aunts", VEC_BASE64STRING),
(".tendermint.crypto.Proof.leaf_hash", BASE64STRING),
(".tendermint.types.RowProof.row_roots", VEC_HEXSTRING),
(".tendermint.types.RowProof.root", BASE64STRING),
(".tendermint.types.ShareProof.data", VEC_BASE64STRING),
(".tendermint.types.ShareProof.namespace_id", BASE64STRING),
(".tendermint.types.NMTProof.nodes", VEC_BASE64STRING),
(".tendermint.types.NMTProof.leaf_hash", BASE64STRING),
];