Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
807aaae
new structure: moved default files
BowTiedDeployer Sep 9, 2023
cac9414
new structure: added stacks-blockchain repo locally
BowTiedDeployer Sep 9, 2023
3572a0e
new structure: add stacks blockchain files locally
BowTiedDeployer Sep 9, 2023
c03bc27
new structure: added clarity smart contracts
BowTiedDeployer Sep 9, 2023
bf61f26
update: updated our code on the last tm code
BowTiedDeployer Sep 9, 2023
597bb97
add: returned script's merkle root from signer to coordinator
Web3RustDev Sep 18, 2023
6616f19
update: removed merkle_root parsed to a fn that doesn't have it as pa…
Web3RustDev Sep 18, 2023
776403d
update: switched on testnet stacks node, tested signer joining flow o…
Web3RustDev Sep 19, 2023
c5cc8e3
add: test whole sc flow
Web3RustDev Sep 19, 2023
f2b773c
add: query mempool for transactions - in progress, function to get po…
Web3RustDev Sep 21, 2023
8048f8d
add: stacks flow - voting out signers with bad stacks addresses/bad u…
Web3RustDev Sep 25, 2023
93d5b8d
add: coordinator also voting positive for removal after broadcast
Web3RustDev Sep 27, 2023
b75515b
add: thread for autoexchange - in progress, get call for user balance
Web3RustDev Oct 5, 2023
b30fe58
add: unfinished - request to signers to refund their funds for block …
Web3RustDev Oct 6, 2023
11468d0
add: request/response from signers to sign the transaction from scrip…
Web3RustDev Oct 8, 2023
b62ee3c
fix: vote positive removal request by signers is now done after with …
Web3RustDev Oct 9, 2023
faa623e
add: signer chooses amount to script in his config, automatically acc…
Web3RustDev Oct 10, 2023
5bcdd5b
add: refund for script if there's not enough money to send to coordin…
Web3RustDev Oct 10, 2023
183314a
add: verification if user's amount to pox in config is enough for at …
Web3RustDev Oct 10, 2023
ad8de28
update: removed script refund path / request because it is unused
Web3RustDev Oct 10, 2023
fe330d6
add: signers check the transaction's outputs for correct pox addresse…
Web3RustDev Oct 10, 2023
90bb709
update: in coordinator 2 transactions are made quickly, so we keep a …
Web3RustDev Oct 10, 2023
1dadbbb
add: local log in case the coordinator sends a bad transaction to the…
Web3RustDev Oct 11, 2023
56d7a95
update: changed fee name to user_to_script_fee, fixed checking if utx…
Web3RustDev Oct 11, 2023
bb88fe3
add: signers check if the voted out signer is still in miners list be…
Web3RustDev Oct 11, 2023
18d6327
update: also added error handling for config file
Web3RustDev Oct 11, 2023
bed4e70
add: signers verify the pox transaction's inputs and outputs to be th…
Web3RustDev Oct 17, 2023
8aebd49
update: changed location where user's status is gotten to be behind t…
Web3RustDev Oct 17, 2023
4606690
update: removed hardcoded network
Web3RustDev Oct 23, 2023
a89aa24
add: verifying already anchored transactions, node call to return out…
Web3RustDev Oct 24, 2023
3271898
update: fees for transactions to pox and script are now parsed from c…
Web3RustDev Oct 25, 2023
20333d7
add: user can now choose in config to fund the script at each block o…
Web3RustDev Nov 12, 2023
6ae36a4
update: removed unnecessary if statement, renamed array for clarifica…
Web3RustDev Nov 12, 2023
ccf7eba
update: commented the part that warns/proposes for removal bad actors
Web3RustDev Dec 5, 2023
2b425bd
fix: removed '=' from '>=' that causes the code to reach out of bound…
Web3RustDev Dec 5, 2023
4ab6c52
update: changed 'blockstack_lib' dependency to 'stackslib' and path f…
Jan 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
run: deno cache ./yarpc/js/stacks/transactions.ts
- run: cargo install cargo-tarpaulin
# - run: cargo tarpaulin
- run: cargo tarpaulin --verbose --all-features --workspace --timeout 120 --out Xml --avoid-cfg-tarpaulin
- run: cargo tarpaulin --verbose --all-features --workspace --timeout 120 --out xml --avoid-cfg-tarpaulin
- uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Cargo.lock
cobertura.xml
tarpaulin-report.html
*~
.DS_Store
.idea
22 changes: 9 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
[workspace]
members = [
"relay-server",
"frost-test",
"frost-signer",
"frost-coordinator",
"sbtc-cli",
"stacks-coordinator",
"stacks-signer",
"stacks-signer-api",
"stacks-doctor",
"test-utils",
"test-vectors",
"yarpc"]
"degen-base-signer",
"degen-base-coordinator",
"degen-superior-coordinator",
"degen-superior-signer",
"yarpc",
"test-utils"
]

