Skip to content

Commit

Permalink
fix: correctly load first byte when loading proof
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 13, 2024
1 parent a67bf6a commit 2be432f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/merkle/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ impl PartialEq for MerkleProofRef<'_> {
}
}

impl PartialEq<MerkleProof> for MerkleProofRef<'_> {
fn eq(&self, other: &MerkleProof) -> bool {
self.hash == other.hash
&& self.depth == other.depth
&& self.cell.as_ref() == other.cell.as_ref()
}
}

impl Default for MerkleProofRef<'_> {
fn default() -> Self {
Self {
Expand All @@ -44,7 +52,7 @@ impl<'a> Load<'a> for MerkleProofRef<'a> {
return Err(Error::CellUnderflow);
}

if !s.cell().descriptor().is_exotic() || ok!(s.get_u8(0)) != CellType::MerkleProof.to_byte()
if !s.cell().descriptor().is_exotic() || ok!(s.load_u8()) != CellType::MerkleProof.to_byte()
{
return Err(Error::InvalidCell);
}
Expand Down Expand Up @@ -89,6 +97,14 @@ impl PartialEq for MerkleProof {
}
}

impl PartialEq<MerkleProofRef<'_>> for MerkleProof {
fn eq(&self, other: &MerkleProofRef<'_>) -> bool {
self.hash == other.hash
&& self.depth == other.depth
&& self.cell.as_ref() == other.cell.as_ref()
}
}

impl Default for MerkleProof {
fn default() -> Self {
Self {
Expand Down
3 changes: 3 additions & 0 deletions src/merkle/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ fn correct_proof_store_load() {

let parsed = cell.as_ref().parse::<MerkleProof>().unwrap();
assert_eq!(parsed, proof);

let parsed = cell.as_ref().parse::<MerkleProofRef<'_>>().unwrap();
assert_eq!(parsed, proof);
}

#[test]
Expand Down

0 comments on commit 2be432f

Please sign in to comment.