Skip to content

Rewrite parts of channel, cleanup a bunch of stuff #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ description = """
A Bitcoin Lightning implementation in Rust.
Still super-early code-dump quality and is missing large chunks. See README in git repo for suggested projects if you want to contribute. Don't have to bother telling you not to use this for anything serious, because you'd have to finish building it to even try.
"""
build = "build.rs"

[features]
# Supports tracking channels with a non-bitcoin chain hashes. Currently enables all kinds of fun DoS attacks.
non_bitcoin_chain_hash_routing = []
fuzztarget = ["secp256k1/fuzztarget", "bitcoin/fuzztarget"]

[dependencies]
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin" }
bitcoin = "0.13"
rust-crypto = "0.2"
rand = "0.4"
secp256k1 = "0.9"

[build-dependencies]
gcc = "0.3"

[dev-dependencies.bitcoin]
version = "0.13"
features = ["bitcoinconsensus"]
10 changes: 10 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extern crate gcc;

fn main() {
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")))]
{
let mut cfg = gcc::Build::new();
cfg.file("src/util/rust_crypto_nonstd_arch.c");
cfg.compile("lib_rust_crypto_nonstd_arch.a");
}
}
9 changes: 8 additions & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "lightning-fuzz"
version = "0.0.1"
authors = ["Automatically generated"]
publish = false
# Because the function is unused it gets dropped before we link lightning, so
# we have to duplicate build.rs here. Note that this is only required for
# fuzztarget mode.
build = "../build.rs"

[package.metadata]
cargo-fuzz = true
Expand All @@ -13,12 +17,15 @@ honggfuzz_fuzz = ["honggfuzz"]

[dependencies]
lightning = { path = "..", features = ["fuzztarget"] }
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", features = ["fuzztarget"] }
bitcoin = { version = "0.13", features = ["fuzztarget"] }
secp256k1 = { version = "0.9", features = ["fuzztarget"] }
rust-crypto = "0.2"
honggfuzz = { version = "0.5", optional = true }
afl = { version = "0.3", optional = true }

[build-dependencies]
gcc = "0.3"

# Prevent this from interfering with workspaces
[workspace]
members = ["."]
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/channel_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bitcoin::util::hash::Sha256dHash;
use bitcoin::network::serialize::{serialize, BitcoinHash};

use lightning::ln::channel::Channel;
use lightning::ln::channelmanager::PendingForwardHTLCInfo;
use lightning::ln::channelmanager::{HTLCFailReason, PendingForwardHTLCInfo};
use lightning::ln::msgs;
use lightning::ln::msgs::MsgDecodable;
use lightning::chain::chaininterface::{FeeEstimator, ConfirmationTarget};
Expand Down Expand Up @@ -241,11 +241,11 @@ pub fn do_test(data: &[u8]) {
},
4 => {
let update_fail_htlc = decode_msg_with_len16!(msgs::UpdateFailHTLC, 32 + 8, 1);
return_err!(channel.update_fail_htlc(&update_fail_htlc));
return_err!(channel.update_fail_htlc(&update_fail_htlc, HTLCFailReason::dummy()));
},
5 => {
let update_fail_malformed_htlc = decode_msg!(msgs::UpdateFailMalformedHTLC, 32+8+32+2);
return_err!(channel.update_fail_malformed_htlc(&update_fail_malformed_htlc));
return_err!(channel.update_fail_malformed_htlc(&update_fail_malformed_htlc, HTLCFailReason::dummy()));
},
6 => {
let commitment_signed = decode_msg_with_len16!(msgs::CommitmentSigned, 32+64, 64);
Expand Down
1 change: 1 addition & 0 deletions fuzz/src/util/rust_crypto_nonstd_arch.c
6 changes: 3 additions & 3 deletions src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ pub struct HTLCOutputInCommitment {
}

#[inline]
pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey, offered: bool) -> Script {
pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script {
let payment_hash160 = {
let mut ripemd = Ripemd160::new();
ripemd.input(&htlc.payment_hash);
let mut res = [0; 20];
ripemd.result(&mut res);
res
};
if offered {
if htlc.offered {
Builder::new().push_opcode(opcodes::All::OP_DUP)
.push_opcode(opcodes::All::OP_HASH160)
.push_slice(&Hash160::from_data(&revocation_key.serialize())[..])
Expand Down Expand Up @@ -231,5 +231,5 @@ pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a
/// commitment secret. 'htlc' does *not* need to have its previous_output_index filled.
#[inline]
pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, keys: &TxCreationKeys) -> Script {
get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key, htlc.offered)
get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key)
}
Loading