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

override default bytes ser/de. #131

Merged
merged 2 commits into from
Dec 15, 2023
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
16 changes: 15 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"sugondat-chain/primitives",
"adapters/sovereign",
"sugondat-nmt",
"sugondat-serde-util",
"sugondat-shim",
"sugondat-shim/common/rollkit",
"sugondat-shim/common/sovereign",
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 @@ Blobchains on Polkadot and Kusama
│ ├── <a href="./demo/rollkit">rollkit</a>: Rollkit's GM rollup.
│ ├── <a href="./demo/sovereign">sovereign</a>: Sovereign Demo Rollup.
├──<a href="./sugondat-chain">sugondat-chain</a>: Implementation of sugondat parachain.
├──<a href="./sugondat-serde-util">sugondat-serde-util</a>: Various utilities for serde.
├──<a href="./sugondat-shim">sugondat-shim</a>: Shim between sugondat parachain RPC and RDK adapters.
├──<a href="./sugondat-subxt">sugondat-subxt</a>: Bindings to Sugondat RPC.
</pre>
Expand Down
2 changes: 1 addition & 1 deletion adapters/sovereign/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
pub struct DaLayerSpec;

pub struct ChainParams {
pub namespace_id: [u8; 4],
pub namespace_id: [u8; sugondat_nmt::NS_ID_SIZE],
}

