Skip to content

Commit

Permalink
fix(fortuna): check chain length as a short-circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m committed Jun 6, 2024
1 parent c264c31 commit 88360c9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion apps/fortuna/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 apps/fortuna/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fortuna"
version = "6.2.3"
version = "6.2.4"
edition = "2021"

[dependencies]
Expand Down
56 changes: 31 additions & 25 deletions apps/fortuna/src/command/setup_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub async fn setup_provider(opts: &SetupProviderOptions) -> Result<()> {
/// 3. Re-register if there is a mismatch in generated hash chain.
/// 4. Update provider fee if there is a mismatch with the fee set on contract.
/// 5. Update provider uri if there is a mismatch with the uri set on contract.
#[tracing::instrument(name="setup_chain_provider", skip_all, fields(chain_id=chain_id))]
#[tracing::instrument(name = "setup_chain_provider", skip_all, fields(chain_id = chain_id))]
async fn setup_chain_provider(
config: &Config,
chain_id: &ChainId,
Expand Down Expand Up @@ -95,32 +95,38 @@ async fn setup_chain_provider(
e
)
})?;

let secret = provider_config.secret.load()?.ok_or(anyhow!(
"Please specify a provider secret in the config file."
))?;
let hash_chain = PebbleHashChain::from_config(
&secret,
&chain_id,
&provider_address,
&chain_config.contract_addr,
&metadata.seed,
provider_config.chain_length,
provider_config.chain_sample_interval,
)?;
let chain_state = HashChainState {
offsets: vec![provider_info
.original_commitment_sequence_number
.try_into()?],
hash_chains: vec![hash_chain],
};
if metadata.chain_length != provider_config.chain_length {
tracing::info!("Chain length mismatch");
register = true;
} else {
let secret = provider_config.secret.load()?.ok_or(anyhow!(
"Please specify a provider secret in the config file."
))?;
let hash_chain = PebbleHashChain::from_config(
&secret,
&chain_id,
&provider_address,
&chain_config.contract_addr,
&metadata.seed,
provider_config.chain_length,
provider_config.chain_sample_interval,
)?;
let chain_state = HashChainState {
offsets: vec![provider_info
.original_commitment_sequence_number
.try_into()?],
hash_chains: vec![hash_chain],
};


if chain_state.reveal(provider_info.original_commitment_sequence_number)?
!= provider_info.original_commitment
{
tracing::info!("The root of the generated hash chain does not match the commitment",);
register = true;
if chain_state.reveal(provider_info.original_commitment_sequence_number)?
!= provider_info.original_commitment
{
tracing::info!(
"The root of the generated hash chain does not match the commitment",
);
register = true;
}
}
}

Expand Down

0 comments on commit 88360c9

Please sign in to comment.