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

Fix for spark names RPC #1528

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
177f164
Initial spark name architecture
psolstice Aug 28, 2024
3eb4c37
Spark address ownership proofs implemented.
levonpetrosyan93 Oct 5, 2024
7534405
Missing files added
levonpetrosyan93 Oct 6, 2024
5e14aa4
Check the ownership proof for spark names: initial implementation
psolstice Oct 13, 2024
e520cc3
Fixes to the core part of spark names
psolstice Nov 17, 2024
a5c6f14
Added additional field (core)
psolstice Dec 15, 2024
450bc65
Consensus parameters for spark names
psolstice Dec 21, 2024
cd6b4f3
Fixed mempool bug
psolstice Dec 22, 2024
200df44
Fixes in spark name conflict resolution
psolstice Jan 12, 2025
c1970e7
RPCs for spark names
levoncrypto Jan 15, 2025
6878f4f
Additional API for spark names tx creation
psolstice Jan 15, 2025
de07857
Changed way of checking spark name tx
psolstice Jan 19, 2025
5a320a7
Wallet API for spark name transaction creation
psolstice Jan 19, 2025
5ab7f4d
API changes for spark name tx creation
psolstice Jan 22, 2025
6309af4
Added registersparkname RPC call
psolstice Jan 25, 2025
b14e6fd
Merge remote-tracking branch 'origin/spark-names' into rpc_spark_names
levoncrypto Jan 27, 2025
a560e38
Spark activation check for RPC
levoncrypto Jan 27, 2025
503a397
Make spark names case-insensitive
psolstice Jan 31, 2025
1dff023
Merge remote-tracking branch 'firo/rpc_spark_names' into spark-names
psolstice Feb 1, 2025
ca5c1ba
Spark name RPC fixes
psolstice Feb 2, 2025
13093ee
Faster lookup for spark name by spark address
psolstice Feb 3, 2025
335b332
Fixes for spark name/address lookup
psolstice Feb 3, 2025
2a59c73
Improvements for duplicated address detection
psolstice Feb 3, 2025
672b700
Fixes for spark name state
psolstice Feb 4, 2025
e243b7d
Block index entries for spark names
psolstice Feb 5, 2025
88438ec
Make dot (.) a legit symbol in spark name
psolstice Feb 6, 2025
b739e1e
Spark name block number for testnet
psolstice Feb 9, 2025
fb4d49d
Fixed restoration of old spark name data if block is disconnected
psolstice Feb 9, 2025
344050d
API for quick check of spark name transaction validity before the cre…
psolstice Feb 10, 2025
a2366fb
added isAddressMine function
levonpetrosyan93 Feb 11, 2025
2f47a1d
Check if the address belongs to the wallet before creating spark name…
psolstice Feb 11, 2025
8d973d0
Fixed fee calculation for spark name
psolstice Feb 13, 2025
d4ccf02
Fix for spark names RPC
levoncrypto Feb 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contrib/bitcoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ FORMS += \
../src/qt/forms/transactiondescdialog.ui \
../src/qt/forms/zerocoinpage.ui \
../src/qt/forms/sendcoinsdialog.ui \
../src/qt/forms/createsparkname.ui

RESOURCES += \
../src/qt/bitcoin.qrc
3 changes: 3 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ BITCOIN_CORE_H = \
sigma.h \
lelantus.h \
spark/state.h \
sparkname.h \
blacklists.h \
coin_containers.h \
firo_params.h \
Expand Down Expand Up @@ -424,6 +425,7 @@ libbitcoin_server_a_SOURCES = \
bip47/paymentcode.cpp \
spark/state.cpp \
spark/primitives.cpp \
sparkname.cpp \
coin_containers.cpp \
mtpstate.cpp \
$(BITCOIN_CORE_H)
Expand Down Expand Up @@ -684,6 +686,7 @@ libspark_a_SOURCES = \
libspark/hash.cpp \
libspark/mint_transaction.h \
libspark/mint_transaction.cpp \
libspark/ownership_proof.h \
libspark/spend_transaction.h \
libspark/spend_transaction.cpp \
libspark/f4grumble.h \
Expand Down
12 changes: 8 additions & 4 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ QT_FORMS_UI = \
qt/forms/sendtopcodedialog.ui \
qt/forms/signverifymessagedialog.ui \
qt/forms/transactiondescdialog.ui \
qt/forms/lelantusdialog.ui
qt/forms/lelantusdialog.ui \
qt/forms/createsparkname.ui