impl sov_rollup_interface::da::DaSpec for DaLayerSpec {
Expand Down
4 changes: 2 additions & 2 deletions adapters/sovereign/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sov_rollup_interface::{
da::{BlockHeaderTrait, DaSpec, DaVerifier},
zk::ValidityCondition,
};
use sugondat_nmt::Namespace;
use sugondat_nmt::{Namespace, NS_ID_SIZE};

/// A validity condition expressing that a chain of DA layer blocks is contiguous and canonical
#[derive(
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct SugondatVerifier {
// is needed a way to create the verifier without knowing the trait DaVerifier,
// so without new method
impl SugondatVerifier {
pub fn from_raw(raw_namespace_id: [u8; 4]) -> Self {
pub fn from_raw(raw_namespace_id: [u8; NS_ID_SIZE]) -> Self {
Self {
namespace: Namespace::from_raw_bytes(raw_namespace_id),
}
Expand Down
52 changes: 26 additions & 26 deletions demo/rollkit/init-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TOKEN_AMOUNT="10000000000000000000000000stake"
STAKING_AMOUNT="1000000000stake"

# create a random Namespace ID for your rollup to post blocks to
NAMESPACE=01020304
NAMESPACE=01020304050607080910111213141516

# query the DA Layer start height, in this case we are querying
# our local devnet at port 26657, the RPC. The RPC endpoint is
Expand All @@ -22,32 +22,32 @@ DA_BLOCK_HEIGHT=1
# rollkit logo
cat <<'EOF'

:=+++=.
-++- .-++:
.=+=. :++-.
-++- .=+=: .
.=+=: -%@@@*
+%- .=#@@@@@@*
-++- -*%@@@@@@%+:
.=*=. .=#@@@@@@@%=.
-++-.-++: =*#@@@@@%+:.-++-=-
.=+=. :=+=.-: @@#=. .-*@@@@%
=*=: .-==+- :+#@@@@@@%-
:++- -*@@@@@@@#=:
=%+=. .=#@@@@@@@#%:
-++: -++- *+=@@@@%+: =#*##-
=*=. :=+=---@*=. .=*@@@@@%
.-+=: :-: :+%@@@@@@%+.
:=+- -*@@@@@@@#=.
.=+=: .=#@@@@@@%*-
-++- *=.@@@#+:
.====+*-.

______ _ _ _ _ _
| ___ \ | || || | (_)| |
| |_/ / ___ | || || | __ _ | |_
:=+++=.
-++- .-++:
.=+=. :++-.
-++- .=+=: .
.=+=: -%@@@*
+%- .=#@@@@@@*
-++- -*%@@@@@@%+:
.=*=. .=#@@@@@@@%=.
-++-.-++: =*#@@@@@%+:.-++-=-
.=+=. :=+=.-: @@#=. .-*@@@@%
=*=: .-==+- :+#@@@@@@%-
:++- -*@@@@@@@#=:
=%+=. .=#@@@@@@@#%:
-++: -++- *+=@@@@%+: =#*##-
=*=. :=+=---@*=. .=*@@@@@%
.-+=: :-: :+%@@@@@@%+.
:=+- -*@@@@@@@#=.
.=+=: .=#@@@@@@%*-
-++- *=.@@@#+:
.====+*-.

______ _ _ _ _ _
| ___ \ | || || | (_)| |
| |_/ / ___ | || || | __ _ | |_
| / / _ \ | || || |/ /| || __|
| |\ \ | (_) || || || < | || |_
| |\ \ | (_) || || || < | || |_
\_| \_| \___/ |_||_||_|\_\|_| \__|
EOF

Expand Down
4 changes: 2 additions & 2 deletions demo/rollkit/restart-local.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DA_BLOCK_HEIGHT=1
NAMESPACE=01020304
NAMESPACE=01020304050607080910111213141516
AUTH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJwdWJsaWMiLCJyZWFkIiwid3JpdGUiLCJhZG1pbiJdfQ.mj7taF7Z9ZcTN2hhC1-cLf5SmqQd-ZA4YVZymd3-Ato
gmd start --rollkit.aggregator true --rollkit.da_layer sugondat --rollkit.da_config='{"base_url":"http://localhost:10995","namespace":"01020304"}' --rollkit.namespace_id $NAMESPACE --rollkit.da_start_height $DA_BLOCK_HEIGHT --rpc.laddr tcp://127.0.0.1:36657 --p2p.laddr "0.0.0.0:36656"
gmd start --rollkit.aggregator true --rollkit.da_layer sugondat --rollkit.da_config='{"base_url":"http://localhost:10995","namespace":"01020304050607080910111213141516"}' --rollkit.namespace_id $NAMESPACE --rollkit.da_start_height $DA_BLOCK_HEIGHT --rpc.laddr tcp://127.0.0.1:36657 --p2p.laddr "0.0.0.0:36656"
11 changes: 11 additions & 0 deletions demo/sovereign/Cargo.lock

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

2 changes: 1 addition & 1 deletion demo/sovereign/const-rollup-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// The namespace used by the rollup to store its data. This is a raw slice of 8 bytes.
/// The rollup stores its data in the namespace b"sov-test" on Celestia. Which in this case is encoded using the
/// ascii representation of each character.
pub const ROLLUP_NAMESPACE_RAW: [u8; 4] = [3, 0, 0, 0];
pub const ROLLUP_NAMESPACE_RAW: [u8; 16] = 3_u128.to_be_bytes();

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

3 changes: 2 additions & 1 deletion sugondat-nmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ license = "MIT OR Apache-2.0"
sha2 = { version = "0.10.6", default-features = false }
nmt-rs = { git = "https://github.com/Sovereign-Labs/nmt-rs.git", rev = "627f9622a987db4a0b22dc04107442f4010096fb", default-features = false }
serde = { version = "1.0.130", default-features = false, optional = true }
sugondat-serde-util = { path = "../sugondat-serde-util", optional = true }

[features]
default = ["native"]
native = []
serde = ["dep:serde", "nmt-rs/serde"]
serde = ["dep:serde", "dep:sugondat-serde-util", "nmt-rs/serde"]
17 changes: 12 additions & 5 deletions sugondat-nmt/src/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ use core::fmt;
/// assert!(Namespace::from_u128_be(0x0100) > Namespace::from_u128_be(0x00FF));
/// ````
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Namespace([u8; NS_ID_SIZE]);
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(transparent)
)]
pub struct Namespace(
#[cfg_attr(feature = "serde", serde(with = "sugondat_serde_util::bytes16_hex"))]
[u8; NS_ID_SIZE],
);

impl Namespace {
/// Creates a namespace from the given raw bytes.
Expand All @@ -28,15 +35,15 @@ impl Namespace {
self.0
}

/// A convenience function to create a namespace from an unsigned 32-bit integer.
/// A convenience function to create a namespace from an unsigned 128-bit integer.
///
/// This function will take the given integer (which is assumed to be in host byte order), and
/// take its big-endian representation as the namespace ID.
pub fn from_u128_be(namespace_id: u128) -> Self {
Self(namespace_id.to_be_bytes())
}

/// Reinterpret the namespace ID as a big-endian 32-bit integer and return.
/// Reinterpret the namespace ID as a big-endian 128-bit integer and return.
pub fn to_u128_be(&self) -> u128 {
u128::from_be_bytes(self.0)
}
Expand All @@ -54,7 +61,7 @@ impl Namespace {

impl fmt::Display for Namespace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Print the namespace as a 4-byte hex string. We don't use `hex` crate here to avoid
// Print the namespace as a 16-byte hex string. We don't use `hex` crate here to avoid
// extra dependencies.
write!(f, "0x")?;
for byte in self.to_raw_bytes().iter() {
Expand Down
1 change: 1 addition & 0 deletions sugondat-nmt/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub use crate::ns::Namespace;
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TreeRoot {
#[cfg_attr(feature = "serde", serde(with = "sugondat_serde_util::bytes32_hex"))]
pub root: [u8; 32],
pub min_ns: Namespace,
pub max_ns: Namespace,
Expand Down
18 changes: 18 additions & 0 deletions sugondat-serde-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "sugondat-serde-util"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.130", default-features = false }
hex = { version = "0.4.3" }
base64 = "0.21.5"

[dev-dependencies]
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
serde_json = "1.0.108"
serde = { version = "1.0.130", features = ["derive"] }
Loading