Skip to content

Commit

Permalink
add a penumbra_use_prehash_key_before_comparison to config
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence authored and conorsch committed Sep 25, 2023
1 parent b2948cc commit fb33d58
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions crates/relayer-cli/src/chain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ where
url: websocket_address,
batch_delay: default::batch_delay(),
},
penumbra_use_prehash_key_before_comparison: false,
rpc_timeout: default::rpc_timeout(),
trusted_node: default::trusted_node(),
genesis_restart: None,
Expand Down
12 changes: 7 additions & 5 deletions crates/relayer/src/chain/penumbra/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,11 +1313,13 @@ impl ChainEndpoint for PenumbraChain {
.trusting_period
.unwrap_or_else(|| trusting_period_default);

let proof_specs = self
.config
.proof_specs
.clone()
.unwrap_or(crate::chain::penumbra::proofspec::penumbra_proof_spec());
let proof_specs = self.config.proof_specs.clone().unwrap_or_else(|| {
if self.config.penumbra_use_prehash_key_before_comparison {
crate::chain::penumbra::proofspec::penumbra_proof_spec_with_prehash()
} else {
crate::chain::penumbra::proofspec::penumbra_proof_spec_no_prehash()
}
});

// Build the client state.
TmClientState::new(
Expand Down
16 changes: 13 additions & 3 deletions crates/relayer/src/chain/penumbra/proofspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ibc_relayer_types::core::ics23_commitment::specs::ProofSpecs;

const SPARSE_MERKLE_PLACEHOLDER_HASH: [u8; 32] = *b"SPARSE_MERKLE_PLACEHOLDER_HASH__";

fn jmt_spec() -> ics23::ProofSpec {
fn jmt_spec_no_prehash() -> ics23::ProofSpec {
ics23::ProofSpec {
leaf_spec: Some(ics23::LeafOp {
hash: ics23::HashOp::Sha256.into(),
Expand All @@ -25,6 +25,12 @@ fn jmt_spec() -> ics23::ProofSpec {
}
}

fn jmt_spec_with_prehash() -> ics23::ProofSpec {
let mut spec = jmt_spec_no_prehash();
spec.prehash_key_before_comparison = true;
spec
}

/// this is a proof spec for computing Penumbra's AppHash, which is defined as
/// SHA256("PenumbraAppHash" || jmt.root()). In ICS/IBC terms, this applies a single global prefix
/// to Penumbra's state. Having a stable merkle prefix is currently required for our IBC
Expand Down Expand Up @@ -55,6 +61,10 @@ fn apphash_spec() -> ibc_proto::cosmos::ics23::v1::ProofSpec {
}

// TODO: this should re-export the proof specs from the Penumbra crate
pub fn penumbra_proof_spec() -> ProofSpecs {
vec![jmt_spec(), apphash_spec()].into()
pub fn penumbra_proof_spec_no_prehash() -> ProofSpecs {
vec![jmt_spec_no_prehash(), apphash_spec()].into()
}

pub fn penumbra_proof_spec_with_prehash() -> ProofSpecs {
vec![jmt_spec_with_prehash(), apphash_spec()].into()
}
4 changes: 4 additions & 0 deletions crates/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ pub struct ChainConfig {
#[serde(default = "default::trusted_node")]
pub trusted_node: bool,

/// Whether to use prehash_key_before_comparison in Penumbra proof specs.
#[serde(default)]
pub penumbra_use_prehash_key_before_comparison: bool,

pub account_prefix: String,
pub key_name: String,
#[serde(default)]
Expand Down
1 change: 1 addition & 0 deletions tools/test-framework/src/types/single/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl FullNode {
.to_string();

Ok(config::ChainConfig {
penumbra_use_prehash_key_before_comparison: false,
id: self.chain_driver.chain_id.clone(),
r#type: ChainType::CosmosSdk,
rpc_addr: Url::from_str(&self.chain_driver.rpc_address())?,
Expand Down

0 comments on commit fb33d58

Please sign in to comment.