QT_MOC_CPP = \
qt/moc_addressbookpage.cpp \
Expand Down Expand Up @@ -181,7 +182,8 @@ QT_MOC_CPP = \
qt/moc_automintmodel.cpp \
qt/moc_automintnotification.cpp \
qt/moc_pcodemodel.cpp \
qt/moc_sparkmodel.cpp
qt/moc_sparkmodel.cpp \
qt/moc_createsparknamepage.cpp

BITCOIN_MM = \
qt/macdockiconhandler.mm \
Expand Down Expand Up @@ -264,7 +266,8 @@ BITCOIN_QT_H = \
qt/lelantusdialog.h \
qt/lelantuscoincontroldialog.h \
qt/automintmodel.h \
qt/sparkmodel.h
qt/sparkmodel.h \
qt/createsparknamepage.h

RES_ICONS = \
qt/res/icons/add.png \
Expand Down Expand Up @@ -454,7 +457,8 @@ BITCOIN_QT_WALLET_CPP = \
qt/lelantusdialog.cpp \
qt/lelantuscoincontroldialog.cpp \
qt/automintmodel.cpp \
qt/sparkmodel.cpp
qt/sparkmodel.cpp \
qt/createsparknamepage.cpp

BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP)
if TARGET_WINDOWS
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ BITCOIN_TESTS = \
liblelantus/test/sigma_extended_test.cpp \
libspark/test/transcript_test.cpp \
libspark/test/schnorr_test.cpp \
libspark/test/ownership_test.cpp \
libspark/test/chaum_test.cpp \
libspark/test/bpplus_test.cpp \
libspark/test/grootle_test.cpp \
Expand Down
13 changes: 13 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "chainparams.h"
#include "coin_containers.h"
#include "streams.h"
#include "sparkname.h"

#include <vector>
#include <unordered_set>
Expand Down Expand Up @@ -268,6 +269,11 @@ class CBlockIndex
//! std::map {feature name} -> {block number when feature is re-enabled again, parameter}
ActiveSporkMap activeDisablingSporks;

//! List of spark names that were created or extended in this block. Map of spark name to <address, expiration block height, additional info>
std::map<std::string, CSparkNameBlockIndexData> addedSparkNames;
//! List of spark names that were removed in this block because of expiration
std::map<std::string, CSparkNameBlockIndexData> removedSparkNames;

void SetNull()
{
phashBlock = NULL;
Expand Down Expand Up @@ -310,6 +316,8 @@ class CBlockIndex
sigmaSpentSerials.clear();
lelantusSpentSerials.clear();
activeDisablingSporks.clear();
addedSparkNames.clear();
removedSparkNames.clear();
}

CBlockIndex()
Expand Down Expand Up @@ -584,6 +592,11 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(activeDisablingSporks);
}
nDiskBlockVersion = nVersion;

if (!(s.GetType() & SER_GETHASH) && nHeight >= params.nSparkNamesStartBlock) {
READWRITE(addedSparkNames);
READWRITE(removedSparkNames);
}
}

uint256 GetBlockHash() const
Expand Down
23 changes: 23 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ static Consensus::LLMQParams llmq400_85 = {
.keepOldConnections = 5,
};

static std::array<int,21> standardSparkNamesFee = {
-1,
1000,
100,
10, 10, 10,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};

