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

fault_proving(compression): include commitment to registry in compressed block header #2571

Closed
wants to merge 1 commit into from
Closed
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added
- [2551](https://github.com/FuelLabs/fuel-core/pull/2551): Enhanced the DA compressed block header to include block id.
- [2571](https://github.com/FuelLabs/fuel-core/pull/2571): Enhanced the DA compressed block header to include registry id.

## [Version 0.41.0]

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/compression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fuel-core-types = { workspace = true, features = [
"serde",
"da-compression",
] }
fuel-crypto = { version = "0.59.1", optional = true }
paste = { workspace = true }
rand = { workspace = true, optional = true }
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -43,4 +44,4 @@ test-helpers = [
"fuel-core-types/random",
"fuel-core-types/std",
]
fault-proving = []
fault-proving = ["dep:fuel-crypto"]
1 change: 1 addition & 0 deletions crates/compression/src/compressed_block_payload/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod v0;

#[cfg(feature = "fault-proving")]
pub mod v1;
20 changes: 16 additions & 4 deletions crates/compression/src/compressed_block_payload/v1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{
registry::RegistrationsPerTable,
registry::{
RegistrationsPerTable,
RegistryId,
},
VersionedBlockPayload,
};
use fuel_core_types::{
Expand Down Expand Up @@ -31,10 +34,15 @@ pub struct CompressedBlockHeader {
pub consensus: ConsensusHeader<Empty>,
// The block id.
pub block_id: BlockId,
// The registry id.
pub registry_id: RegistryId,
}

impl From<&BlockHeader> for CompressedBlockHeader {
fn from(header: &BlockHeader) -> Self {
impl CompressedBlockHeader {
fn from_header_and_registry(
header: &BlockHeader,
registry: &RegistrationsPerTable,
) -> Self {
let ConsensusHeader {
prev_root,
height,
Expand All @@ -56,6 +64,7 @@ impl From<&BlockHeader> for CompressedBlockHeader {
generated: Empty {},
},
block_id: header.id(),
registry_id: registry.id(),
}
}
}
Expand Down Expand Up @@ -114,7 +123,10 @@ impl CompressedBlockPayloadV1 {
transactions: Vec<CompressedTransaction>,
) -> Self {
Self {
header: CompressedBlockHeader::from(header),
header: CompressedBlockHeader::from_header_and_registry(
header,
&registrations,
),
registrations,
transactions,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ mod tests {
generated: Empty,
},
block_id: BlockId::from_str("0xecea85c17070bc2e65f911310dbd01198f4436052ebba96cded9ddf30c58dd1a").unwrap(),
registry_id: registrations.id(),
};


Expand Down Expand Up @@ -302,6 +303,7 @@ mod tests {

if let VersionedCompressedBlock::V1(block) = decompressed {
assert_eq!(block.header.block_id, header.block_id);
assert_eq!(block.header.registry_id, header.registry_id);
} else {
panic!("Expected V1 block, got {:?}", decompressed);
}
Expand Down
18 changes: 18 additions & 0 deletions crates/compression/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use fuel_core_types::{
tai64::Tai64,
};

#[cfg(feature = "fault-proving")]
pub type RegistryId = fuel_core_types::fuel_tx::Bytes32;

macro_rules! tables {
($($ident:ty: $type:ty),*) => { paste::paste! {
#[doc = "RegistryKey namespaces"]
Expand Down Expand Up @@ -90,10 +93,25 @@ macro_rules! tables {

Ok(())
}

#[cfg(feature = "fault-proving")]
pub fn id(&self) -> RegistryId {
let mut hasher = fuel_crypto::Hasher::default();

$(
for (key, value) in self.$ident.iter() {
hasher.input(key);
hasher.input(value);
}
)*

hasher.digest()
}
}
}};
}

// Don't change the order of these, it will affect the order of hashing
Copy link
Member Author

Choose a reason for hiding this comment

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

tables!(
address: Address,
asset_id: AssetId,
Expand Down
Loading