fix test and new verifying key

This commit is contained in:
NikVolf 2019-04-29 17:41:00 +03:00
parent 551147f67a
commit 2362b335f7
7 changed files with 43 additions and 8 deletions

2
Cargo.lock generated
View File

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "abstract-ns"
version = "0.3.4"

View File

@ -21,6 +21,12 @@ pub fn load_sapling_output_verifying_key() -> Result<Groth16VerifyingKey, String
Ok(Groth16VerifyingKey(prepare_verifying_key(&output_vk.into())))
}
pub fn load_joinsplit_groth16_verifying_key() -> Result<Groth16VerifyingKey, String> {
let output_vk_json = include_bytes!("../../../res/sprout-groth16-key.json");
let output_vk = serde_json::from_slice::<VerifyingKey>(&output_vk_json[..]).unwrap();
Ok(Groth16VerifyingKey(prepare_verifying_key(&output_vk.into())))
}
type G1 = Point<G1Uncompressed>;
type G2 = Point<G2Uncompressed>;

View File

@ -35,7 +35,7 @@ use siphasher::sip::SipHasher24;
use primitives::hash::{H32, H160, H256};
pub use json::groth16::{
load_sapling_spend_verifying_key, load_sapling_output_verifying_key,
load_sapling_spend_verifying_key, load_sapling_output_verifying_key, load_joinsplit_groth16_verifying_key,
};
pub use pghr13::{VerifyingKey as Pghr13VerifyingKey, Proof as Pghr13Proof, verify as pghr13_verify};

View File

