forked from comit-network/xmr-btc-swap
-
Notifications
You must be signed in to change notification settings - Fork 79
feat: Hermes #855
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
Draft
binarybaron
wants to merge
11
commits into
master
Choose a base branch
from
feat/hermes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: Hermes #855
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2346362
Add first draft for Hermes protocol
binarybaron 969ccbe
feat(monero-wallet-ng): complete Hermes codec and add regtest happy-p…
3fb9c9c
feat(swap): transmit encrypted signature on-chain via Hermes
09315dd
feat(swap): detect Hermes funding during lock-tx verification and gat…
30e71b0
feat(monero-wallet-ng): received_amount reports largest output
4b946bc
test(swap): happy path succeeds with Hermes disabled
ccf7479
refactor(swap): make construct_hermes_tx infallible
e279796
split up states
f50ff5d
add HermesTxConfirmed state
cfd7055
progress
6ea8e9f
refactor(swap): collapse Hermes delivery states into EncSigReadyToBeSent
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,121 @@ | ||
| use std::time::Duration; | ||
|
|
||
| use anyhow::Context; | ||
| use curve25519_dalek::constants::ED25519_BASEPOINT_TABLE; | ||
| use monero_harness::{Cli, Monero}; | ||
| use monero_oxide_wallet::{ | ||
| OutputWithDecoys, Scanner, ViewPair, | ||
| address::Network, | ||
| ed25519::{Point, Scalar}, | ||
| interface::prelude::*, | ||
| ringct::RctType, | ||
| send::{Change, SignableTransaction}, | ||
| }; | ||
| use monero_wallet_ng::hermes::HermesMessage; | ||
| use rand::RngCore; | ||
| use rand::rngs::OsRng; | ||
| use zeroize::Zeroizing; | ||
|
|
||
| const HERMES_TEST_MESSAGE: &[u8] = b"hermes happy path message from bob to alice"; | ||
|
|
||
| fn keypair() -> (Zeroizing<Scalar>, Point) { | ||
| let secret = Zeroizing::new(Scalar::random(&mut OsRng)); | ||
| let public = Point::from(&(*secret).into() * ED25519_BASEPOINT_TABLE); | ||
|
|
||
| (secret, public) | ||
| } | ||
|
|
||
| /// Bob sends a Hermes message to the shared wallet, Alice discovers and decrypts it | ||
| /// by scanning the chain with the shared wallet's view key. | ||
| #[tokio::test] | ||
| async fn hermes_happy_path() -> anyhow::Result<()> { | ||
| tracing_subscriber::fmt() | ||
| .with_env_filter("info,monero_harness=debug,monero_wallet_ng=trace") | ||
| .init(); | ||
|
|
||
| let cli = Cli::default(); | ||
| let (monero, _monerod_container, _wallet_containers) = Monero::new(&cli, vec![]).await?; | ||
| let daemon = monero.monerod().client().clone(); | ||
|
|
||
| let (bob_spend, bob_spend_pub) = keypair(); | ||
| let (bob_view, _) = keypair(); | ||
| let bob_view_pair = ViewPair::new(bob_spend_pub, bob_view)?; | ||
| let bob_address = bob_view_pair.legacy_address(Network::Mainnet); | ||
|
|
||
| // Fund Bob and provide enough on-chain outputs for decoy selection. | ||
| // The funding coinbase output unlocks after 60 confirmations. | ||
| let funding_height = daemon.latest_block_number().await? + 1; | ||
| daemon.generate_blocks(&bob_address, 110).await?; | ||
|
|
||
| let funding_block = daemon.block_by_number(funding_height).await?; | ||
| let funding_output = Scanner::new(bob_view_pair.clone()) | ||
| .scan(daemon.expand_to_scannable_block(funding_block).await?)? | ||
| .ignore_additional_timelock() | ||
| .swap_remove(0); | ||
|
|
||
| // The shared wallet of which both parties know the private view key | ||
| let (_shared_spend, shared_spend_pub) = keypair(); | ||
| let (shared_view, _) = keypair(); | ||
| let shared_view_pair = ViewPair::new(shared_spend_pub, shared_view.clone())?; | ||
| let shared_address = shared_view_pair.legacy_address(Network::Mainnet); | ||
|
|
||
| let message = HermesMessage::new(HERMES_TEST_MESSAGE.to_vec())?; | ||
| let arbitrary_data = message.to_arbitrary_data(shared_view.clone(), &mut OsRng); | ||
|
|
||
| let hardfork_version = daemon | ||
| .block_by_number(daemon.latest_block_number().await?) | ||
| .await? | ||
| .header | ||
| .hardfork_version; | ||
| anyhow::ensure!( | ||
| matches!(hardfork_version, 15 | 16), | ||
| "Unexpected hardfork version {hardfork_version}" | ||
| ); | ||
|
|
||
| let input = OutputWithDecoys::fingerprintable_deterministic_new( | ||
| &mut OsRng, | ||
| &daemon, | ||
| 16, | ||
| daemon.latest_block_number().await?, | ||
| funding_output, | ||
| ) | ||
| .await?; | ||
|
|
||
| let mut outgoing_view_key = Zeroizing::new([0u8; 32]); | ||
| OsRng.fill_bytes(outgoing_view_key.as_mut()); | ||
|
|
||
| let transaction = SignableTransaction::new( | ||
| RctType::ClsagBulletproofPlus, | ||
| outgoing_view_key, | ||
| vec![input], | ||
| vec![(shared_address, 1_000_000_000)], | ||
| Change::new(bob_view_pair, None), | ||
| arbitrary_data, | ||
| daemon.fee_rate(FeePriority::Unimportant, u64::MAX).await?, | ||
| )? | ||
| .sign(&mut OsRng, &bob_spend)?; | ||
|
|
||
| let scan_start_height = daemon.latest_block_number().await?; | ||
| daemon.publish_transaction(&transaction).await?; | ||
| daemon.generate_blocks(&bob_address, 1).await?; | ||
|
|
||
| let mut subscription = monero_wallet_ng::scanner::naive_scanner( | ||
| daemon.clone(), | ||
| shared_spend_pub, | ||
| shared_view.clone(), | ||
| scan_start_height, | ||
| Duration::from_millis(250), | ||
| )?; | ||
|
|
||
| let output = tokio::time::timeout( | ||
| Duration::from_secs(60), | ||
| subscription.wait_until(|output| output.transaction() == transaction.hash()), | ||
| ) | ||
| .await | ||
| .context("Timed out waiting for the Hermes output")??; | ||
|
|
||
| let received = HermesMessage::from_wallet_output(&output, shared_view)?; | ||
| assert_eq!(received.as_bytes(), HERMES_TEST_MESSAGE); | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is totally not required at all, we dont need to check the hardfork version