Skip to content

Commit

Permalink
Add full zksnarks tx support
Browse files Browse the repository at this point in the history
  • Loading branch information
joeuhren committed Mar 22, 2021
1 parent d2521a8 commit 4bef1a1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Table of Contents
- **getsupply:** Returns the current money supply
- **getnextrewardestimate:** Returns an estimate for the next block reward based on the current state of decentralized voting
- **getnextrewardwhenstr:** Returns a string describing how long until the votes are tallied and the next block reward is computed
- Partial Zcash/zk-SNARKs private tx support (90% complete)
- Zcash/zk-SNARKs private tx support

### See it in Action

Expand Down
73 changes: 56 additions & 17 deletions lib/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,26 +1082,65 @@ module.exports = {
// check if zksnarks is enabled
if (settings.blockchain_specific.zksnarks.enabled == true) {
// check for hidden/anonymous outputs
vhidden.forEach(function(vanon, i) {
if (vanon.vpub_old > 0) {
module.exports.convert_to_satoshi(parseFloat(vanon.vpub_old), function(amount_sat) {
arr_vout.push({addresses: 'hidden_address', amount: amount_sat});
});
} else {
module.exports.convert_to_satoshi(parseFloat(vanon.vpub_new), function(amount_sat) {
if (vhidden.length > 0 && (!vout || vout.length == 0) && (!vin || vin.length == 0)) {
if (vhidden != null && vhidden.length > 0) {
tx_type = "zksnarks";
// loop through all hidden/anonymous outputs
module.exports.syncLoop(vhidden.length, function (loop) {
var i = loop.iteration();

if (vhidden[i].vpub_old > 0) {
// process vout addresses
processVoutAddresses(['hidden_address'], parseFloat(vhidden[i].vpub_old), arr_vout, function(vout_array) {
// save updated array
arr_vout = vout_array;
// move to next vout
loop.next();
});
} else {
if ((!vout || vout.length == 0) && (!vin || vin.length == 0)) {
// hidden sender is sending to hidden recipient
// the sent and received values are not known in this case. only the fee paid is known and subtracted from the sender.
arr_vout.push({addresses: 'hidden_address', amount: 0});
// process vout addresses
processVoutAddresses(['hidden_address'], 0, arr_vout, function(vout_array) {
// save updated array
arr_vout = vout_array;
// add a private send address with the known amount sent
module.exports.is_unique(arr_vin, 'hidden_address', function(unique, index) {
if (unique == true) {
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
// move to next vout
loop.next();
});
} else {
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
arr_vin[index].amount = arr_vin[index].amount + amount_sat;
// move to next vout
loop.next();
});
}
});
});
} else {
module.exports.is_unique(arr_vin, 'hidden_address', function(unique, index) {
if (unique == true) {
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
// move to next vout
loop.next();
});
} else {
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
arr_vin[index].amount = arr_vin[index].amount + amount_sat;
// move to next vout
loop.next();
});
}
});
}

// add a private send address with the known amount sent
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
});
}

tx_type = "zksnarks";
});
}
});
}
}

if (typeof vout[0] !== 'undefined' && vout[0].scriptPubKey.type == 'nonstandard') {
Expand Down
3 changes: 0 additions & 3 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,6 @@ exports.blockchain_specific = {
}
},
// zksnarks: A collection of settings that pertain to Zcash zk-SNARKs private transactions
// NOTE: This is only partial zk-SNARKs private tx support (90% complete)
// While the current implementation should be stable, it does not yet work in 100% of the transaction scenarios
// USE THIS FEATURE AT YOUR OWN RISK. FOR TESTING PURPOSES ONLY!
"zksnarks": {
// enabled: Enable/disable Zcash zk-SNARKs private transaction support (true/false)
// If set to false, zk-SNARKs private txs will not be properly read or saved by the explorer
Expand Down
3 changes: 0 additions & 3 deletions settings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,6 @@
}
},
// zksnarks: A collection of settings that pertain to Zcash zk-SNARKs private transactions
// NOTE: This is only partial zk-SNARKs private tx support (90% complete)
// While the current implementation should be stable, it does not yet work in 100% of the transaction scenarios
// USE THIS FEATURE AT YOUR OWN RISK. FOR TESTING PURPOSES ONLY!
"zksnarks": {
// enabled: Enable/disable Zcash zk-SNARKs private transaction support (true/false)
// If set to false, zk-SNARKs private txs will not be properly read or saved by the explorer
Expand Down

0 comments on commit 4bef1a1

Please sign in to comment.