-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rust/BNB]: Move BNB Beacon chain to Rust (#3589)
* [BNB]: Generate BNB Beacon chain skeleton files in Rust * [BNB]: Implement `BinanceAddress`, add Address tests * [BNB]: Add TBinance address tests * [BNB]: Add Transaction and its encoding, prehashing * Add Amino encoding * [BNB]: Sign a transaction * TODO Add tests, handle all message types * [BNB]: Add a signing test * [BNB]: Add `SendOrder`, `CancelOrder` * [BNB]: Add Token orders * [BNB]: Add `TokenBurnOrder`, `HTLTOrder` * [BNB]: Add `DepositHTLT` * [BNB]: Add `ClaimHTLTOrder`, `RefundHTLTOrder` * [BNB]: Add `TransferOutOrder` * [BNB]: Add `SideChainDelegate`, `SideChainRedelegate`, `SideChainUndelegate` orders * [BNB]: Add `TimeLock`, `TimeRelock`, `TimeUnlock` orders * [BNB]: Implement Transaction Compiler * [BNB]: Increase code coverage * [BNB]: Replace C++ implementation * [BNB]: Move TX preimage implementation to `JsonPreimager` * Remove C++ Signing tests * [BNB]: Extend `CoinEntry` documentation * [CI] Trigger CI * [BNB]: Remove `TransactionCompilerBuildInput` * [BNB]: Avoid duplicating code * [BNB]: Add fuzz tests
- Loading branch information
1 parent
f7bdfbe
commit 2a63cda
Showing
99 changed files
with
3,419 additions
and
1,643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "tw_binance" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
quick-protobuf = "0.8.1" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
serde_repr = "0.1" | ||
strum_macros = "0.25" | ||
tw_bech32_address = { path = "../../tw_bech32_address" } | ||
tw_coin_entry = { path = "../../tw_coin_entry" } | ||
tw_cosmos_sdk = { path = "../../tw_cosmos_sdk" } | ||
tw_encoding = { path = "../../tw_encoding" } | ||
tw_evm = { path = "../../tw_evm" } | ||
tw_hash = { path = "../../tw_hash" } | ||
tw_keypair = { path = "../../tw_keypair" } | ||
tw_memory = { path = "../../tw_memory" } | ||
tw_misc = { path = "../../tw_misc" } | ||
tw_proto = { path = "../../tw_proto" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "tw_binance-fuzz" | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = "0.4" | ||
tw_any_coin = { path = "../../../tw_any_coin", features = ["test-utils"] } | ||
tw_coin_registry = { path = "../../../tw_coin_registry" } | ||
tw_proto = { path = "../../../tw_proto", features = ["fuzz"] } | ||
|
||
[dependencies.tw_binance] | ||
path = ".." | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[profile.release] | ||
debug = 1 | ||
|
||
[[bin]] | ||
name = "sign" | ||
path = "fuzz_targets/sign.rs" | ||
test = false | ||
doc = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use tw_any_coin::test_utils::sign_utils::AnySignerHelper; | ||
use tw_coin_registry::coin_type::CoinType; | ||
use tw_proto::Binance::Proto; | ||
|
||
fuzz_target!(|input: Proto::SigningInput<'_>| { | ||
let mut signer = AnySignerHelper::<Proto::SigningOutput>::default(); | ||
let _ = signer.sign(CoinType::Binance, input); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright © 2017-2023 Trust Wallet. | ||
// | ||
// This file is part of Trust. The full Trust copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
|
||
use serde::Serialize; | ||
use std::fmt; | ||
use std::str::FromStr; | ||
use tw_bech32_address::bech32_prefix::Bech32Prefix; | ||
use tw_bech32_address::Bech32Address; | ||
use tw_coin_entry::coin_context::CoinContext; | ||
use tw_coin_entry::coin_entry::CoinAddress; | ||
use tw_coin_entry::error::{AddressError, AddressResult}; | ||
use tw_keypair::tw::PublicKey; | ||
use tw_memory::Data; | ||
|
||
/// The list of known BNB hrps. | ||
const BNB_KNOWN_HRPS: [&str; 2] = [ | ||
BinanceAddress::VALIDATOR_HRP, // BNB Validator HRP. | ||
"bca", | ||
]; | ||
|
||
#[derive(Serialize)] | ||
pub struct BinanceAddress(Bech32Address); | ||
|
||
impl CoinAddress for BinanceAddress { | ||
#[inline] | ||
fn data(&self) -> Data { | ||
self.0.data() | ||
} | ||
} | ||
|
||
impl BinanceAddress { | ||
pub const VALIDATOR_HRP: &'static str = "bva"; | ||
|
||
pub fn new_validator_addr(key_hash: Data) -> AddressResult<BinanceAddress> { | ||
Bech32Address::new(Self::VALIDATOR_HRP.to_string(), key_hash).map(BinanceAddress) | ||
} | ||
|
||
/// Creates a Binance address with the only `prefix` | ||
pub fn from_str_with_coin_and_prefix( | ||
coin: &dyn CoinContext, | ||
address_str: String, | ||
prefix: Option<Bech32Prefix>, | ||
) -> AddressResult<BinanceAddress> | ||
where | ||
Self: Sized, | ||
{ | ||
let possible_hrps = match prefix { | ||
Some(Bech32Prefix { hrp }) => vec![hrp], | ||
None => { | ||
let coin_hrp = coin.hrp().ok_or(AddressError::InvalidHrp)?; | ||
let other_hrps = BNB_KNOWN_HRPS | ||
.iter() | ||
.map(|another_hrp| another_hrp.to_string()); | ||
std::iter::once(coin_hrp).chain(other_hrps).collect() | ||
}, | ||
}; | ||
Bech32Address::from_str_checked(possible_hrps, address_str).map(BinanceAddress) | ||
} | ||
|
||
pub fn with_public_key_coin_context( | ||
coin: &dyn CoinContext, | ||
public_key: &PublicKey, | ||
prefix: Option<Bech32Prefix>, | ||
) -> AddressResult<BinanceAddress> { | ||
Bech32Address::with_public_key_coin_context(coin, public_key, prefix).map(BinanceAddress) | ||
} | ||
|
||
pub fn from_key_hash_with_coin( | ||
coin: &dyn CoinContext, | ||
key_hash: Data, | ||
) -> AddressResult<BinanceAddress> { | ||
Bech32Address::from_key_hash_with_coin(coin, key_hash).map(BinanceAddress) | ||
} | ||
} | ||
|
||
impl FromStr for BinanceAddress { | ||
type Err = AddressError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Bech32Address::from_str(s).map(BinanceAddress) | ||
} | ||
} | ||
|
||
impl fmt::Display for BinanceAddress { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
fmt::Display::fmt(&self.0, f) | ||
} | ||
} |
Oops, something went wrong.