diff --git a/.gitignore b/.gitignore index 0e82613dfd..f26121387e 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ client/cmd/translationsreport/translationsreport client/cmd/translationsreport/worksheets server/cmd/dexadm/dexadm server/cmd/geogame/geogame +internal/libsecp256k1/secp256k1 +internal/cmd/xmrswap/xmrswap diff --git a/client/cmd/bisonw-desktop/go.mod b/client/cmd/bisonw-desktop/go.mod index e3310d95b6..2f2ea0e8d3 100644 --- a/client/cmd/bisonw-desktop/go.mod +++ b/client/cmd/bisonw-desktop/go.mod @@ -1,6 +1,6 @@ module decred.org/dcrdex/client/cmd/bisonw-desktop -go 1.21 +go 1.21.10 replace decred.org/dcrdex => ../../.. @@ -92,7 +92,7 @@ require ( github.com/decred/dcrd/database/v3 v3.0.2 // indirect github.com/decred/dcrd/dcrec v1.0.1 // indirect github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.1-0.20240912225101-7333f805850b // indirect github.com/decred/dcrd/dcrjson/v4 v4.1.0 // indirect github.com/decred/dcrd/dcrutil/v4 v4.0.2 // indirect github.com/decred/dcrd/gcs/v4 v4.1.0 // indirect diff --git a/client/cmd/bisonw-desktop/go.sum b/client/cmd/bisonw-desktop/go.sum index 0fd6112ca3..b978b5ab83 100644 --- a/client/cmd/bisonw-desktop/go.sum +++ b/client/cmd/bisonw-desktop/go.sum @@ -293,8 +293,8 @@ github.com/decred/dcrd/dcrec v1.0.1/go.mod h1:CO+EJd8eHFb8WHa84C7ZBkXsNUIywaTHb+ github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 h1:l/lhv2aJCUignzls81+wvga0TFlyoZx8QxRMQgXpZik= github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3/go.mod h1:AKpV6+wZ2MfPRJnTbQ6NPgWrKzbe9RCIlCF/FKzMtM8= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.1-0.20240912225101-7333f805850b h1:HIjTBv19sQRjUiifEKPy6BLFKkOtV44uCnDThmYQ37s= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.1-0.20240912225101-7333f805850b/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/decred/dcrd/dcrjson/v4 v4.1.0 h1:WJVogRnYnNxB5hWoGHODvP4fNTG1JycTuHHKt/XucHk= github.com/decred/dcrd/dcrjson/v4 v4.1.0/go.mod h1:2qVikafVF9/X3PngQVmqkbUbyAl32uik0k/kydgtqMc= github.com/decred/dcrd/dcrutil/v4 v4.0.2 h1:eIl3E6gGln54qE8nk5o5lLtjh2/9C2Rz63OpD662h+8= diff --git a/dex/testing/loadbot/go.mod b/dex/testing/loadbot/go.mod index 9a42a71111..8b656096ff 100644 --- a/dex/testing/loadbot/go.mod +++ b/dex/testing/loadbot/go.mod @@ -74,7 +74,7 @@ require ( github.com/decred/dcrd/database/v3 v3.0.2 // indirect github.com/decred/dcrd/dcrec v1.0.1 // indirect github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.1-0.20240912225101-7333f805850b // indirect github.com/decred/dcrd/dcrjson/v4 v4.1.0 // indirect github.com/decred/dcrd/dcrutil/v4 v4.0.2 // indirect github.com/decred/dcrd/gcs/v4 v4.1.0 // indirect diff --git a/dex/testing/loadbot/go.sum b/dex/testing/loadbot/go.sum index bc1b87e569..98db339237 100644 --- a/dex/testing/loadbot/go.sum +++ b/dex/testing/loadbot/go.sum @@ -289,8 +289,8 @@ github.com/decred/dcrd/dcrec v1.0.1/go.mod h1:CO+EJd8eHFb8WHa84C7ZBkXsNUIywaTHb+ github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 h1:l/lhv2aJCUignzls81+wvga0TFlyoZx8QxRMQgXpZik= github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3/go.mod h1:AKpV6+wZ2MfPRJnTbQ6NPgWrKzbe9RCIlCF/FKzMtM8= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.1-0.20240912225101-7333f805850b h1:HIjTBv19sQRjUiifEKPy6BLFKkOtV44uCnDThmYQ37s= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.1-0.20240912225101-7333f805850b/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/decred/dcrd/dcrjson/v4 v4.1.0 h1:WJVogRnYnNxB5hWoGHODvP4fNTG1JycTuHHKt/XucHk= github.com/decred/dcrd/dcrjson/v4 v4.1.0/go.mod h1:2qVikafVF9/X3PngQVmqkbUbyAl32uik0k/kydgtqMc= github.com/decred/dcrd/dcrutil/v4 v4.0.2 h1:eIl3E6gGln54qE8nk5o5lLtjh2/9C2Rz63OpD662h+8= diff --git a/dex/testing/xmr/README.md b/dex/testing/xmr/README.md new file mode 100644 index 0000000000..30df8ab7cd --- /dev/null +++ b/dex/testing/xmr/README.md @@ -0,0 +1,244 @@ +# Monero Development Harness + +Monero development Harness - documentation and notes + +## Useful Info + +Monero is very different than btc in that it does not provide a single rpc +tool like `bitcoin-cli` but rather a set of json 2.0 & other older json apis +which can be accessed by sending curl requests for each one. + +Monero wallets are accounts based + + + +## Architecture + +![alt text](image-1.png) + +Embedded in Tmux + +- **alpha** is a monero p2p daemon + +- **bill** is a miner wallet .. you can top up more funds from bill if you run out + +- **fred** is a normal wallet user + +- **charlie** is a normal wallet user + +- **charlie_view** is a view-only wallet sibling of charlie full wallet - no spend key + +## Using + +### Prerequisites + +- **monero-x86_64-linux-gnu-v0.18.3.3** or later +- **linux** (tested on Ubuntu 22.04) +- **jq** (1.6) + +### Setup + +**monero-x86_64-linux-gnu-v0.18.3.3** should be in PATH + +`export PATH=$PATH:[path-to]/monero-x86_64-linux-gnu-v0.18.3.3` + +### Background Mining + +By default background mining is set up and mines to bill wallet every 15s + +To disable: + +`export NOMINER="1" to your shell` + + or else invoke the harness with: + +`NOMINER="1" ./harness.sh` + +You should disable if attempting the manual offline cold signing using `monero-wallet-cli` + +You should also ctl-C charlie & charlie_view wallets for this + +### Run + +`./harness.sh` + +### Data Directory + +![alt text](image-2.png) + +### Known Issues + +The transaction spend locking needs more investigation + +### Commands Help + +run `./help` from the tmux harness window 0 + +```text + +Commands Help: +-------------- +alpha_get_transactions + +- get transactions info for one or more txid +- inputs: + - tx_hashes - hash1,hash2,hash3,... + +alpha_get_transactions_details + +- get transaction development details from monerod including tx lock time +- inputs: + - tx_hashes - hash1,hash2,hash3,... + +alpha_info + +- get running daemon details - height, etc. +- inputs: None + +alpha_sendrawtransaction + +- broadcast a previously built signed tx +- inputs: + - tx_as_hex string - can be generated with charlie_build_tx or fred_build_tx + +alpha_transaction_pool + +- get mempool details +- inputs: None + +mine-to-bill + +- generate 1 or more blocks to bill wallet +- inputs: + - num_blocks - defaults to 1 + +bill_balance + +- get bill wallet balance details +- inputs: None + +bill_refresh_wallet + +- update bill's wallet from the daemon latest info +- inputs: None + +bill_transfer_to + +- build, sign and broadcast a transaction from bill wallet to another address +- inputs: + - amount in in atomic units 1e12 - e.g. 1230000000000 echo = 1.23 XMR + - address - recipient primary address - account index 0, subaddr_indeces [0] + - unlock_time - unlock after n blocks and make spendable - defaults to 0 (no lock) + +charlie_balance + +- get charlie wallet balance details +- inputs: None + +charlie_refresh_wallet + +- update charlie's wallet from the daemon latest info +- inputs: None + +charlie_build_tx + +- build a signed tx for later broadcasting using alpha_send +- inputs: + - amount in in atomic units 1e12 - e.g. 1230000000000 = 1.23 XMR + - address - recipient primary address - account index 0, subaddr_indeces [0] + - unlock_time - unlock after n blocks and make spendable - defaults to 0 (no lock) +-outputs: + - signed tx_blob + - tx_hash + +charlie_incoming_transfers + +- get a list of incoming mined transfers to charlie wallet +- inputs: None + +charlie_transfer_to + +- build, sign and broadcast a transaction from charlie wallet to another address +- inputs + - amount in in atomic units 1e12 - e.g. 1230000000000 echo = 1.23 XMR + - address - recipient primary address - account index 0, subaddr_indeces [0] + - unlock_time - unlock after n blocks and make spendable - defaults to 0 (no lock) + +fred_export_outputs + +- export fred outputs hex +- input: + - all - defaults to true - otherwise only new outputs since the last call + +charlie_export_outputs + +- export charlie outputs hex +- input: + - all - defaults to true - otherwise only new outputs since the last call + +charlie_view_export_outputs + +- export charlie_view outputs hex - charlie_view knows the outputs but has no spend key +- inputs: None +- only useful in offline, cold signing process using monero-wallet-cli interactive tool + must be hex decoded into a file to use in monero-wallet-cli + +fred_export_key_images + +- export signed key images from fred wallet - an array of key images and ephemeral signatures +- input: + - all - defaults to true - otherwise only new key images since the last call + +charlie_export_key_images + +- export signed key images from charlie wallet - an array of key images and ephemeral signatures +- input: + - all - defaults to true - otherwise only new key images since the last call + +fred_balance + +- get fred wallet balance details +- inputs: None + +fred_refresh_wallet + +- update fred's wallet from the daemon latest info +- inputs: None + +fred_build_tx + +- build a signed tx for later broadcasting using alpha_send +- inputs: + - amount in in atomic units 1e12 - e.g. 1230000000000 = 1.23 XMR + - address - recipient primary address - account index 0, subaddr_indeces [0] + - unlock_time - unlock after n blocks and make spendable - defaults to 0 (no lock) +-outputs: + - signed tx_blob + - tx_hash + +fred_incoming_transfers + +- get a list of incoming mined transfers to fred wallet +- inputs: None + +fred_transfer_to + +- build, sign and broadcast a transaction from bill wallet to another address +- inputs + - amount in in atomic units 1e12 - e.g. 1230000000000 echo = 1.23 XMR + - address - recipient primary address - account index 0, subaddr_indeces [0] + - unlock_time - unlock after n blocks and make spendable - defaults to 0 (no lock) + +wallets + +- wallet details exported to the harness environment - useful for building commands in the harness window 0 + +help + +- this help + +quit + +- shutdown daemons and quit the harness + +``` diff --git a/dex/testing/xmr/harness.sh b/dex/testing/xmr/harness.sh new file mode 100755 index 0000000000..ee70a4ccf1 --- /dev/null +++ b/dex/testing/xmr/harness.sh @@ -0,0 +1,638 @@ +#!/usr/bin/env bash +# Tmux script that sets up an XMR regtest harness with one node 'alpha' and 3 +# wallets 'fred', 'bill' & 'charlie'. Charlie also has a View-Only sibling. +# +# There is now a new monero-wallet-rpc server with no attached wallet. This is +# for programmatically creating and using a new wallet. The wallet will be gen- +# erated in "own" directory but can be named whatever you need - maybe "alice", +# "Bob" or "carol" + +################################################################################ +# Development +################################################################################ + +# export PATH=$PATH:~/monero-x86_64-linux-gnu-v0.18.3.3 + +################################################################################ +# Monero RPC functions +################################################################################ + +source monero_functions + +################################################################################ +# Start up +################################################################################ + +set -evx + +RPC_USER="user" +RPC_PASS="pass" +WALLET_PASS=abc + +LOCALHOST="127.0.0.1" + +# p2p listen and rpc listen ports for alpha node +export ALPHA_NODE_PORT="18080" +export ALPHA_NODE_RPC_PORT="18081" + +# for multinode - not used for singlenode +export ALPHA_NODE="${LOCALHOST}:${ALPHA_NODE_PORT}" + +# wallet servers' listen rpc ports +export FRED_WALLET_RPC_PORT="28084" +export BILL_WALLET_RPC_PORT="28184" +export CHARLIE_WALLET_RPC_PORT="28284" +export CHARLIE_VIEW_WALLET_RPC_PORT="28384" +export OWN_WALLET_RPC_PORT="28484" + +# wallet seeds, passwords & primary addresses +FRED_WALLET_SEED="vibrate fever timber cuffs hunter terminal dilute losing light because nabbing slower royal brunt gnaw vats fishing tipsy toxic vague oscar fudge mice nasty light" +export FRED_WALLET_NAME="fred" +export FRED_WALLET_PASS="" +export FRED_WALLET_PRIMARY_ADDRESS="494aSG3QY1C4PJf7YyDjFc9n2uAuARWSoGQ3hrgPWXtEjgGrYDn2iUw8WJP5Dzm4GuMkY332N9WfbaKfu5tWM3wk8ZeSEC5" + +BILL_WALLET_SEED="zodiac playful artistic friendly ought myriad entrance inroads mural duets enraged furnished tsunami pimple ammo prying january swiftly pulp aunt beer ticket tubes unplugs ammo" +export BILL_WALLET_NAME="bill" +export BILL_WALLET_PASS="" +export BILL_WALLET_PRIMARY_ADDRESS="42xPx5nWhxegefWEzRNoJZWwK7d5ofKoWLG1Gmf8567nJMVR37P1EvqYxqWtfgtYUn8qgSbeAqoLcLKe3seFXV2k5ZSqvQw" + +CHARLIE_WALLET_SEED="tilt equip bikini nylon ardent asylum eight vane gyrate venomous dove vortex aztec maul rash lair elope rover lodge neutral lemon eggs mocked mugged equip" +export CHARLIE_WALLET_NAME="charlie" +export CHARLIE_WALLET_PASS="" +export CHARLIE_WALLET_PRIMARY_ADDRESS="453w1dEoNE1HjKzKVpAU14Honzenqs5VKKQWHb7RuNHLa4ekXhXnGhR6RuttNpvjbtDjzy8pTgz5j4ZSsWQqyxSDBVQ4WCk" +export CHARLIE_WALLET_VIEWKEY="ff3bef320b8268cef410b78c91f34dfc995c72fcb1b498f7a732d76a42a9e207" +export CHARLIE_VIEW_WALLET_NAME="charlie_view" + +# data dir +NODES_ROOT=~/dextest/xmr +FRED_WALLET_DIR="${NODES_ROOT}/wallets/fred" +BILL_WALLET_DIR="${NODES_ROOT}/wallets/bill" +CHARLIE_WALLET_DIR="${NODES_ROOT}/wallets/charlie" +CHARLIE_VIEW_WALLET_DIR="${NODES_ROOT}/wallets/charlie_view" +OWN_WALLET_DIR="${NODES_ROOT}/wallets/own" +HARNESS_CTL_DIR="${NODES_ROOT}/harness-ctl" +ALPHA_DATA_DIR="${NODES_ROOT}/alpha" +ALPHA_REGTEST_CFG="${ALPHA_DATA_DIR}/alpha.conf" + +if [ -d "${NODES_ROOT}" ]; then + rm -fR "${NODES_ROOT}" +fi +mkdir -p "${FRED_WALLET_DIR}" +mkdir -p "${BILL_WALLET_DIR}" +mkdir -p "${CHARLIE_WALLET_DIR}" +mkdir -p "${CHARLIE_VIEW_WALLET_DIR}" +mkdir -p "${OWN_WALLET_DIR}" +mkdir -p "${HARNESS_CTL_DIR}" +mkdir -p "${ALPHA_DATA_DIR}" +touch "${ALPHA_REGTEST_CFG}" + +# make available from the harness-ctl dir +cp monero_functions ${HARNESS_CTL_DIR} + +# Background watch mining in window 7 by default: +# 'export NOMINER="1"' or uncomment this line to disable +#NOMINER="1" + +################################################################################ +# Control Scripts +################################################################################ +echo "Writing ctl scripts" + +# Daemon info +cat > "${HARNESS_CTL_DIR}/alpha_info" <_build_tx) +# - do_not_relay to other nodes - defaults to false +cat > "${HARNESS_CTL_DIR}/alpha_sendrawtransaction" </dev/null +EOF +chmod +x "${HARNESS_CTL_DIR}/alpha_sendrawtransaction" +# ----------------------------------------------------------------------------- + +# Get one or more transaction details from monerod +# inputs: +# - txids as hex string - "hash1,hash2,hash3,..." +# - decode_as_json - defaults to false +cat > "${HARNESS_CTL_DIR}/alpha_get_transactions" </dev/null +EOF +chmod +x "${HARNESS_CTL_DIR}/alpha_get_transactions" +# ----------------------------------------------------------------------------- + +# Get one or more transaction development details from monerod including tx lock time +# inputs: +# - txids as hex string - "hash1,hash2,hash3,..." +cat > "${HARNESS_CTL_DIR}/alpha_get_transactions_details" </dev/null | jq '.txs[] | .as_json | fromjson' +EOF +chmod +x "${HARNESS_CTL_DIR}/alpha_get_transactions_details" +# ----------------------------------------------------------------------------- + +# Mempool info +cat > "${HARNESS_CTL_DIR}/alpha_transaction_pool" </dev/null +EOF +chmod +x "${HARNESS_CTL_DIR}/alpha_transaction_pool" +# ----------------------------------------------------------------------------- + +# Mine to bill-the-miner +# inputs: +# - number of blocks to mine +cat > "${HARNESS_CTL_DIR}/mine-to-bill" < "${HARNESS_CTL_DIR}/fred_transfer_to" < "${HARNESS_CTL_DIR}/bill_transfer_to" < "${HARNESS_CTL_DIR}/charlie_transfer_to" < "${HARNESS_CTL_DIR}/fred_balance" < "${HARNESS_CTL_DIR}/bill_balance" < "${HARNESS_CTL_DIR}/charlie_balance" < "${HARNESS_CTL_DIR}/fred_refresh_wallet" < "${HARNESS_CTL_DIR}/bill_refresh_wallet" < "${HARNESS_CTL_DIR}/charlie_refresh_wallet" < "${HARNESS_CTL_DIR}/fred_incoming_transfers" < "${HARNESS_CTL_DIR}/charlie_incoming_transfers" < "${HARNESS_CTL_DIR}/fred_export_outputs" < "${HARNESS_CTL_DIR}/charlie_export_outputs" < "${HARNESS_CTL_DIR}/charlie_view_export_outputs" < "${HARNESS_CTL_DIR}/fred_export_key_images" < "${HARNESS_CTL_DIR}/charlie_export_key_images" < "${HARNESS_CTL_DIR}/fred_build_tx" < "${HARNESS_CTL_DIR}/charlie_build_tx" < "${HARNESS_CTL_DIR}/wallets" < "${NODES_ROOT}/harness-ctl/quit" < "${NODES_ROOT}/harness-ctl/help" < "${ALPHA_REGTEST_CFG}" <