Skip to content
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

Update strict_encoding requirement from =1.2.3 to =1.6.0 #2

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Static Analysis

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:

format:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run Rustfmt
run: cargo fmt -- --check

clippy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run Clippy
run: cargo clippy --workspace --all-targets
57 changes: 57 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:

rustdoc:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install Rust Nightly
uses: actions-rs/toolchain@v1.0.7
with:
toolchain: nightly
override: true
profile: minimal

- name: Build rust doc
run: cargo doc --all-features --no-deps
env:
RUSTDOCFLAGS: "--cfg docsrs"

build:

strategy:
matrix:
rust: [
stable,
nightly
]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install Rust ${{ matrix.rust }}
uses: actions-rs/toolchain@v1.0.7
with:
toolchain: ${{ matrix.rust }}
override: true
profile: minimal

- uses: Swatinem/rust-cache@v1.3.0

- name: Build
run: cargo build --verbose
41 changes: 1 addition & 40 deletions .github/workflows/ci.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Test

on:
push:
Expand All @@ -11,45 +11,6 @@ env:

jobs:

static_analysis:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run Rustfmt
run: cargo fmt -- --check

- name: Run Clippy
run: cargo clippy --workspace --all-targets

build:

strategy:
matrix:
rust: [
stable,
nightly
]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install Rust ${{ matrix.rust }}
uses: actions-rs/toolchain@v1.0.7
with:
toolchain: ${{ matrix.rust }}
override: true
profile: minimal

- uses: Swatinem/rust-cache@v1.3.0

- name: Build
run: cargo build --verbose

test:

strategy:
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) as described in [The Cargo Book](https://doc.rust-lang.org/cargo/reference/manifest.html#the-version-field).

## [Unreleased]
### Added
- Swap offers
- Swap roles and trade roles
- Basic transaction template for `Bitcoin<SegwitV0>`
- **experimental** ECDSA adaptor signatures (with `ecdsa_fun`)
- Messages exchanged between farcaster-node's microservices
- Tasks and blockchain events used by syncers
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ edition = "2018"
[features]
rpc = []
experimental = ["ecdsa_fun", "rand", "sha2", "rand_chacha", "bincode"]
serde = ["serde_crate", "bitcoin/use-serde", "monero/serde_support"]
serde = ["serde_crate", "bitcoin/use-serde", "monero/serde_support", "inet2_addr/serde"]

default = ["experimental"]

Expand All @@ -30,12 +30,12 @@ amplify = "3"
hex = "0.4.3"
tiny-keccak = { version = "2", features = ["keccak"] }
fixed-hash = { version = "0.7.0", default-features = false }
strict_encoding = "=1.2.3"
strict_encoding = "=1.6.0"
strict_encoding_derive = "=1.0.0"
lightning_encoding = "0.4.0-beta.1"
thiserror = "1.0.24"
serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true }
internet2 = { git = "https://github.com/zkao/rust-internet2", branch = "farcaster" }
inet2_addr = { version = "0.4.0", default-features = false, features = ["tor", "strict_encoding"] }

rand = { version = "0.8.4", optional = true }
ecdsa_fun = { version = "0.6", default-features = false, features = ["all"], optional = true }
Expand All @@ -51,7 +51,6 @@ monero = { version = "0.14" }
bitcoincore-rpc = "0.13.0"
rand_core = { version = "^0.6.3", features = ["getrandom"] }
secp256k1 = { version = "0.20.1", features = ["rand-std"] }
internet2 = { git = "https://github.com/zkao/rust-internet2", branch = "farcaster" }
lazy_static = "1.4.0"

[package.metadata.docs.rs]
Expand Down
41 changes: 26 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[![Build Status](https://img.shields.io/github/workflow/status/farcaster-project/farcaster-core/CI/main)](https://github.com/farcaster-project/farcaster-core/actions/workflows/ci.yml)
[![Build Status](https://img.shields.io/github/workflow/status/farcaster-project/farcaster-core/Build/main)](https://github.com/farcaster-project/farcaster-core/actions/workflows/build.yml)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance)
[![Crates.io](https://img.shields.io/crates/v/farcaster_core.svg)](https://crates.io/crates/farcaster_core)
[![Documentation](https://docs.rs/farcaster_core/badge.svg)](https://docs.rs/farcaster_core)
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
![MSRV](https://img.shields.io/badge/MSRV-1.54.0-blue)

# Farcaster Core Library
Farcaster atomic swaps project core library implementing in Rust:

:warning: **This library is a :construction: work in progress :construction: and does not implement everything yet, nor is suitable for production use.**

- [x] Farcaster swap offers
The Farcaster atomic swaps project core library aim to implement in Rust the following functionnalities needed to build a swap node:

- [x] Swap offers
- [x] Swap roles and trade roles
- [ ] Transactions templates to implement on-chain behaviours
- [ ] Transaction templates implementing on-chain behaviours (arbitration)
- [ ] Signature and cryptographic utilities
- [x] `experimental` ECDSA adaptor signatures (with `ecdsa_fun`)
- [ ] Cross-group discrete logarithm proof system
Expand All @@ -21,31 +21,37 @@ Farcaster atomic swaps project core library implementing in Rust:
- [x] Tasks and blockchain events used by syncers

## Core framework
This library is twofold: providing a flexible framework to add specific blockchain support and implementing these specific blockchain. The framework is accessible in all module at the root of the crate:
This library is twofold: providing a flexible framework to add specific blockchain support and implementing these specific blockchain. The framework is accessible in modules at the root of the crate:

- `blockchain`: generic types and constraint traits for on-chain behavior.
- `bundle`: generic types for inter-microservice communication, bonds to arbitrating and accordant traits.
- `bundle`: generic types for inter-microservice communication, bonded to arbitrating and accordant traits.
- `consensus`: encoding and decoding implementation for all types in the crate.
- `crypto`: traits and generic types to define cryptographic interactions (wallet capability, commit/reveal scheme, signature and key types, etc).
- `instruction`: generic types for inter-microservice communication.
- `instruction`: types for inter-microservice communication.
- `negotiation`: generic types and utilities for handling the negotiation phase.
- `protocol_message`: generic types exchanged between daemon running a swap toghether.
- `protocol_message`: generic types exchanged between daemons running a swap toghether.
- `role`: role definition (trade and swap) and implementation over the generic framework.
- `script`: generic types for transaction data management.
- `swap`: swap trait definition, utility types, and swap instance like Btc/Xmr.
- `syncer`: tasks, blockchain events, and errors used by syncers in the microservice architecture.
- `transaction`: transaction traits to implement for building and validating the arbitrating set of transaction.
- `transaction`: transaction traits for building and validating the arbitrating set of transaction.

The blockchain specific support is added under the the following modules:

- `bitcoin`: support for Bitcoin, implementation of all required traits from the framework, e.g. the `Arbitrating` trait in `role` module.
- `monero`: support for Monero, implementation of all required traits from the framework, e.g. the `Accordant` trait in `role` module.
- `swap/btcxmr`: definition of a swap between Bitcoin from `bitcoin` and Monero from `monero` implementations.
- `swap/btcxmr`: definition of a swap between `bitcoin` and `monero` modules.

### Features
As default the `experimental` feature is enable.

- **serde**: enable serde implementation on some of the types in the library.
- **experimental**: enable experimental cryptography, i.e. not battle tested nor peer reviewed and not intended for production use.

### Adding blockchain support
To add a blockchain implementation you must implements `Aribtrating` or `Accordant` trait on your blockchain definition, the trait implemented depends on its blockchain on-chain features, see [RFCs](https://github.com/farcaster-project/RFCs) for more details.

To add support for Bitcoin we implement the `Arbitrating` trait on our definition of `Bitcoin`. The implementation contains a strategy allowing variation in SegWit versions or with cryptographic protocols. An `experimental` feature include `SegwitV0` implementation with ECDSA and SegWit v0 experimental support.
To add support for Bitcoin we implement the `Arbitrating` trait on our definition of `Bitcoin`. The implementation contains a strategy allowing variations in SegWit versions or with cryptographic protocols. An `experimental` feature include `SegwitV0` implementation that supports ECDSA for SegWit v0.

```rust
#[derive(Clone, Debug, Copy, Eq, PartialEq)]
Expand All @@ -59,7 +65,7 @@ impl Strategy for SegwitV0 {}
impl Arbitrating for Bitcoin<SegwitV0> {}
```

The implementation is void but requires a list of traits such as (see `src/role.rs`):
The implementation of `Arbitrating` is void but requires a list of other traits (see `src/role.rs`):

```rust
pub trait Arbitrating:
Expand All @@ -77,7 +83,7 @@ pub trait Arbitrating:
}
```

By implementing all the required traits on Bitcoin we associate Bitcoin external concrete types used in the framework logic.
By implementing all the required traits on our Bitcoin definition we associate external concrete types used later in the framework logic.

```rust
impl<S: Strategy> blockchain::Asset for Bitcoin<S> {
Expand Down Expand Up @@ -139,6 +145,11 @@ impl blockchain::Transactions for Bitcoin<SegwitV0> {
}
```

# About
## Release Notes
See [CHANGELOG.md](CHANGELOG.md).

## About
This work is part of the Farcaster cross-chain atomic swap project, see [Farcaster Project](https://github.com/farcaster-project).

## Licensing
The code in this project is licensed under the [LGPL-3.0 License ](LICENSE)
10 changes: 5 additions & 5 deletions src/bitcoin/fee.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Transaction fee unit type and implementation. Defines the [`SatPerVByte`] unit used in methods
//! that set the fee and check the fee on transactions given a [`FeeStrategy`] and a
//! [`FeePolitic`].
//! [`FeePriority`].
//!
//! ```rust
//! use farcaster_core::bitcoin::fee::SatPerVByte;
Expand All @@ -22,7 +22,7 @@ use bitcoin::util::amount::Denomination;
use bitcoin::util::psbt::PartiallySignedTransaction;
use bitcoin::Amount;

use crate::blockchain::{Fee, FeePolitic, FeeStrategy, FeeStrategyError};
use crate::blockchain::{Fee, FeePriority, FeeStrategy, FeeStrategyError};
use crate::consensus::{self, CanonicalBytes};

use crate::bitcoin::{transaction, Bitcoin, Strategy};
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<S: Strategy> Fee for Bitcoin<S> {
fn set_fee(
tx: &mut PartiallySignedTransaction,
strategy: &FeeStrategy<SatPerVByte>,
politic: FeePolitic,
politic: FeePriority,
) -> Result<Amount, FeeStrategyError> {
if tx.global.unsigned_tx.output.len() != 1 {
return Err(FeeStrategyError::new(
Expand All @@ -143,8 +143,8 @@ impl<S: Strategy> Fee for Bitcoin<S> {
let fee_amount = match strategy {
FeeStrategy::Fixed(sat_per_vbyte) => sat_per_vbyte.as_native_unit().checked_mul(weight),
FeeStrategy::Range(range) => match politic {
FeePolitic::Aggressive => range.start.as_native_unit().checked_mul(weight),
FeePolitic::Conservative => range.end.as_native_unit().checked_mul(weight),
FeePriority::Low => range.start.as_native_unit().checked_mul(weight),
FeePriority::High => range.end.as_native_unit().checked_mul(weight),
},
}
.ok_or_else(|| FeeStrategyError::AmountOfFeeTooHigh)?;
Expand Down
Loading