Skip to content

Commit

Permalink
test 2
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed May 26, 2024
1 parent a64cedd commit b1fbef4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
4 changes: 2 additions & 2 deletions aiken.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ requirements = []
source = "github"

[etags]
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1716739572, nanos_since_epoch = 238233000 }, "d7aadd4a9b25589bd6d5e3bbedcd809cdf97fe3eddb365cf89cd6ac6bc829643"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1716739572, nanos_since_epoch = 12247000 }, "dfda6bc70aad760f7f836c0db06b07e0a398bb3667f4d944d7d7255d54a454af"]
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1716743235, nanos_since_epoch = 519470000 }, "d7aadd4a9b25589bd6d5e3bbedcd809cdf97fe3eddb365cf89cd6ac6bc829643"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1716743235, nanos_since_epoch = 326281000 }, "dfda6bc70aad760f7f836c0db06b07e0a398bb3667f4d944d7d7255d54a454af"]
17 changes: 7 additions & 10 deletions lib/aiken/sparse_merkle_tree/merkle_blake256.ak
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ pub fn combine_sides(
|> HashedProof
}

pub fn pass_through_trace(x: ByteArray) -> ByteArray {
trace to_hex(x)
x
}

/// Combine the left and right proofs to get the new combined hash
/// Then repeat with the item to be inserted
pub fn combine_proofs(
Expand Down Expand Up @@ -347,11 +352,7 @@ pub fn left_proof(
leaf_byte
|> bytearray.concat(left_leaf.inner)
|> hash.blake2b_256
|> do_left_proof(
left_side,
bytearray.length(left_side.inner),
proof_length(),
)
|> do_left_proof(left_side, bytearray.length(left_side.inner), 0)
|> HashedProof
}
}
Expand Down Expand Up @@ -442,11 +443,7 @@ pub fn right_proof(
leaf_byte
|> bytearray.concat(right_leaf.inner)
|> hash.blake2b_256
|> do_right_proof(
right_side,
bytearray.length(right_side.inner),
proof_length(),
)
|> do_right_proof(right_side, bytearray.length(right_side.inner), 0)
|> HashedProof
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/aiken/sparse_merkle_tree_blake256.ak
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use aiken/sparse_merkle_tree/merkle_blake256.{

pub fn init_root() -> Root<a> {
let lower_leaf =
leaf_byte |> bytearray.concat(merkle_lower_bound) |> hash.blake2b_256
leaf_byte
|> bytearray.concat(merkle_lower_bound)
|> hash.blake2b_256

let upper_leaf =
leaf_byte |> bytearray.concat(merkle_upper_bound) |> hash.blake2b_256
Expand Down
37 changes: 36 additions & 1 deletion lib/aiken/sparse_merkle_tree_blake256_test.ak
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use aiken/bytearray
use aiken/hash
use aiken/sparse_merkle_tree/consts.{merkle_lower_bound, merkle_upper_bound}
use aiken/sparse_merkle_tree/merkle_blake256.{
MerkleProofBlock, Root, check_bounds, check_heights, combine_proofs,
get_starting_side, hash_to_hashed_proof, left_proof, right_proof,
get_starting_side, hash_to_hashed_proof, leaf_byte, left_proof, right_proof,
test_add_member, to_string, validate_structure, verify_root,
}
use aiken/sparse_merkle_tree_blake256.{init_root}
Expand Down Expand Up @@ -856,6 +858,7 @@ test sparse_merkle_proof_1() {
let expected_root =
#"18c8dbcc059576ec251c90862baee3387c4ea916ef72e6f7dbf15502521ebed2"

// #"7cf7b9047b2ebdf8bcd289e621c7a8bd304f77f312c287c41848605d8b0deb70"
let member = "apple (0)"

let data_serializer = identity
Expand All @@ -876,3 +879,35 @@ test sparse_merkle_proof_1() {

expected_root == actual_root
}

test sparse_merkle_proof_2() {
let old_root =
#"18c8dbcc059576ec251c90862baee3387c4ea916ef72e6f7dbf15502521ebed2"

let expected_root =
#"49148fa603b03d70fff1733cb9a70a35b9057637e11cde68e30f6f624b001504"

// #"a909ba8699e34f8a78bacd04266b57f36ff3a758b93c0c31b0aaa18ba0be1e87"
let member = "apricot (0)"

let data_serializer = identity

let proof_block =
MerkleProofBlock {
left_leaf: #"7cf7b9047b2ebdf8bcd289e621c7a8bd304f77f312c287c41848605d8b0deb70",
right_leaf: merkle_upper_bound,
left_proofs: bytearray.concat(
bytearray.concat(leaf_byte, merkle_lower_bound) |> hash.blake2b_256,
#"fe",
),
right_proofs: "",
continuing_side_proofs: "",
remaining_proofs: "",
left_right_intersection: 255,
intersecting_level: 254,
}

let actual_root = add_member(member, data_serializer, proof_block, old_root)

expected_root == actual_root
}

0 comments on commit b1fbef4

Please sign in to comment.