@ -6,6 +6,8 @@ lazy_static! {
.expect("hardcoded value should load without errors");
static ref SAPLING_OUTPUT_VK: crypto::Groth16VerifyingKey = crypto::load_sapling_output_verifying_key()
.expect("hardcoded value should load without errors");
static ref JOINSPLIT_GROTH16_VK: crypto::Groth16VerifyingKey = crypto::load_joinsplit_groth16_verifying_key()
.expect("hardcoded value should load without errors");
}
#[derive(Debug, Clone)]
@ -73,6 +75,9 @@ pub struct ConsensusParams {
/// Active key for pghr13 joinsplit verification
pub joinsplit_verification_key: crypto::Pghr13VerifyingKey,
/// Active key for groth16 joinsplit verification
pub joinsplit_groth16_verification_key: &'static crypto::Groth16VerifyingKey,
/// Sapling spend verification key.
pub sapling_spend_verifying_key: &'static crypto::Groth16VerifyingKey,
/// Sapling output verification key.
@ -209,6 +214,7 @@ impl ConsensusParams {
equihash_params: Some((200, 9)),
joinsplit_verification_key: mainnet_pghr_verification_key(),
joinsplit_groth16_verification_key: &JOINSPLIT_GROTH16_VK,
sapling_spend_verifying_key: &SAPLING_SPEND_VK,
sapling_output_verifying_key: &SAPLING_OUTPUT_VK,
@ -288,9 +294,11 @@ impl ConsensusParams {
equihash_params: Some((200, 9)),
joinsplit_verification_key: testnet_pghr_verification_key(),
joinsplit_groth16_verification_key: &JOINSPLIT_GROTH16_VK,
sapling_spend_verifying_key: &SAPLING_SPEND_VK,
sapling_output_verifying_key: &SAPLING_OUTPUT_VK,
},
Network::Regtest => ConsensusParams {
network: network,
@ -320,6 +328,7 @@ impl ConsensusParams {
equihash_params: Some((200, 9)),
joinsplit_verification_key: regtest_pghr_verification_key(),
joinsplit_groth16_verification_key: &JOINSPLIT_GROTH16_VK,
sapling_spend_verifying_key: &SAPLING_SPEND_VK,
sapling_output_verifying_key: &SAPLING_OUTPUT_VK,
@ -352,6 +361,7 @@ impl ConsensusParams {
equihash_params: None,
joinsplit_verification_key: unitest_pghr_verification_key(),
joinsplit_groth16_verification_key: &JOINSPLIT_GROTH16_VK,
sapling_spend_verifying_key: &SAPLING_SPEND_VK,
sapling_output_verifying_key: &SAPLING_OUTPUT_VK,

View File

@ -0,0 +1,20 @@
{
"alphaG1": "0x0db882cf5db3e8567f16b4db1772d4d1f5a3fe8d62f0df2eb8a5cfa50806702afde8fc25335eb5ec859c2818b2610b2e19ab445dac720bb1f2b0cd3336f7a1acc62bf1b3a321826264dc7e469281e23b218394d598689da04e136878ff9a7897",
"betaG1": "0x014a78a8d17180a37c4ca8fb231f264ab89bd14863777fc1ffe901fd92444365d18f78237612ac38e39f419c32f0824515219ec45c26c1fad530514ed891a0d0043acedf348922102e95b3e6d07e0afa94c58aa41480631fc1ca36e55aae51fd",
"betaG2": "0x0a416b8187450b28f025c421e3ff14d38f9abd9af2f1046b914b53ab37e9aebba683cb25284e5c22fa341129985250a103547de5d005df48265f7cb258162253d56fbc682d106a1ecb07666ebf7524a364e512c37aa62f82d6e7dd4ed8838478104376a98072766c29959358e9cde6a4985618f65ea257e8f288974f4aedde52e5dac2fb7ae5d30eab7cd828a2c8b15f15b16f139f2c33ef33d63befe404e696c97077d17ea42f4ff9d82ec456aaf43914a3d07968111a3a348f157e64c0278a",
"gammaG2": "0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801",
"deltaG1": "0x163a172acc0b2c767845cfbd68b1d833c0339ac63cf9e3ed1118da02b49e4c52f519fa66132d905a832db41dd601692215d8a41d6a57d05dd805a02eb757a3368bd5d1ff128a6fb12a0476bc197b0e8b6ccfb87ac654ed63d38c6892eea8a30d",
"deltaG2": "0x0b1463b9bac462399c6f68c288f3b011ece2f6373b93e3fadb54dc942d507bcda05a890d560ae31b2fe6335c9a20545d0cc178cc2059a2ed2310ef82009f8ccd9626461349826dba59d3c472c4e714e8627415b0e721423979b63f92d487b47202fd41281149bc3ac44efacb4cb9a5e08f94a501df13839b119340db136ae7b429286f7badb76ec1ad5cb6a82aba801303d215102021c0b077499892e9e395ce26379b791f3aa24332244af952bd63d8b88d3f65b13e72189d2aec114a95eabe",
"ic": [
"0x0d97f9bc23442f2ad8102c99be160c76f4acbbe094c83dac8842ea5852ee8906c69e5c591086aa4c45f29c75bc53dd460174af2943249b84206d65c7541c826b3c51ef10f8ef866d7c456c8aecb52e5ff49befe4f03a8c29e3c5d18ade6f41fd",
"0x0e0c186c0a4b6a5439c155f0470f5e858a69103593ed0cea4924ee402b5fffac8c6cce307265ef0a7fd3f3d943dd40a201ab5bdc58bd06f03b6e506c4505fb0e60c425b648c7e9b770c338aa47dfe68b512a601266adcacb026bf92b0ad545ef",
"0x019e822cf432de2712476848e4973be485f2dab7b7b2c61806132cd823a008b6c3040aa64566fa7e4a36a082c11626990a5a402a52d7c9a4a583b534b78436fcc9e54b31ad0d228a12e4a7fd4846f7f1daf4e9de5cb4a81cc5edda80942be9f4",
"0x01378546aae41ca23490479020f4c606830d3d52e1202ca591bfe697b570347096e21bd63406cba5513155c28e03f3dc0ddd3f9c14a6e4ae0a4b8db973b7f913fb5b419fc8e3c1e829b1468e6e389df38ada375f86285a30519c107d6b5bfb60",
"0x0c46d90dc5a2cda86f764b71d965e7ede02b7f3ae750484d8abda3adee364ffda5929a24029fcfc012957720eaf4f1960ff515e37dc31c9db3adde517d7fb0ce3f1dd151611529715994d98485f2cae57f36a0e7a472c891b059f59659bbc04b",
"0x0a96b78180f7191125f5e064a22abff870275163a66f9805e741d8b578ec52df3cf18bb548a9b9477e7c257d8f3b7b69153d0c6dd9a29d335e9d04843413c90f04908f6a7458a73d3839962872e294c9e57c1e8c440b36a110b7e3a89783caa9",
"0x17ae7a0bf88c71915691a2a39bd4286a4b7413af95dbcb9243dd3d5e2c10d5631485d6f6950e667cad9ae32dd2bd6128103707248c026256835c920c2b063a365940ee1d5ae499679dea872eb4aa3e276fbc8ecb7c2954e32311e8ff14c20859",
"0x055d14d652bc8eda7f6b2e8cd4684c8af8a5e56fdfd00cd790b718b535f3b0717c065c4cb678105448b5fecf77d003030c8347c8764d2a7595e87632ab7ece577dff40d78235f96b38b5e200b8c945eceb153b28c0436732360e38724d8f2f98",
"0x01abb94269630f88638f72caac370308512a1d00743c4e3eb73992fca590c811580bee7d53bf375627b02baca5c8f82e02ca79f2de40bcf0dffa4c2e6f89aff5c59c9f0cad78a0e31b3c2846143ecdb726bddc76dcd3ecd9fa140e42985801b9",
"0x18d405db3a6c7fd359c38632a917587ad836cc9f1dc13040b55e0751afe6e1c2369b33c96ac61f1fb1e25bf2021b630819808298f2d82910dce519ebf1db6fbd6f9f965d8e075d65b5025dc13a7d92f73e15a6bbbaa1134c494ac8de335110bb"
]
}

View File

@ -602,7 +602,7 @@ impl<'a> JoinSplitProof<'a> {
&desc,
&join_split,
&self.consensus_params.joinsplit_verification_key,
&self.consensus_params.sapling_spend_verifying_key,
&self.consensus_params.joinsplit_groth16_verification_key,
).map_err(|_e| TransactionError::InvalidJoinSplit(index))?;
tree_cache.continue_root(&desc.anchor.into(), &desc.commitments)?;

View File

@ -69,15 +69,12 @@ pub fn verify(
JoinSplitProof::Groth(ref proof) => {
let input = input.into_bls_frs();
assert_eq!(input.len(), 9);
assert_eq!(sapling_verifying_key.0.ic.len(), 10);
if !crypto::bellman::groth16::verify_proof(
&sapling_verifying_key.0,
&proof.to_bls_proof().map_err(|_| ErrorKind::InvalidEncoding)?,
&input,
// ).map_err(|_| ErrorKind::InvalidGrothProof)? {
).unwrap() {
).map_err(|_| ErrorKind::InvalidGrothProof)? {
return Err(ErrorKind::InvalidGrothProof);
}
},
@ -162,7 +159,7 @@ mod tests {
use super::{compute_hsig, verify};
use crypto;
use chain::{JoinSplit, JoinSplitProof, JoinSplitDescription};
use crypto::{load_sapling_spend_verifying_key, load_sapling_output_verifying_key};
use crypto::load_joinsplit_groth16_verifying_key;
fn hash(s: &'static str) -> [u8; 32] {
use hex::FromHex;
@ -394,7 +391,7 @@ mod tests {
&js.descriptions[0],
&js,
&vkey(),
&load_sapling_spend_verifying_key().expect("Known to be good"),
&load_joinsplit_groth16_verifying_key().unwrap(),
).unwrap();
}