Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
benluelo committed Jan 9, 2024
1 parent 03e5eed commit 10a6190
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 53 deletions.
8 changes: 4 additions & 4 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
flake = false;
};
ics23 = {
url = "github:cosmos/ics23?rev=74ce807b7be39a7e0afb4e2efb8e28a57965f57b";
url = "github:cosmos/ics23?rev=bf89d957b019bb9a2f381edb1f24d06957807690";
flake = false;
};
cosmosproto = {
Expand Down
26 changes: 23 additions & 3 deletions generated/rust/src/cosmos.ics23.v1.rs

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

9 changes: 3 additions & 6 deletions lib/ics23/src/ops/inner_op.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use unionlabs::cosmos::ics23::{
hash_op::HashOp,
inner_op::InnerOp,
inner_spec::{InnerSpecMaxPrefixLen, InnerSpecMinPrefixLen},
proof_spec::ProofSpec,
hash_op::HashOp, inner_op::InnerOp, inner_spec::PositiveI32AsUsize, proof_spec::ProofSpec,
};

use super::{hash_op, validate_iavl_ops};
Expand All @@ -20,12 +17,12 @@ pub enum SpecMismatchError {
#[error("inner prefix too short, got ({prefix_len}) while the min length is ({min_len})")]
InnerOpPrefixTooShort {
prefix_len: usize,
min_len: InnerSpecMinPrefixLen,
min_len: PositiveI32AsUsize,
},
#[error("inner prefix too long, got ({prefix_len}) while the max length is ({max_len})")]
InnerOpPrefixTooLong {
prefix_len: usize,
max_len: InnerSpecMaxPrefixLen,
max_len: PositiveI32AsUsize,
},
#[error("malformed inner op suffix ({0})")]
InnerOpSuffixMalformed(usize),
Expand Down
29 changes: 13 additions & 16 deletions lib/ics23/src/proof_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::borrow::Cow;
use unionlabs::{
cosmos::ics23::{
hash_op::HashOp,
inner_spec::{
InnerSpec, InnerSpecChild, InnerSpecChildSize, InnerSpecMaxPrefixLen,
InnerSpecMinPrefixLen,
},
inner_spec::{InnerSpec, PositiveI32AsUsize},
leaf_op::LeafOp,
length_op::LengthOp,
proof_spec::ProofSpec,
Expand All @@ -23,13 +20,13 @@ pub const IAVL_PROOF_SPEC: ProofSpec = ProofSpec {
prefix: Cow::Borrowed(&[0]),
},
inner_spec: InnerSpec {
child_order: Cow::Borrowed(promote!(&[InnerSpecChild]: &[
result_unwrap!(InnerSpecChild::new(0)),
result_unwrap!(InnerSpecChild::new(1)),
child_order: Cow::Borrowed(promote!(&[PositiveI32AsUsize]: &[
result_unwrap!(PositiveI32AsUsize::new(0)),
result_unwrap!(PositiveI32AsUsize::new(1)),
])),
child_size: result_unwrap!(InnerSpecChildSize::new(33)),
min_prefix_length: result_unwrap!(InnerSpecMinPrefixLen::new(4)),
max_prefix_length: result_unwrap!(InnerSpecMaxPrefixLen::new(12)),
child_size: result_unwrap!(PositiveI32AsUsize::new(33)),
min_prefix_length: result_unwrap!(PositiveI32AsUsize::new(4)),
max_prefix_length: result_unwrap!(PositiveI32AsUsize::new(12)),
empty_child: Cow::Borrowed(&[]),
hash: HashOp::Sha256,
},
Expand All @@ -47,13 +44,13 @@ pub const TENDERMINT_PROOF_SPEC: ProofSpec = ProofSpec {
prefix: Cow::Borrowed(&[0]),
},
inner_spec: InnerSpec {
child_order: Cow::Borrowed(promote!(&[InnerSpecChild]: &[
result_unwrap!(InnerSpecChild::new(0)),
result_unwrap!(InnerSpecChild::new(1)),
child_order: Cow::Borrowed(promote!(&[PositiveI32AsUsize]: &[
result_unwrap!(PositiveI32AsUsize::new(0)),
result_unwrap!(PositiveI32AsUsize::new(1)),
])),
child_size: result_unwrap!(InnerSpecChildSize::new(32)),
min_prefix_length: result_unwrap!(InnerSpecMinPrefixLen::new(1)),
max_prefix_length: result_unwrap!(InnerSpecMaxPrefixLen::new(1)),
child_size: result_unwrap!(PositiveI32AsUsize::new(32)),
min_prefix_length: result_unwrap!(PositiveI32AsUsize::new(1)),
max_prefix_length: result_unwrap!(PositiveI32AsUsize::new(1)),
empty_child: Cow::Borrowed(&[]),
hash: HashOp::Sha256,
},
Expand Down
6 changes: 3 additions & 3 deletions lib/ics23/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use unionlabs::cosmos::ics23::{
existence_proof::ExistenceProof,
hash_op::HashOp,
inner_op::InnerOp,
inner_spec::{InnerSpec, InnerSpecChild},
inner_spec::{InnerSpec, PositiveI32AsUsize},
non_existence_proof::NonExistenceProof,
proof_spec::ProofSpec,
};
Expand Down Expand Up @@ -68,7 +68,7 @@ pub enum NeighborSearchError {
#[error("branch ({branch}) not found in ({order:?})")]
BranchNotFoundInOrder {
branch: usize,
order: Vec<InnerSpecChild>,
order: Vec<PositiveI32AsUsize>,
},
#[error("cannot find any valid spacing for this node")]
CannotFindValidSpacing,
Expand Down Expand Up @@ -332,7 +332,7 @@ fn get_padding(

/// checks where the branch is in the order and returns
/// the index of this branch
fn get_position(order: &[InnerSpecChild], branch: usize) -> Result<usize, NeighborSearchError> {
fn get_position(order: &[PositiveI32AsUsize], branch: usize) -> Result<usize, NeighborSearchError> {
// NOTE: Reference implementation checks `branch < 0` as well as it uses signed integers
if branch >= order.len() {
return Err(NeighborSearchError::InvalidBranch {
Expand Down
Loading

0 comments on commit 10a6190

Please sign in to comment.