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

Merge ozan/kickoff-root-operations into withdrawal #231

Merged
merged 8 commits into from
Aug 26, 2024

Conversation

ozankaymak
Copy link
Contributor

@ozankaymak ozankaymak commented Aug 22, 2024

Closes #225 and #219.

@ozankaymak ozankaymak changed the base branch from main to withdrawal August 22, 2024 14:03
@ozankaymak ozankaymak marked this pull request as draft August 22, 2024 14:04
@ozankaymak ozankaymak marked this pull request as ready for review August 23, 2024 13:22
};

let move_tx_simple =
TransactionBuilder::create_btc_tx(move_txins, vec![move_txout, anyone_can_spend_txout]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use create_move_tx here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

&[relative_timelock_script.clone()],
Some(*nofn_xonly_pk),
network,
);

let mut op_return_script: Vec<u8> = hex::decode(move_txid.to_string()).unwrap();
let op_return_idx: Vec<u8> = if operator_idx < 256 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write this better @lemonpartee ?
I just want to use less bytes here but i want this to work if there are more than 256 operators as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code snippet encodes variable n of type usize using least amount of bytes.

let usize_bytes = usize::BITS.div(8) as usize;
let bits = n.max(1).ilog2() + 1;
let len = bits.div_ceil(8) as usize;
let empty = usize_bytes - len;
let bytes = n.to_be_bytes();
let bytes = &bytes[empty..];

This code snippet would decode it.

let mut encoded = [0u8; 8];
encoded[empty..].copy_from_slice(bytes);
let decoded = usize::from_be_bytes(encoded);

TxHandler {
tx,
prevouts,
scripts,
taproot_spend_infos,
taproot_spend_infos: vec![],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add N-of-N and operator script here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -86,7 +95,7 @@ where
self.config.network,
)?;

let num_required_nonces = self.operator_xonly_pks.len() + 2;
let num_required_nonces = 3 * self.operator_xonly_pks.len() + 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use 2*n+1 here since we won't be generating burn txs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

