more clean up
This commit is contained in:
parent
11589f07bf
commit
ae5558e90b
2
Makefile
2
Makefile
|
@ -23,7 +23,7 @@ update:
|
|||
|
||||
doc:
|
||||
# generates the documentation
|
||||
cargo +nightly doc
|
||||
echo "cargo +nightly doc"
|
||||
|
||||
clean:
|
||||
cargo +nightly clean
|
||||
|
|
23
README.md
23
README.md
|
@ -15,7 +15,9 @@ The libbolt library is a proof of concept implementation that relies on experime
|
|||
* bn
|
||||
* bulletproofs
|
||||
|
||||
# Compile and Install
|
||||
# Installation
|
||||
|
||||
Please ensure you have installed the libsodium library for your platform. See install instructions [here](https://download.libsodium.org/doc/installation/index.html).
|
||||
|
||||
To compile the library, run `make`
|
||||
|
||||
|
@ -49,6 +51,21 @@ The libbolt library provides APIs for three types of privacy-preserving payment
|
|||
* bidirectional payment channels (done)
|
||||
* third-party payments (done)
|
||||
|
||||
# Crypto Design
|
||||
**TODO**
|
||||
|
||||
To build the design docs, run `make doc`.
|
||||
# Documentation
|
||||
|
||||
Build the api documentation by simply running `make doc`. Documentation will be generated in your local `target/doc` directory.
|
||||
|
||||
For the libbolt design documentation, see the `docs/bolt_design.pdf`.
|
||||
|
||||
# Contributions
|
||||
|
||||
To contribute code improvements, please checkout the repository as follows:
|
||||
|
||||
git clone https://github.com/yeletech/libbolt.git
|
||||
|
||||
|
||||
# License
|
||||
|
||||
Licensed under MIT (LICENSE-MIT or http://opensource.org/licenses/MIT)
|
||||
|
|
|
@ -100,7 +100,7 @@ fn main() {
|
|||
println!("******************************************");
|
||||
println!("Testing the pay protocol..");
|
||||
// let's test the pay protocol
|
||||
assert!(bidirectional::pay_by_customer_phase1_precompute(&pp, &init_cust_data.T, &merch_keypair.pk, &mut init_cust_data.csk));
|
||||
bidirectional::pay_by_customer_phase1_precompute(&pp, &init_cust_data.T, &merch_keypair.pk, &mut init_cust_data.csk);
|
||||
let s = PreciseTime::now();
|
||||
let (t_c, new_wallet, pay_proof) = bidirectional::pay_by_customer_phase1(&pp, &channel, &init_cust_data.T, // channel token
|
||||
&merch_keypair.pk, // merchant pub key
|
||||
|
@ -131,7 +131,7 @@ fn main() {
|
|||
println!("Merchant balance: {}", merch_wallet.balance);
|
||||
}
|
||||
|
||||
assert!(bidirectional::pay_by_customer_phase1_precompute(&pp, &init_cust_data.T, &merch_keypair.pk, &mut init_cust_data.csk));
|
||||
bidirectional::pay_by_customer_phase1_precompute(&pp, &init_cust_data.T, &merch_keypair.pk, &mut init_cust_data.csk);
|
||||
let (t_c1, new_wallet1, pay_proof1) = bidirectional::pay_by_customer_phase1(&pp, &channel, &init_cust_data.T, // channel token
|
||||
&merch_keypair.pk, // merchant pub key
|
||||
&init_cust_data.csk, // wallet
|
||||
|
|
|
@ -258,17 +258,6 @@ pub fn sign_d(mpk: &PublicParams, sk: &SecretKeyD, m: &Vec<Fr>) -> SignatureD {
|
|||
return sig;
|
||||
}
|
||||
|
||||
//pub fn random_small_exp(bits: usize) -> Fr {
|
||||
// let buf_len = bits / 8;
|
||||
// let mut s0 = vec![0; buf_len];
|
||||
// randombytes::randombytes_into(&mut s0);
|
||||
// return Fr::interpret(s0.as_slice());
|
||||
// //debug_elem_in_hex("")
|
||||
// //let mut buf: [u8; buf_len] = [0; buf_len];
|
||||
// //randombytes::randombytes_into(&mut buf);
|
||||
// //return Fr::from_str("1234567890").unwrap();
|
||||
//}
|
||||
|
||||
pub fn verify_d_unoptimized(mpk: &PublicParams, pk: &PublicKeyD, m: &Vec<Fr>, sig: &SignatureD) -> bool {
|
||||
//assert!(sig.A.len()+1 <= m.len());
|
||||
//assert!(sig.B.len()+1 <= m.len());
|
||||
|
@ -298,11 +287,7 @@ pub fn verify_d_unoptimized(mpk: &PublicParams, pk: &PublicKeyD, m: &Vec<Fr>, si
|
|||
lhs3 = lhs3 * pairing(pk.X, sig.B[i] * m[i+1]); // eq3
|
||||
}
|
||||
|
||||
// let mut lhs3 = pairing(pk.X, sig.a) * pairing(pk.X, sig.b * m[0]);
|
||||
// for i in 1 .. l {
|
||||
// lhs3 = lhs3 * pairing(pk.X, sig.B[i] * m[i]);
|
||||
// }
|
||||
return (result1 == true) && (lhs2a == rhs2a) && (result2b == true) && (lhs3 == rhs3);
|
||||
return result1 && (lhs2a == rhs2a) && result2b && (lhs3 == rhs3);
|
||||
}
|
||||
|
||||
// optimized but does not include small exps for security
|
||||
|
|
38
src/lib.rs
38
src/lib.rs
|
@ -561,8 +561,6 @@ pub mod bidirectional {
|
|||
third_party_pay: bool
|
||||
}
|
||||
|
||||
// TODO: add display method to print structure (similar to Commitment)
|
||||
|
||||
// proof of wallet signature, blind signature on wallet and common params for NIZK
|
||||
#[derive(Clone)]
|
||||
pub struct CustomerWalletProof {
|
||||
|
@ -584,7 +582,8 @@ pub mod bidirectional {
|
|||
pub balance: i32, // the balance for the user
|
||||
merchant_balance: i32,
|
||||
signature: Option<clsigs::SignatureD>,
|
||||
proof: Option<CustomerWalletProof>, // proof of knowledge computed after obtaining signature on wallet contents in zero-knowledge
|
||||
// proof of signature on wallet contents in zero-knowledge
|
||||
proof: Option<CustomerWalletProof>,
|
||||
refund_token: Option<clsigs::SignatureD>
|
||||
}
|
||||
|
||||
|
@ -810,7 +809,7 @@ pub mod bidirectional {
|
|||
///// end of establish channel protocol
|
||||
|
||||
///// begin of pay protocol
|
||||
pub fn pay_by_customer_phase1_precompute(pp: &PublicParams, T: &ChannelToken, pk_m: &clsigs::PublicKeyD, old_w: &mut CustomerWallet) -> bool {
|
||||
pub fn pay_by_customer_phase1_precompute(pp: &PublicParams, T: &ChannelToken, pk_m: &clsigs::PublicKeyD, old_w: &mut CustomerWallet) {
|
||||
// generate proof of knowledge of valid signature on previous wallet signature
|
||||
let old_wallet_sig = &old_w.signature;
|
||||
|
||||
|
@ -847,10 +846,9 @@ pub mod bidirectional {
|
|||
let proof_vs = clproto::vs_gen_nizk_proof(&old_x, &common_params, common_params.vs);
|
||||
|
||||
// return the payment proof for the old wallet
|
||||
let proof = CustomerWalletProof { proof_cv: proof_old_cv, proof_vs: proof_vs, bal_com: old_w_bal_com,
|
||||
blind_sig: blind_sig, common_params: common_params };
|
||||
old_w.proof = Some(proof);
|
||||
return true;
|
||||
let old_iou_proof = CustomerWalletProof { proof_cv: proof_old_cv, proof_vs: proof_vs,
|
||||
bal_com: old_w_bal_com, blind_sig: blind_sig, common_params: common_params };
|
||||
old_w.proof = Some(old_iou_proof);
|
||||
}
|
||||
|
||||
pub fn pay_by_customer_phase1(pp: &PublicParams, channel: &ChannelState, T: &ChannelToken, pk_m: &clsigs::PublicKeyD,
|
||||
|
@ -1261,11 +1259,11 @@ pub mod bidirectional {
|
|||
}
|
||||
}
|
||||
|
||||
// on input the customer and merchant channel tokens T_c, T_m
|
||||
// along with closure messages rc_c, rc_m
|
||||
// this will be executed by the network --> using new opcodes (makes sure
|
||||
// only one person is right)
|
||||
pub fn resolve(pp: &PublicParams, c: &InitCustomerData, m: &InitMerchantData, // cust and merch
|
||||
/// on input the customer and merchant channel tokens T_c, T_m
|
||||
/// along with closure messages rc_c, rc_m
|
||||
/// this will be executed by the network --> using new opcodes (makes sure
|
||||
/// only one person is right)
|
||||
pub fn resolve(pp: &PublicParams, c: &InitCustomerData, m: &InitMerchantData,
|
||||
rc_c: Option<ChannelclosureC>, rc_m: Option<ChannelclosureM>,
|
||||
rt_w: Option<clsigs::SignatureD>) -> (i32, i32) {
|
||||
let total_balance = c.csk.balance + m.csk.balance;
|
||||
|
@ -1274,7 +1272,8 @@ pub mod bidirectional {
|
|||
}
|
||||
|
||||
if rc_c.is_none() {
|
||||
// customer did not specify channel closure message
|
||||
// could not find customer's channel closure message.
|
||||
// judgement: give merchant everything
|
||||
return (0, total_balance);
|
||||
}
|
||||
|
||||
|
@ -1317,9 +1316,8 @@ pub mod bidirectional {
|
|||
let rc_merch = rc_m.unwrap();
|
||||
let refute_valid = clsigs::verify_d(&pp.cl_mpk, &pk_m, &rc_merch.message.hash(), &rc_merch.signature);
|
||||
if !refute_valid {
|
||||
// refutation is invalid, so return customer balance and merchant balance - claimed value
|
||||
let claimed_value = 0; // TODO: figure out where this value comes from
|
||||
return (c.csk.balance, m.csk.balance - claimed_value); // TODO: ensure merchant balance > 0
|
||||
// refute token is invalid, so return customer balance and merchant balance
|
||||
return (c.csk.balance, m.csk.balance);
|
||||
} else {
|
||||
// if refutation is valid
|
||||
return (0, total_balance);
|
||||
|
@ -1425,7 +1423,7 @@ mod tests {
|
|||
cust_keys: &clsigs::KeyPairD, cust_data: &mut bidirectional::InitCustomerData,
|
||||
payment_increment: i32) {
|
||||
// let's test the pay protocol
|
||||
assert!(bidirectional::pay_by_customer_phase1_precompute(&pp, &cust_data.T, &merch_keys.pk, &mut cust_data.csk));
|
||||
bidirectional::pay_by_customer_phase1_precompute(&pp, &cust_data.T, &merch_keys.pk, &mut cust_data.csk);
|
||||
|
||||
let (t_c, new_wallet, pay_proof) = bidirectional::pay_by_customer_phase1(&pp, &channel, &cust_data.T, // channel token
|
||||
&merch_keys.pk, // merchant pub key
|
||||
|
@ -1535,8 +1533,8 @@ mod tests {
|
|||
cust2_keys: &clsigs::KeyPairD, cust2_data: &mut bidirectional::InitCustomerData,
|
||||
payment_increment: i32) {
|
||||
// let's test the pay protocol
|
||||
assert!(bidirectional::pay_by_customer_phase1_precompute(&pp, &cust1_data.T, &merch_keys.pk, &mut cust1_data.csk));
|
||||
assert!(bidirectional::pay_by_customer_phase1_precompute(&pp, &cust2_data.T, &merch_keys.pk, &mut cust2_data.csk));
|
||||
bidirectional::pay_by_customer_phase1_precompute(&pp, &cust1_data.T, &merch_keys.pk, &mut cust1_data.csk);
|
||||
bidirectional::pay_by_customer_phase1_precompute(&pp, &cust2_data.T, &merch_keys.pk, &mut cust2_data.csk);
|
||||
|
||||
println!("Channel 1 fee: {}", channel1.get_channel_fee());
|
||||
let (t_c1, new_wallet1, pay_proof1) = bidirectional::pay_by_customer_phase1(&pp, &channel1,
|
||||
|
|
Loading…
Reference in New Issue