Skip to content

Commit

Permalink
Merge pull request #103 from dusk-network/vlopes11/microkelvin-max-an…
Browse files Browse the repository at this point in the history
…notation

PoseidonMaxAnnotation borrow fix latest microkelvin
  • Loading branch information
vlopes11 authored Dec 4, 2020
2 parents 52de9b3 + 44320e6 commit 2ecc42b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.15.0] - 04-12-20
### Fixed
- PoseidonMaxAnnotation borrow fix for latest microkelvin.

## [0.14.1] - 21-11-20
### Changed
- Sponge hash defined as a no-std function.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poseidon252"
version = "0.14.1"
version = "0.15.0"
authors = [
"zer0 <[email protected]>", "vlopes11 <[email protected]>", "CPerezz <[email protected]>", "Kristoffer Ström <[email protected]>"
]
Expand Down
21 changes: 14 additions & 7 deletions src/tree/annotation/max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ impl Borrow<BlsScalar> for PoseidonMaxAnnotation {
}
}

impl Borrow<u64> for PoseidonMaxAnnotation {
fn borrow(&self) -> &u64 {
match &self.max {
Max::Maximum(m) => m,
Max::NegativeInfinity => &u64::min_value(),
}
impl Borrow<Max<u64>> for PoseidonMaxAnnotation {
fn borrow(&self) -> &Max<u64> {
&self.max
}
}

Expand Down Expand Up @@ -88,6 +85,14 @@ where
}
}

#[inline]
fn borrow_u64<A: Borrow<Max<u64>>>(ann: &A) -> u64 {
match ann.borrow() {
Max::NegativeInfinity => 0,
Max::Maximum(m) => *m,
}
}

impl<C, L, S> PoseidonWalkableAnnotation<C, u64, L, S> for PoseidonMaxAnnotation
where
L: PoseidonLeaf<S>,
Expand All @@ -100,7 +105,9 @@ where
fn poseidon_walk(walk: Walk<'_, C, S>, data: u64) -> Step<'_, C, S> {
match walk {
Walk::Leaf(l) if data <= *l.borrow() => Step::Found(l),
Walk::Node(n) if data <= *n.annotation().borrow() => Step::Into(n),
Walk::Node(n) if data <= borrow_u64(n.annotation()) => {
Step::Into(n)
}
_ => Step::Next,
}
}
Expand Down

0 comments on commit 2ecc42b

Please sign in to comment.