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

DA compression for fuel-tx types #670

Merged
merged 82 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
eddf4cb
WIP
Dentosal Jan 29, 2024
bf61b73
Migrate compact-derive from fuel-core
Dentosal Feb 1, 2024
1b0917e
Merge branch 'master' into dento/da-compression
Dentosal Feb 5, 2024
0c7f3dd
Add doc comments and cleanup
Dentosal Feb 5, 2024
cbc2173
Add changelog
Dentosal Feb 5, 2024
82b2efa
Cargo.toml fmt
Dentosal Feb 5, 2024
1e792e9
Wrap Compaction return types to anyhow::Result
Dentosal Feb 12, 2024
6ad66c3
Update readme
Dentosal Feb 12, 2024
cc1b7a8
Fix wording
Dentosal Mar 6, 2024
8f60962
Combine some bounds
Dentosal Mar 6, 2024
3169f6c
Merge branch 'master' into dento/da-compression
Dentosal Jul 16, 2024
ac811f5
Fix issues after merge
Dentosal Jul 16, 2024
8ed0672
Fix compression for latest types
Dentosal Jul 17, 2024
f04df70
Keep used gas price
Dentosal Jul 17, 2024
141efe5
Cargo sort
Dentosal Jul 17, 2024
da7819f
Introduce ContractId table to da compression registry
Dentosal Jul 18, 2024
42e8634
Reference table types directly in #[da_compress(registry = _)]
Dentosal Jul 18, 2024
781fe1e
WIP: migrate domain logic to fuel-core
Dentosal Jul 22, 2024
546dda0
Re-add dummy registry for testing
Dentosal Jul 22, 2024
bf2b976
Add some missing docs
Dentosal Jul 22, 2024
880d13c
Move block section data for fuel-core
Dentosal Jul 22, 2024
b23bff5
Minor change for fuel-core integration
Dentosal Jul 22, 2024
293f0f0
cargo sort
Dentosal Jul 22, 2024
a1b5174
Fix incorrect feature cfg on default_test_tx
Dentosal Jul 23, 2024
dd40e5b
Merge branch 'master' into dento/da-compression
Dentosal Aug 27, 2024
f7d6ced
Implement compacting for blobs as well
Dentosal Aug 27, 2024
21b4ab6
Fix no_std deps
Dentosal Aug 27, 2024
4188f37
WIP: working towards adapting Green's trait-based approach
Dentosal Sep 2, 2024
f0be2b1
Complete migration to Green's trait-heavy approach
Dentosal Sep 3, 2024
0b8a0d9
Polish: docs, naming, argument order
Dentosal Sep 3, 2024
69ac157
Clean up proc macro a bit
Dentosal Sep 3, 2024
1ef6803
Line count reduction :\
Dentosal Sep 3, 2024
07391b2
More polish
Dentosal Sep 3, 2024
6b359f0
Move readme from fuel-compression to fuel-core-compression
Dentosal Sep 3, 2024
3ee7589
Enable more lints for fuel-derive, remove unnecessary regex dependency
Dentosal Sep 3, 2024
1530755
Remove debug writing to /tmp, as we're hopefully done here
Dentosal Sep 3, 2024
f1e7114
Get rid of anyhow
Dentosal Sep 3, 2024
31083c1
Add roundtrip tests
Dentosal Sep 3, 2024
0cc0be0
Use type-based registry keyspaces
Dentosal Sep 3, 2024
2a7904a
Omit Message amount from DA compressed data
Dentosal Sep 3, 2024
b2861d7
Remove extra "Compressible" bound from "RegistrySubstitutableBy"
Dentosal Sep 3, 2024
4f7a2d6
Implement da compression for TxId -> TxPointer
Dentosal Sep 3, 2024
c984fa1
Use the type instead of field annotations for determining compressed …
Dentosal Sep 4, 2024
b947dae
Make da compression async
Dentosal Sep 4, 2024
5d9087d
Also make compression context async
Dentosal Sep 4, 2024
3d2af6d
unused_crate_dependencies fix
Dentosal Sep 4, 2024
19aa0c0
More unused_crate_dependencies
Dentosal Sep 4, 2024
9a80b08
cargo sort
Dentosal Sep 4, 2024
af39dcf
Cosmetic changes:
xgreenx Sep 4, 2024
bf75dbc
Cleanup small nits after review
xgreenx Sep 4, 2024
cc1b892
Revert commits af39dcfcf19d6e41cca6fb39a6707b8614854338 and bf75dbc13…
Dentosal Sep 5, 2024
b8011ce
Split derive macro "Compressed" into "Compress" and "Decompress"
Dentosal Sep 5, 2024
34c7a23
Re-apply Green's da_compress(bound) removal and bound simplification
Dentosal Sep 5, 2024
0342ae1
Re-introduce Green's TxId type, do some cleanup related to these types
Dentosal Sep 5, 2024
285cf88
Re-apply bf75dbc1354840fb7787d1282821b241d4bb8c89
Dentosal Sep 5, 2024
b3e0718
Compress the whole UtxoId instead of just TxId
Dentosal Sep 5, 2024
ee39490
Compress UtxoId: test fixes
Dentosal Sep 5, 2024
7aa5405
Introduce PredicateCode to allow compressing it
Dentosal Sep 5, 2024
1bb7090
Make fields for Compressed* public
Dentosal Sep 5, 2024
d23d6cd
Remove Decompress derive from Message and Coin
Dentosal Sep 5, 2024
efd2dc6
Rename da_compress attribute to just compress
Dentosal Sep 5, 2024
92983a9
Add tests for TxId
Dentosal Sep 5, 2024
7b88695
Rename remaining instances of compaction into compression
Dentosal Sep 5, 2024
b60e38a
Add explicit CompressedUtxoId type
Dentosal Sep 5, 2024
89654f1
Rename De/CompressionContext methods
Dentosal Sep 6, 2024
d9c3aa3
Clippy
Dentosal Sep 6, 2024
7a98ae4
Ignore incorrect unused crate warning
Dentosal Sep 6, 2024
7e6a865
Fix no-default-features
Dentosal Sep 6, 2024
9b33143
Remove De/CompressionContext traits, they seem unnecessary
Dentosal Sep 6, 2024
cc61e1e
Simplifying tests for DA compression (#816)
xgreenx Sep 9, 2024
0fe904a
Merge branch 'master' into dento/da-compression
Dentosal Sep 9, 2024
5728192
Address PR review comments
Dentosal Sep 9, 2024
6356189
Merge branch 'dento/da-compression' of https://github.com/FuelLabs/fu…
Dentosal Sep 9, 2024
860dc98
Fix , => ;
Dentosal Sep 9, 2024
987fdbb
Fix a memory leak in unsafe array de/compress code
Dentosal Sep 9, 2024
90c71df
Fix typo
Dentosal Sep 9, 2024
e80ee5d
Fix typo
Dentosal Sep 9, 2024
cbe48f9
Add a test cases to cover skipped fields and nested structs
Dentosal Sep 10, 2024
b0f52dd
Remove unneeded change of field ref for struct that impls Deref
Dentosal Sep 10, 2024
1601729
Remove useless .scollect()s
Dentosal Sep 10, 2024
59ffbd5
Clarify variable namings around serialization in a test case
Dentosal Sep 10, 2024
476c898
Add a test case showing that skipped fields are not part of the compr…
Dentosal Sep 10, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- [#670](https://github.com/FuelLabs/fuel-vm/pull/670): Add DA compression functionality to `Transaction` and any types within

## [Version 0.45.0]

### Changed
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"fuel-asm",
"fuel-compression",
"fuel-crypto",
"fuel-merkle",
"fuel-storage",
Expand All @@ -21,7 +22,9 @@ repository = "https://github.com/FuelLabs/fuel-vm"
version = "0.45.0"

[workspace.dependencies]
anyhow = "1.0"
fuel-asm = { version = "0.45.0", path = "fuel-asm", default-features = false }
fuel-compression = { version = "0.45.0", path = "fuel-compression", default-features = false }
fuel-crypto = { version = "0.45.0", path = "fuel-crypto", default-features = false }
fuel-derive = { version = "0.45.0", path = "fuel-derive", default-features = false }
fuel-merkle = { version = "0.45.0", path = "fuel-merkle", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and [the Sway compiler](https://github.com/FuelLabs/sway/).
| Crate | Version | Description |
|--------------|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| fuel-asm | [![crates.io](https://img.shields.io/crates/v/fuel-asm)](https://crates.io/crates/fuel-asm) | Contains the FuelVM instruction set - opcodes used by the Sway and VM. |
| fuel-compression | [![crates.io](https://img.shields.io/crates/v/fuel-compression)](https://crates.io/crates/fuel-compression) | DA-layer compression of Fuel transaction types |
| fuel-crypto | [![crates.io](https://img.shields.io/crates/v/fuel-crypto)](https://crates.io/crates/fuel-crypto) | Cryptographic primitives used across Fuel Rust based projects. |
| fuel-merkle | [![crates.io](https://img.shields.io/crates/v/fuel-merkle)](https://crates.io/crates/fuel-merkle) | Implementations of the Merkle Tree used by the `fuel-core` to fulfill fraud proofs requirements, and `fuel-tx` to validate transaction validity. |
| fuel-storage | [![crates.io](https://img.shields.io/crates/v/fuel-storage)](https://crates.io/crates/fuel-storage) | Storage abstraction is used to connect FuelVM, `fuel-merkle`, and `fuel-core` together without direct access. |
Expand Down
28 changes: 28 additions & 0 deletions fuel-compression/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "fuel-compression"
version = { workspace = true }
authors = { workspace = true }
categories = ["cryptography::cryptocurrencies"]
edition = { workspace = true }
homepage = { workspace = true }
keywords = ["blockchain", "cryptocurrencies", "fuel-compression"]
license = { workspace = true }
repository = { workspace = true }
description = "Compression and decompression of Fuel blocks for DA storage."

[dependencies]
anyhow = { workspace = true }
fuel-derive = { workspace = true }
postcard = { version = "1.0", features = ["use-std"] }
serde = { version = "1.0", features = ["derive"] }
serde-big-array = "0.5"

[dev-dependencies]
bincode = "1.3"
fuel-asm = { workspace = true }
fuel-compression = { path = "." } # Self-dependency needed by test for macros
fuel-tx = { workspace = true }
fuel-types = { workspace = true, features = ["serde"] }

[features]
test-helpers = []
34 changes: 34 additions & 0 deletions fuel-compression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Compression and decompression of fuel-types for the DA layer

## Compressed block header

Each compressed block begins with a single-byte version field, so that it's possible to change the format later.

## Temporal registry

This crate provides offchain registries for different types such as `AssetId`, `ContractId`, scripts, and predicates. Each registry is a key-value store with three-byte key. The registires are essentially compression caches. The three byte key allows cache size of 16 million values before reregistering the older values.

The registries allow replacing repeated objects with their respective keys, so if an object
is used multiple times in a short interval (couple of months, maybe), then the full value
exists on only a single uncompressed block,

### Fraud proofs

Compressed block will start with 32 bytes of merkle root over all compression smts, followed by newly registered values along with their keys. Using an SMT provides flexibility around the algorithm we use to define keys without knowing how exactly values were chosen to be registered.

Each registry also uses an SMT. Since the keys are three bytes long, the depth of the SMT is capped at 24 levels.


- More efficient for fraud proofs instead of needing to provide entire previous blocks with proofs

## Compression of `UtxoIds`

Since each `UtxoId` only appears once, there's no point in registering them. Instead, they are replaced with `TxPointer`s (7 bytes worst case), which are still unique.

### Fraud proofs

During fraud proofs we need to use the `prev_root` to prove that the referenced block height is part of the chain.

## Other techniques

- These techniques should be good enough for now, but there are lots of other interesting ideas for this.
Loading
Loading