async fn operator_kickoffs_generated(
&self,
deposit_outpoint: OutPoint,
kickoff_utxos: Vec<UTXO>,
operators_kickoff_sigs: Vec<secp256k1::schnorr::Signature>, // These are not transaction signatures, rather, they are to verify the operator's identity.
agg_nonces: Vec<MuSigAggNonce>,
) -> Result<Vec<MuSigPartialSignature>, BridgeError> {
agg_nonces: (Vec<MuSigAggNonce>, Vec<MuSigAggNonce>), // First vector is for the slash_or_take_txs, the second vector is for the burn_txs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take all aggNonces in here, so that bridge backend can instantly aggregate pubNonces and send them back and delete them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

&self.nofn_xonly_pk,
&self.config.operators_xonly_pks[i],
);
let (musig2_and_operator_address, _) = TransactionBuilder::create_taproot_address(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets have a create_kickoff_address function in transaction_builder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// .unwrap();
// let root_bytes: [u8; 32] = *root.as_byte_array();

self.db
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should save aggNonces first so that we can partialSign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

&self,
deposit_outpoint: OutPoint,
_burn_sigs: Vec<schnorr::Signature>,
_slash_or_take_sigs: Vec<schnorr::Signature>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also verify these slash_or_take_sigs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

This was linked to issues Aug 26, 2024
@ekrembal ekrembal merged commit 15e7f80 into withdrawal Aug 26, 2024
@ekrembal ekrembal deleted the ozan/kickoff-root-operations branch August 26, 2024 08:53
ozankaymak added a commit that referenced this pull request Aug 26, 2024
* WIP

* nits

* Add sig check for withdrawal (#229)

* Add sig check for withdrawal

* Use tx.verify

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>

* Impl operator paying withdrawal

* Merge ozan/withdrawal-endpoint-test into ekrem-new-architecture (#230)

* wip

* WIP: created operators and verifiers

* Add steps for the flow

* Add withdrawal endpoint test,organize configs

* Flaky but ok

* Fix flakiness

* Remove unnecessary serialization

---------

Co-authored-by: lemonpartee <lemonpartey@proton.me>
Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>

* Merge ozan/kickoff-root-operations into withdrawal (#231)

* WIP Implement endpoints with db operations and tests

* wip

* WIP

* WIP

* Implement changes

* Apply review changes

* Refactor the binaries

* Rename, refactor

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>
Co-authored-by: lemonpartee <lemonpartey@proton.me>
@@ -158,6 +158,12 @@ pub enum BridgeError {
KickoffOutpointsNotFound,
#[error("DepositInfoNotFound")]
DepositInfoNotFound,

#[error("FromHexError: {0}")]
FromHexError(hex::FromHexError),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to manually implement From if you use this syntax.

Suggested change
FromHexError(hex::FromHexError),
FromHexError(#[from] hex::FromHexError),

let verifier = Verifier::new(rpc, config).await?;

let addr = match server.local_addr() {
let addr: std::net::SocketAddr = match server.local_addr() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let addr: std::net::SocketAddr = match server.local_addr() {
let addr: std::net::SocketAddr = server.local_addr().map_err(|e| BridgeError::ServerError(e)|)?;

Copy link
Contributor

@lemonpartee lemonpartee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple nits

ekrembal added a commit that referenced this pull request Aug 29, 2024
* Set rpc endpoints and impl operator new deposit

* Impl verifier new_deposit

* Impl operator_kickoffs_generated

* impl more verifier functions

* Merge MuSig2 functions into ekrem/new-architecture (#206)

* Add some musig2 functionalities

* Some changes in general and in MuSig2

* Change musig2 functions

* Add one small test

* Added three more simple tests

* Add test with dummy_tx key_spend

* Add test with dummy_tx script_spend

* Add rpc tests for key_spend and script_spend

* Add wrappers for aggregate_nonces and aggregate_partial_signatures, formatting

* Cargo fmt

* Small change for config file

* Some refactor

* (WIP) Change XOnlyPublicKeys to PublicKeys in config files

* Fix errors from pk-xonlypk change

* More refactor

* Remove code duplication

* More refactor

* Commentation + more refactor

* Trying something

* Removed Cargo.lock + add to .gitignore

* Create XOnlyPublicKeys from PublicKeys using an extension trait (#216)

Reduces code duplication and isolates the reponsibility to a dedicated function

* Finalize new architecture for deposit except db operations (#211)

* WIP

* Fix some errors

* WIP

* Merge ozan/new-architecture-improvments into ekrem/new-architecture-improvments (#218)

* WIP Impl. new endpoints

* WIP Impl. new endpoints

* nits

* Implement move txs partial sig

* WIP db nonce

* Use UTXO instead of PsbtOutpoint

* remove redundant db funcs

---------

Co-authored-by: ozankaymak <92448699+ozankaymak@users.noreply.github.com>

* Update DB for New Architecture (#222)

* Change the db file for the new architecture

* Change some UTXOs to OutPoints, add some checks

* WIP Fix inconsistencies

* WIP Impl database wrappers

* Update schema

* Fix some db

* WIP

* nits

* Fix error for a wrapper, add some example db trait impl. and db func.

* nits

* WIP Impl. database functions

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>

* Merge DB changes to ekrem/new-architecture (#227)

* Update config files and impl. some db tests

* WIP Fix checks and tests

* (WIP) Add test for nonce table, fix small errors

* (WIP) Add more tests for nonces table

* (WIP) Add tests for get_pub_nonce

* (WIP) Add test for deposit_utxo

* Change operator new_deposit with new schema

* WIP

* DecodeRow inside the function

* Current tests work

* WIP

* Fix Json issue with UTXODB

* Clean wrapper.rs and formatting

* Add tests for deposit_kickoff_generator_txs table

* Apply review

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>

* Remove code duplication (#228)

* Merge withdrawal into ekrem/new-architecture (#234)

* WIP

* nits

* Add sig check for withdrawal (#229)

* Add sig check for withdrawal

* Use tx.verify

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>

* Impl operator paying withdrawal

* Merge ozan/withdrawal-endpoint-test into ekrem-new-architecture (#230)

* wip

* WIP: created operators and verifiers

* Add steps for the flow

* Add withdrawal endpoint test,organize configs

* Flaky but ok

* Fix flakiness

* Remove unnecessary serialization

---------

Co-authored-by: lemonpartee <lemonpartey@proton.me>
Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>

* Merge ozan/kickoff-root-operations into withdrawal (#231)

* WIP Implement endpoints with db operations and tests

* wip

* WIP

* WIP

* Implement changes

* Apply review changes

* Refactor the binaries

* Rename, refactor

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>
Co-authored-by: lemonpartee <lemonpartey@proton.me>

* Implement sig_agg helpers (#237)

Co-authored-by: ozankaymak <ozan.kaymak@boun.edu.tr>

* Deposit test (#232)

* wip

* WIP: created operators and verifiers

* Add steps for the flow

* wip

* Test e2e deposit flow

* Undo unrelated changes

* Fix agg nonces and use same deposit

* Adjust test flow after rebase to withdrawal

* Use create verifiers and operators func

* Works until set_operator_funding_utxo_rpc

* Fix create operators and verifiers

* Fix sig aggregation

* nits

* WIP

* WIP MuSig2VerifyError(BadSignature)

* Debug

* Fix error

* Send move_tx + refactor

---------

Co-authored-by: Ekrem BAL <mail.ekrembal@gmail.com>
Co-authored-by: ozankaymak <ozan.kaymak@boun.edu.tr>

* Apply review + refactor (#243)

* Remove unused dependencies (#238)

* Remove unused utils (#239)

* Add docker compose with database (#245)

* Introduce dockerized PostgresSQL database compatible with integration tests

* refactor compose

* Full withdrawal flow (#253)

* Save operator take and slash or take sigs

* Operator can find kickoff utxo

* Operator can send kickoff tx onchain

* WIP verifiers and operators should use same db missing

* Fix bugs

* WIP Boths sigs verified but operator_take_tx fails

* WIP MuSig2 fix

* Fix withdrawal happy part test

* nits

* Fix musig test

* Use key aggregator trait

---------

Co-authored-by: ozankaymak <ozan.kaymak@boun.edu.tr>

* get rid of basic workflow

* Workflow improvements (#251) (#255)

* workflow: Add all-targets flag to clippy.

* workflow: Add the new build_and_test workflow.

* workflow: Remove all features and move services.

* workflow: Remove old basic workflow.

* workflow: Add cache warm ups for build and test.

* workflow: Add all features flag to build and test.

* workflow: Lower healt-retries to 5.

Co-authored-by: Ceyhun Şen <ceyhuusen@gmail.com>

* workflow: remove all features.

* Merge "clippy" into "ekrem/new-architecture"

* Fix CI config toml

* Change CI config + remove warnings

* Apply clippy suggestions for all

* nits

* Fix duplication

* Fix CI error

* Apply more clippy suggestions (#256)

* cargo: Update mock_rpc.

* workflow: Re-add --all-features.

* workflow: Upgrade 4 cores to 16 cores.

* perf: Insert nonces in a single batch (#248)

* Cargo upgrade

* minimize op_return usage

* fmt

---------

Co-authored-by: ozankaymak <92448699+ozankaymak@users.noreply.github.com>
Co-authored-by: lemonpartee <lemonpartey@proton.me>
Co-authored-by: ozankaymak <ozan.kaymak@boun.edu.tr>
Co-authored-by: Ceyhun Şen <ceyhuusen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix operator related binaries Change config.toml files
3 participants