From f4997bae39f08b05c52368813dc7e4e360544e46 Mon Sep 17 00:00:00 2001 From: Artem Pikulin Date: Mon, 15 Oct 2018 20:29:50 +0700 Subject: [PATCH] #191 Use different zk proof size depending on tx version. --- iguana/exchanges/LP_bitcoin.c | 17 +++++++++++------ iguana/exchanges/LP_include.h | 2 +- start_BEER_OTHER_trade.sh | 1 + start_BEER_OTHER_trade_inverted.sh | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 7217e2036..79043d97d 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3726,7 +3726,7 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht return(sigtxid); } -int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgjoinsplit *msg) +int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgjoinsplit *msg,uint32_t proof_size) { int32_t len = 0; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->vpub_old),&msg->vpub_old); @@ -3746,9 +3746,9 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->vmacs[0]),msg->vmacs[0].bytes); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->vmacs[1]),msg->vmacs[1].bytes); if ( rwflag == 1 ) - memcpy(&serialized[len],msg->zkproof,sizeof(msg->zkproof)); - else memcpy(msg->zkproof,&serialized[len],sizeof(msg->zkproof)); - len += sizeof(msg->zkproof); + memcpy(&serialized[len],msg->zkproof,proof_size); + else memcpy(msg->zkproof,&serialized[len],proof_size); + len += proof_size; return(len); } @@ -3774,15 +3774,20 @@ int32_t iguana_rwmsgtx(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shty len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); uint32_t overwintered = msg->version >> 31; uint32_t version = msg->version; + // for version 4 the ZK proof size is 192, otherwise 296 + uint32_t zksnark_proof_size = ZKSNARK_PROOF_SIZE; if (zcash) { if (overwintered) { + version = msg->version & 0x7FFFFFFF; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version_group_id),&msg->version_group_id); + if (version >= 4) { + zksnark_proof_size = GROTH_PROOF_SIZE; + } } } if ( json != 0 ) { if (overwintered) { - version = msg->version & 0x7FFFFFFF; jaddnum(json,"version",msg->version & 0x7FFFFFFF); } else { jaddnum(json, "version", msg->version); @@ -4042,7 +4047,7 @@ int32_t iguana_rwmsgtx(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shty if ( msg->numjoinsplits > 0 ) { for (i=0; inumjoinsplits; i++) - len += iguana_rwjoinsplit(rwflag,&serialized[len],&joinsplit); + len += iguana_rwjoinsplit(rwflag,&serialized[len],&joinsplit,zksnark_proof_size); if ( rwflag != 0 ) { memset(joinsplitpubkey,0,sizeof(joinsplitpubkey)); // for now diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 4054d85bf..f7271af19 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -187,7 +187,7 @@ struct iguana_msgjoinsplit uint64_t vpub_old,vpub_new; bits256 anchor,nullifiers[2],commitments[2],ephemeralkey; bits256 randomseed,vmacs[2]; - uint8_t zkproof[GROTH_PROOF_SIZE]; + uint8_t zkproof[ZKSNARK_PROOF_SIZE]; uint8_t ciphertexts[2][601]; }; diff --git a/start_BEER_OTHER_trade.sh b/start_BEER_OTHER_trade.sh index a81500397..a0652c5ec 100755 --- a/start_BEER_OTHER_trade.sh +++ b/start_BEER_OTHER_trade.sh @@ -1,4 +1,5 @@ #!/bin/bash +sleep 5 docker-compose exec -T clientnode ./enable sleep 3 docker-compose exec -T seednode ./enable diff --git a/start_BEER_OTHER_trade_inverted.sh b/start_BEER_OTHER_trade_inverted.sh index 1b0f9d4be..ce0c9c301 100755 --- a/start_BEER_OTHER_trade_inverted.sh +++ b/start_BEER_OTHER_trade_inverted.sh @@ -1,4 +1,5 @@ #!/bin/bash +sleep 5 docker-compose exec -T clientnode ./enable sleep 3 docker-compose exec -T seednode ./enable