Skip to content

Commit

Permalink
refactor: hashchain interface improvements (#156)
Browse files Browse the repository at this point in the history
* refactor: remove unused get_valid_keys

* refactor(common): Creating Signature type

* feat(common): Add method to hash multiple items

* refactor(common): Operation is only a container for op-specific args

* refactor(common): Hashchain provides methods to do operations

* refactor(common): Tree interface uses HashchainEntry instead of Operation

* test: Tree utils use HashchainEntry instead of Operation

* feat: Introduce struct for id-based hashchain updates

* test: OpsBuilder builds requests now

* refactor(prover): Prover uses requests instead of operations

* refactor(da): DA layer uses requests instead of operations

* test(prover): Prover tests use requests instead of operations

* refactor(prover): Webserver uses requests instead of operations

* test: Integration test is adapted to Hashchain changes

* refactor(bin): Adjust celestia config namespace variable names

* refactor(common): No need for entries without challenge

* chore: Remove debug comments and unnecessary code

* refactor: More simple approach for converting REST DTOs

* refactor: Replace more id/entry params with request entity

* refactor: Rename request to transaction

* test: Better file and method names for transaction builder

* refactor: More renaming to transaction

* fix: Correct basic validation for operations

* chore: Incorporate changes in zkvm elf
  • Loading branch information
jns-ps authored Nov 8, 2024
1 parent 41a0898 commit e1901aa
Show file tree
Hide file tree
Showing 19 changed files with 818 additions and 933 deletions.
21 changes: 9 additions & 12 deletions crates/bin/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub struct CommandLineArgs {
#[arg(long)]
snark_namespace_id: Option<String>,

/// Celestia Operation Namespace ID
/// Celestia Transaction Namespace ID
#[arg(long)]
operation_namespace_id: Option<String>,
transaction_namespace_id: Option<String>,

// Height to start searching the DA layer for SNARKs on
#[arg(short = 's', long)]
Expand Down Expand Up @@ -115,9 +115,8 @@ pub fn load_config(args: CommandLineArgs) -> Result<Config> {
.context("Failed to build config")?;

let default_config = Config::default();
let loaded_config: Config = config_source
.try_deserialize()
.context("Failed to deserialize config file")?;
let loaded_config: Config =
config_source.try_deserialize().context("Failed to deserialize config file")?;

let merged_config = merge_configs(loaded_config, default_config);
let final_config = apply_command_line_args(merged_config, args);
Expand Down Expand Up @@ -213,12 +212,12 @@ fn apply_command_line_args(config: Config, args: CommandLineArgs) -> Config {
.map(|c| c.snark_namespace_id.clone())
.unwrap_or_else(|| CelestiaConfig::default().snark_namespace_id)
}),
operation_namespace_id: Some(args.operation_namespace_id.unwrap_or_else(|| {
transaction_namespace_id: Some(args.transaction_namespace_id.unwrap_or_else(|| {
config
.celestia_config
.as_ref()
.map(|c| c.operation_namespace_id.clone())
.unwrap_or_else(|| CelestiaConfig::default().operation_namespace_id)
.map(|c| c.transaction_namespace_id.clone())
.unwrap_or_else(|| CelestiaConfig::default().transaction_namespace_id)
.unwrap()
})),
}),
Expand All @@ -234,10 +233,8 @@ pub async fn initialize_da_layer(

match da_layer {
DALayerOption::Celestia => {
let celestia_conf = config
.celestia_config
.clone()
.context("Celestia configuration not found")?;
let celestia_conf =
config.celestia_config.clone().context("Celestia configuration not found")?;

for attempt in 1..=DA_RETRY_COUNT {
match CelestiaConnection::new(&celestia_conf, None).await {
Expand Down
8 changes: 8 additions & 0 deletions crates/common/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ impl Digest {
Self(hasher.finalize())
}

pub fn hash_items(items: &[impl AsRef<[u8]>]) -> Self {
let mut hasher = Hasher::new();
for item in items {
hasher.update(item.as_ref());
}
Self(hasher.finalize())
}

pub const fn zero() -> Self {
Self([0u8; 32])
}
Expand Down
Loading

0 comments on commit e1901aa

Please sign in to comment.