[workspace.dependencies]
anyhow = "1.0"
array-bytes = "6.1.0"
bdk = "0.28.0"
bs58 = "0.5"
bitcoin = { version = "0.29.2", features = ["rand", "bitcoinconsensus"] }
blockstack-core = { git = "https://github.com/stacks-network/stacks-blockchain/", branch = "next" }
stackslib = { git = "https://github.com/stacks-network/stacks-core/", branch = "next" }
clap = { version = "4.1.1", features = ["derive", "env"] }
hex = "0.4.3"
p256k1 = "5.4.1"
wsts = "2.0"
wsts = "3.0"
rusqlite = "0.24.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
Expand Down
53 changes: 53 additions & 0 deletions Flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
M3 flow:

When a signer runs his code:
The signer makes his config, creating nodes, wallets, addresses, keys, fees etc.
An infinite loop is made until the smart contract read-only call returns that the signer is a miner in pool (hence preventing him to run the signer code).
We then check if the amount to send to the script that he chose in config is enough to cover at least 1 transaction.
- If the check fails, the code panics and informs him to choose a higher amount.
Then we spawn a separate thread in order to continuously run some commands (auto-exchange, accept non-blacklisted users in pool) - every 5 minutes.
The thread doesn't block the signer at all, so he continues to receive requests and send responses to coordinator.

Coordinator:
Stacks Coordinator -> Requests data about signers from Frost Coordinator
Frost Coordinator -> Requests data about signers from signers

Signers:
Frost Signer -> Creates refund and unspendable scripts which are used in order to create a script address and taproot spend info
Frost Signer -> Checks the amount required to send to pox for the current block
Frost Signer -> Calls listunspent command on his script address to retreive the UTXOs
Frost Signer -> Checks if the amount on his script is enough to cover the transaction
- if he has enough money, he then proceeds to create a response containing his script UTXO along with his stacks address
- if he doesn't, then:
- he runs a refund phase on his script, returning the money to him
- he then tries to send money to the script, then creating a response - the utxo field is a result containing either a valid utxo, or an error
Frost Signer -> Constructs a response and sends it to Frost Coordinator

Coordinator:
Frost Coordinator -> Awaits the response from all signers, checking if it is the correct type, and puts the data in a vector
Frost Coordinator -> Returns the signer's data to Stacks Coordinator
Stacks Coordinator -> Checks if the UTXO is valid and not an error, the amount on the utxo is correct, and that the returned stacks addresses are correct
- if there is a bad actor, the transaction is canceled, notifying the signers that there is a bad actor
- if not, the transaction is created, signed and broadcasted

Bad actor case:
Stacks Coordinator -> Checks every address from bad actors:
- warns it if it has less than 2 warnings
- proposes it for removal and votes positive for removal if it has 2 warnings, adding it to a list of users to be voted out of pool
Stacks Coordinator -> Sends the list of users to be voted out of pool to Frost Coordinator
Frost Coordinator -> Sends a request to signers to vote out all users from the list
Frost Signer -> Creates a separate thread, checking for each user:
- if the user is still in mining pool means he was't yet voted out
- if the user is proposed for removal (in order to vote only after the propose for removal call is made)
- if the above conditions are true, the user makes a call to vote positive for removal, no longer checking the voted address

No bad actor case:
Stacks Coordinator -> Creates the transaction containing signer's UTXOs as inputs, and the 2 PoX addresses + the rest of money back to each script as outputs
Stacks Coordinator -> Sends a request to Frost Coordinator for signed transaction
Frost Coordinator -> Iterates through each input, sending a request to signers to sign it, including the transaction in the request
Frost Signer -> Checks if the outputs contain the 2 PoX addresses and the correct amount sent to them
Frost Signer -> Each signer checks if his UTXO is contained in inputs, and if the script address is included in the outputs and has the correct amount back
Frost Signer -> If any of the checks above fail, they don't sign the transaction and write a malicious coordinator log to a local file
Frost Signer -> If the checks succeed, they sign the inputs and return them to Frost Coordinator
Frost Coordinator -> Returns the signed transaction to Stacks Coordinator
Stacks Coordinator -> Broadcasts the transaction
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Documentation: https://trust-machines.github.io/stacks-sbtc
## Projects

- [relay-server](./relay-server/) is a simple HTTP relay server.
- [stacks-signer-api](./stacks-signer-api) is an API server for interacting with a Stacks signer binary.
- [stacks-signer-api](utils/stacks-signer-api) is an API server for interacting with a Stacks signer binary.

## Prerequisites

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "frost-coordinator"
name = "degen-base-coordinator"
version = "0.0.1"
license = "GPLv3"
homepage = "https://github.com/Trust-Machines/core-eng"
Expand All @@ -10,15 +10,18 @@ edition = "2021"

[dependencies]
p256k1 = { workspace = true }
stackslib = { workspace = true }
wsts = { workspace = true }
backoff = { workspace = true }
clap = { workspace = true }
hashbrown = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
frost-signer = { path = "../frost-signer" }
degen-base-signer = { path = "../degen-base-signer" }
serde = { version = "1.0", features = ["serde_derive"] }
bitcoin.workspace = true
url = { workspace = true }

[dev-dependencies]
rand_core = { workspace = true }
Expand All @@ -31,5 +34,5 @@ path = "src/lib.rs" # The source file of the target
crate-type = ["lib"] # The crate types to generate

[[bin]]
name = "frost-coordinator"
name = "degen-base-coordinator"
path = "src/main.rs"
File renamed without changes.
Loading