/**
* Main network
Expand Down Expand Up @@ -481,6 +488,10 @@ class CMainParams : public CChainParams {

// exchange address
consensus.nExchangeAddressStartBlock = consensus.nSparkStartBlock;

// spark names
consensus.nSparkNamesStartBlock = INT_MAX;
consensus.nSparkNamesFee = standardSparkNamesFee;
}
virtual bool SkipUndoForBlock(int nHeight) const
{
Expand Down Expand Up @@ -783,6 +794,10 @@ class CTestNetParams : public CChainParams {

// exchange address
consensus.nExchangeAddressStartBlock = 147000;

// spark names
consensus.nSparkNamesStartBlock = 174000;
consensus.nSparkNamesFee = standardSparkNamesFee;
}
};

Expand Down Expand Up @@ -1027,6 +1042,10 @@ class CDevNetParams : public CChainParams {

// exchange address
consensus.nExchangeAddressStartBlock = 2500;

// spark names
consensus.nSparkNamesStartBlock = 3500;
consensus.nSparkNamesFee = standardSparkNamesFee;
}
};

Expand Down Expand Up @@ -1267,6 +1286,10 @@ class CRegTestParams : public CChainParams {
consensus.nPPSwitchTime = INT_MAX;
consensus.nPPBlockNumber = INT_MAX;
consensus.nInitialPPDifficulty = 0x2000ffff;

// spark names
consensus.nSparkNamesStartBlock = 2000;
consensus.nSparkNamesFee = standardSparkNamesFee;
}

void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
Expand Down
3 changes: 3 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ struct Params {

int nSparkStartBlock;

int nSparkNamesStartBlock;
std::array<int,21> nSparkNamesFee;

int nLelantusGracefulPeriod;

// Lelantus Blacklist
Expand Down
66 changes: 66 additions & 0 deletions src/libspark/keys.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "keys.h"
#include "../hash.h"
#include "transcript.h"

namespace spark {

Expand Down Expand Up @@ -243,4 +244,69 @@ unsigned char Address::decode(const std::string& str) {
return network;
}

Scalar Address::challenge(const Scalar& m, const GroupElement& A, const GroupElement& H) const {
Transcript transcript(LABEL_TRANSCRIPT_OWNERSHIP);
transcript.add("G", this->params->get_G());
transcript.add("F", this->params->get_F());
transcript.add("H", H);
transcript.add("A", A);
transcript.add("m", m);
transcript.add("d", this->d);
transcript.add("Q1", this->Q1);
transcript.add("Q2", this->Q2);

return transcript.challenge("c");
}


void Address::prove_own(const Scalar& m,
const SpendKey& spend_key,
const IncomingViewKey& incomingViewKey,
OwnershipProof& proof) const {
Scalar a, b, c;
a.randomize();
b.randomize();
c.randomize();

GroupElement H = SparkUtils::hash_div(this->d);
proof.A = H * a + this->params->get_G() * b + this->params->get_F() * c;

if (proof.A.isInfinity()) {
throw std::invalid_argument("Bad Proof construction!");
}

Scalar x = challenge(m, proof.A, H);

if (x.isZero()) {
throw std::invalid_argument("Unexpected challenge!");
}

Scalar x_sqr = x.square();

uint64_t i = incomingViewKey.get_diversifier(this->d);
proof.t1 = a + x * spend_key.get_s1();
proof.t2 = b + x_sqr * spend_key.get_r();
proof.t3 = c + x_sqr * (SparkUtils::hash_Q2(spend_key.get_s1(), i) + spend_key.get_s2());
}

bool Address::verify_own(const Scalar& m,
OwnershipProof& proof) const {
if (proof.A.isInfinity()) {
throw std::invalid_argument("Bad Ownership Proof!");
}

GroupElement H = SparkUtils::hash_div(this->d);
Scalar x = challenge(m, proof.A, H);
if (x.isZero()) {
throw std::invalid_argument("Unexpected challenge!");
}

Scalar x_sqr = x.square();

GroupElement left = proof.A + this->Q1 * x + this->Q2 * x_sqr;
GroupElement right = H * proof.t1 + this->params->get_G() * proof.t2 + this->params->get_F() * proof.t3;

return left == right;
}

}
15 changes: 15 additions & 0 deletions src/libspark/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "f4grumble.h"
#include "params.h"
#include "util.h"
#include "../uint256.h"
#include "ownership_proof.h"

namespace spark {

Expand Down Expand Up @@ -82,6 +84,19 @@ class Address {
std::string encode(const unsigned char network) const;
unsigned char decode(const std::string& str);

Scalar challenge(const Scalar& m, const GroupElement& A, const GroupElement& H) const;
void prove_own(const Scalar& m,
const SpendKey& spend_key,
const IncomingViewKey& incomingViewKey,
OwnershipProof& proof) const;

bool verify_own(const Scalar& m,
OwnershipProof& proof) const;

bool operator < (const Address &other) const {
return encode(0) < other.encode(0);
}

private:
const Params* params;
std::vector<unsigned char> d;
Expand Down
31 changes: 31 additions & 0 deletions src/libspark/ownership_proof.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef FIRO_LIBSPARK_OWNERSHIP_PROOF_H
#define FIRO_LIBSPARK_OWNERSHIP_PROOF_H

#include "params.h"

namespace spark {

class OwnershipProof{
public:
inline std::size_t memoryRequired() const {
return Scalar::memoryRequired() * 3 + GroupElement::memoryRequired();
}

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(A);
READWRITE(t1);
READWRITE(t2);
READWRITE(t3);
}

public:
GroupElement A;
Scalar t1;
Scalar t2;
Scalar t3;
};
}

#endif
Loading
Loading