From e2f0262caf77cefb638e1885c0da036b87f918ed Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Wed, 31 Jul 2024 07:55:22 +0500 Subject: [PATCH 1/4] solver types --- types/src/v0/impls/mod.rs | 1 + types/src/v0/impls/solver.rs | 75 ++++++++++++++++++++++++++++++++++++ types/src/v0/v0_3/mod.rs | 2 + types/src/v0/v0_3/solver.rs | 53 +++++++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 types/src/v0/impls/solver.rs create mode 100644 types/src/v0/v0_3/solver.rs diff --git a/types/src/v0/impls/mod.rs b/types/src/v0/impls/mod.rs index 8946357ae..9b02a921a 100644 --- a/types/src/v0/impls/mod.rs +++ b/types/src/v0/impls/mod.rs @@ -7,6 +7,7 @@ mod fee_info; mod header; mod instance_state; mod l1; +mod solver; mod state; mod transaction; diff --git a/types/src/v0/impls/solver.rs b/types/src/v0/impls/solver.rs new file mode 100644 index 000000000..e515b3dac --- /dev/null +++ b/types/src/v0/impls/solver.rs @@ -0,0 +1,75 @@ +use committable::{Commitment, Committable}; +use hotshot::types::SignatureKey; + +use super::v0_3::{RollupRegistrationBody, RollupUpdatebody}; + +impl Committable for RollupRegistrationBody { + fn tag() -> String { + "ROLLUP_REG".to_string() + } + + fn commit(&self) -> Commitment { + // todo (ab): expose to_fixed_bytes() method of fee amount + + let active: [u8; 1] = if self.active { [1] } else { [0] }; + + let mut comm = committable::RawCommitmentBuilder::new(&Self::tag()) + .u64_field("namespace_id", u64::from(self.namespace_id)) + .var_size_field("reserve_url", self.reserve_url.as_str().as_ref()) + .fixed_size_field("reserve_price", &self.reserve_price.to_fixed_bytes()) + .fixed_size_field("active", &active) + .constant_str("signature_keys"); + + for key in self.signature_keys.iter() { + comm = comm.var_size_bytes(&key.to_bytes()); + } + + comm = comm + .var_size_field("signature_key", &self.signature_key.to_bytes()) + .var_size_field("text", self.text.as_bytes()); + + comm.finalize() + } +} + +impl Committable for RollupUpdatebody { + fn tag() -> String { + "ROLLUP_UPDATE".to_string() + } + + fn commit(&self) -> Commitment { + // todo (ab): expose to_fixed_bytes() method of fee amount + + let mut comm = committable::RawCommitmentBuilder::new(&Self::tag()) + .u64_field("namespace_id", u64::from(self.namespace_id)); + + if let Some(reserve_url) = &self.reserve_url { + comm = comm.var_size_field("reserve_url", reserve_url.as_str().as_ref()) + } + + if let Some(rp) = self.reserve_price { + comm = comm.fixed_size_field("reserve_price", &rp.to_fixed_bytes()) + }; + + if let Some(active) = self.active { + let active: [u8; 1] = if active { [1] } else { [0] }; + + comm = comm.fixed_size_field("active", &active); + } + + if let Some(keys) = &self.signature_keys { + comm = comm.constant_str("signature_keys"); + for key in keys.iter() { + comm = comm.var_size_bytes(&key.to_bytes()); + } + } + + comm = comm.var_size_field("signature_key", &self.signature_key.to_bytes()); + + if let Some(text) = &self.text { + comm = comm.var_size_field("text", text.as_bytes()); + } + + comm.finalize() + } +} diff --git a/types/src/v0/v0_3/mod.rs b/types/src/v0/v0_3/mod.rs index 942a75475..7cb1162c8 100644 --- a/types/src/v0/v0_3/mod.rs +++ b/types/src/v0/v0_3/mod.rs @@ -19,8 +19,10 @@ mod auction; mod chain_config; mod fee_info; mod header; +mod solver; pub use auction::{BidTx, BidTxBody, FullNetworkTx, SolverAuctionResults}; pub use chain_config::*; pub use fee_info::IterableFeeInfo; pub use header::Header; +pub use solver::*; diff --git a/types/src/v0/v0_3/solver.rs b/types/src/v0/v0_3/solver.rs new file mode 100644 index 000000000..316efea04 --- /dev/null +++ b/types/src/v0/v0_3/solver.rs @@ -0,0 +1,53 @@ +use crate::{FeeAmount, NamespaceId, SeqTypes}; +use hotshot::types::SignatureKey; +use hotshot_types::traits::node_implementation::NodeType; +use serde::{Deserialize, Serialize}; +use tide_disco::Url; + +#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)] +pub struct RollupRegistration { + pub body: RollupRegistrationBody, + // signature over the above data (must be from a key in the 'signature_keys` list) + pub signature: + <::SignatureKey as SignatureKey>::PureAssembledSignatureType, +} + +#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)] +pub struct RollupRegistrationBody { + pub namespace_id: NamespaceId, + pub reserve_url: Url, + // Denominated in Wei + pub reserve_price: FeeAmount, + // whether this registration is active in the marketplace + pub active: bool, + // a list of keys authorized to update the registration information + pub signature_keys: Vec<::SignatureKey>, + // The signature key used to sign this registration body + pub signature_key: ::SignatureKey, + // Optional field for human readable information + pub text: String, +} + +#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)] +pub struct RollupUpdate { + pub body: RollupUpdatebody, + // signature over the above data (must be from a key in the 'signature_keys` list) + pub signature: + <::SignatureKey as SignatureKey>::PureAssembledSignatureType, +} + +#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)] +pub struct RollupUpdatebody { + pub namespace_id: NamespaceId, + // Denominated in Wei + pub reserve_url: Option, + pub reserve_price: Option, + // whether this registration is active in the marketplace + pub active: Option, + // a list of keys authorized to update the registration information + pub signature_keys: Option::SignatureKey>>, + // The signature key used to sign this update body + pub signature_key: ::SignatureKey, + // Optional field for human readable information + pub text: Option, +} From 5a3c2415dd31c787ab1be1387c95e85622bdf298 Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Wed, 31 Jul 2024 07:57:11 +0500 Subject: [PATCH 2/4] rm comment --- types/src/v0/impls/solver.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/types/src/v0/impls/solver.rs b/types/src/v0/impls/solver.rs index e515b3dac..88a169d04 100644 --- a/types/src/v0/impls/solver.rs +++ b/types/src/v0/impls/solver.rs @@ -9,8 +9,6 @@ impl Committable for RollupRegistrationBody { } fn commit(&self) -> Commitment { - // todo (ab): expose to_fixed_bytes() method of fee amount - let active: [u8; 1] = if self.active { [1] } else { [0] }; let mut comm = committable::RawCommitmentBuilder::new(&Self::tag()) @@ -38,8 +36,6 @@ impl Committable for RollupUpdatebody { } fn commit(&self) -> Commitment { - // todo (ab): expose to_fixed_bytes() method of fee amount - let mut comm = committable::RawCommitmentBuilder::new(&Self::tag()) .u64_field("namespace_id", u64::from(self.namespace_id)); From 5e5c80536f400ed1adb96c7a01c23792c3dbb6b4 Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Wed, 31 Jul 2024 10:08:06 +0500 Subject: [PATCH 3/4] u8::from(active) --- types/src/v0/impls/solver.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/types/src/v0/impls/solver.rs b/types/src/v0/impls/solver.rs index 88a169d04..1f415c473 100644 --- a/types/src/v0/impls/solver.rs +++ b/types/src/v0/impls/solver.rs @@ -9,13 +9,11 @@ impl Committable for RollupRegistrationBody { } fn commit(&self) -> Commitment { - let active: [u8; 1] = if self.active { [1] } else { [0] }; - let mut comm = committable::RawCommitmentBuilder::new(&Self::tag()) .u64_field("namespace_id", u64::from(self.namespace_id)) .var_size_field("reserve_url", self.reserve_url.as_str().as_ref()) .fixed_size_field("reserve_price", &self.reserve_price.to_fixed_bytes()) - .fixed_size_field("active", &active) + .fixed_size_field("active", &[u8::from(self.active)]) .constant_str("signature_keys"); for key in self.signature_keys.iter() { @@ -48,9 +46,7 @@ impl Committable for RollupUpdatebody { }; if let Some(active) = self.active { - let active: [u8; 1] = if active { [1] } else { [0] }; - - comm = comm.fixed_size_field("active", &active); + comm = comm.fixed_size_field("active", &[u8::from(active)]); } if let Some(keys) = &self.signature_keys { From dc2f5f993f78c50a75d31ea1d53df60d15727ed5 Mon Sep 17 00:00:00 2001 From: Abdul Basit <45506001+imabdulbasit@users.noreply.github.com> Date: Wed, 31 Jul 2024 10:46:55 +0500 Subject: [PATCH 4/4] Update tag for rollup reg Co-authored-by: tbro <48967308+tbro@users.noreply.github.com> --- types/src/v0/impls/solver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/src/v0/impls/solver.rs b/types/src/v0/impls/solver.rs index 1f415c473..fb40e5d30 100644 --- a/types/src/v0/impls/solver.rs +++ b/types/src/v0/impls/solver.rs @@ -5,7 +5,7 @@ use super::v0_3::{RollupRegistrationBody, RollupUpdatebody}; impl Committable for RollupRegistrationBody { fn tag() -> String { - "ROLLUP_REG".to_string() + "ROLLUP_REGISTRATION".to_string() } fn commit(&self) -> Commitment {