Created
June 1, 2020 03:59
-
-
Save azuchi/38db49c14ca38f2ab71e44bac1fbc964 to your computer and use it in GitHub Desktop.
Rustのaccumulatorのinclusion proofの生成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[test] | |
fn test_check(){ | |
let acc = Accumulator::<Rsa2048, &'static str>::empty().add(&["a", "b", "c"]); | |
let (acc_d, proof_d) = acc.add_with_proof(&["d"]); | |
let (acc_e, proof_e) = acc_d.clone().add_with_proof(&["e"]); | |
println!("acc_e: {:?}", &acc_e); | |
// 更新後のacc_eに対してacc_dのプルーフでの検証はできない。 | |
println!("verify membership d from e: {:?}", acc_e.clone().verify_membership(&"d", &proof_d)); | |
let all = prime_hash_product(&["a", "b", "c", "d", "e"]); | |
let d_prime = hash_to_prime("d"); | |
let others = all / d_prime; | |
let base = Rsa2048::exp(&Rsa2048::elem(2), &others); | |
println!("all: {:?}", prime_hash_product(&["a", "b", "c", "d", "e"])); | |
println!("all acc: {:?}", Rsa2048::exp(&Rsa2048::elem(2), &prime_hash_product(&["a", "b", "c", "d", "e"]))); | |
println!("others: {:?}", &others); | |
println!("d_prime: {:?}", hash_to_prime(&["d"])); | |
println!("base: {:?}", &base); | |
println!("only d minus: {:?}", prime_hash_product(&["a", "b", "c", "e"])); | |
assert!(prime_hash_product(&["a", "b", "c", "e"]) == others); | |
assert!(Rsa2048::exp(&base, &hash_to_prime("d")) == acc_e.clone().value); | |
let proof = Poe::<Rsa2048>::prove(&base, &hash_to_prime("d"), &acc_e.value); | |
let update_proof = MembershipProof{ | |
witness: Witness(Accumulator::<Rsa2048, &'static str>{phantom: PhantomData, value: base.clone()}), | |
proof | |
}; | |
assert!(acc_e.verify_membership(&"d", &update_proof)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment