Skip to content

Add keccak services/requests/messages#3580

Merged
jsdanielh merged 1 commit into
albatross-nextfrom
viquezcl/albatros-next
Feb 18, 2026
Merged

Add keccak services/requests/messages#3580
jsdanielh merged 1 commit into
albatross-nextfrom
viquezcl/albatros-next

Conversation

@viquezclaudio

Copy link
Copy Markdown
Member

Functionality to request and relay keccak256 proofs

Pull request checklist

  • All tests pass. The project builds and runs.
  • I have resolved any merge conflicts.
  • I have resolved all clippy and rustfmt warnings.

@pkg-pr-new

pkg-pr-new Bot commented Jan 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nimiq/core-rs-albatross/@nimiq/core@3580

commit: 90efdcd

@viquezclaudio viquezclaudio force-pushed the viquezcl/albatros-next branch 2 times, most recently from ceb850c to c3c318f Compare January 16, 2026 20:04
Comment thread network-interface/src/peer_info.rs Outdated
Comment thread consensus/src/consensus/consensus_proxy.rs Outdated
Comment thread consensus/src/consensus/consensus_proxy.rs Outdated
Comment thread consensus/src/consensus/consensus_proxy.rs
Comment thread consensus/src/consensus/mod.rs Outdated
Comment thread primitives/account/src/account/oracle_contract.rs Outdated
Comment thread primitives/account/tests/oracle_contract.rs Outdated
Comment thread primitives/account/tests/oracle_contract.rs Outdated
Comment thread primitives/account/tests/oracle_contract.rs Outdated
Comment thread primitives/account/tests/oracle_contract.rs Outdated
Comment thread blockchain/src/history/interface.rs
@viquezclaudio viquezclaudio force-pushed the viquezcl/albatros-next branch 2 times, most recently from 255f897 to 312daf5 Compare February 2, 2026 20:05
@viquezclaudio viquezclaudio force-pushed the viquezcl/albatros-next branch from 312daf5 to 2422f54 Compare February 2, 2026 22:13
Comment thread consensus/src/messages/mod.rs Outdated
Comment thread consensus/src/messages/mod.rs Outdated
Comment thread primitives/transaction/src/account/htlc_contract.rs
Comment thread primitives/transaction/src/account/htlc_contract.rs Outdated
match self {
AnyHash::Blake2b(_) => {
let mut hasher = Blake2bHasher::default();
hasher.write_all(other.as_bytes()).unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't we using digest?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Hasher::digest only takes a single &[u8], so it can't hash two byte slices in sequence. We need to hash self || other without allocating.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, sorry. Yes, I meant chain

let mut hasher = Sha256Hasher::default();
hasher.write_all(other.as_bytes()).unwrap();
hasher.write_all(self.as_bytes()).unwrap();
AnyHash::Sha256(AnyHash32(hasher.finish().into()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

let mut hasher = Sha512Hasher::default();
hasher.write_all(other.as_bytes()).unwrap();
hasher.write_all(self.as_bytes()).unwrap();
AnyHash::Sha512(AnyHash64(hasher.finish().into()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

let mut hasher = Keccak256Hasher::default();
hasher.write_all(other.as_bytes()).unwrap();
hasher.write_all(self.as_bytes()).unwrap();
AnyHash::Keccak256(AnyHash32(hasher.finish().into()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@viquezclaudio viquezclaudio force-pushed the viquezcl/albatros-next branch 2 times, most recently from 3e85391 to 8979767 Compare February 5, 2026 16:10
Comment thread primitives/account/src/account/oracle_contract.rs Outdated
Comment thread primitives/account/tests/oracle_contract.rs Outdated
Comment thread primitives/account/tests/oracle_contract.rs Outdated
match self {
AnyHash::Blake2b(_) => {
let mut hasher = Blake2bHasher::default();
hasher.write_all(self.as_bytes()).unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to use chain to avoid importing std::io::Write?

@viquezclaudio viquezclaudio force-pushed the viquezcl/albatros-next branch from 8979767 to 5af33eb Compare February 5, 2026 20:02
let combined: Vec<u8> = self
.as_bytes()
.iter()
.chain(other.as_bytes())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking on chain from the hasher. Something like:
Blake2bHasher::default().chain(self.as_bytes()).chain(other.as_bytes()).finish();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok there is a problem with chain because doing something like:
Blake2bHasher::default().chain(self.as_bytes()).chain(other.as_bytes()).finish().into(),

gives a compilation error because chain<T: SerializeContent>(self, h: &T) uses a type parameter T that is Sized by default. self.as_bytes() is &[u8], so T is inferred as [u8], which is unsized, so the compiler errors.

The fix would be to use the hasher's write API, as it currently is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, but then you could implement SerializeContent for AnyHash:

impl SerializeContent for AnyHash {
    fn serialize_content<W: io::Write, H: HashOutput>(&self, writer: &mut W) -> io::Result<()> {
        writer.write_all(self.as_bytes())?;
        Ok(())
    }
}

And then:

Blake2bHasher::default()
    .chain(&self)
    .chain(&other)
    .finish()
    .into(),

@viquezclaudio viquezclaudio force-pushed the viquezcl/albatros-next branch 2 times, most recently from eaa3615 to 90efdcd Compare February 18, 2026 20:50

@jsdanielh jsdanielh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Functionality to request and relay keccak256 proofs
Implemented requested changes
@jsdanielh jsdanielh force-pushed the viquezcl/albatros-next branch from 90efdcd to 7bb72f1 Compare February 18, 2026 21:43
@jsdanielh jsdanielh merged commit 7bb72f1 into albatross-next Feb 18, 2026
8 checks passed
@jsdanielh jsdanielh deleted the viquezcl/albatros-next branch February 18, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants