Skip to content

Commit

Permalink
Segwit support debug (#251)
Browse files Browse the repository at this point in the history
* Whitelist P2SH addresses

* Whitelist P2PKH or P2SH addresses

* Reduce registeraddress tx size for contactintx=1

* Revert "Reduce registeraddress tx size for contactintx=1"

This reverts commit 837ebd5.

* Correct onboard_cit.py

* Whitelist P2SH addresses

* Correct error in whitelist.h

* Registeraddress script version 1

* Dont include pubkeys etc. in registeraddress TX if contractintx=0

* Test for P2PKH and P2SH address whitelisting

* Added test for whitelisting witness address.

* Revert dockerfile change.

* Test segwit adress onboarding and backwards compatibility. Bug fix in whitelist.cpp

* Implement != operator for CNoDestination

* Fix bug

* Correctly build version 0 registeraddress TXs
  • Loading branch information
lawlawlaw authored and tomt1664 committed Oct 30, 2019
1 parent d062fd0 commit a2cc55f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 21 deletions.
3 changes: 2 additions & 1 deletion qa/rpc-tests/onboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def run_test (self):
kycfile0_plain=self.initfile(os.path.join(self.options.tmpdir,"kycfile0_plain.dat"))
self.nodes[0].readkycfile(kycfile0, kycfile0_plain)

self.nodes[0].onboarduser(kycfile0)
#Old registeraddresss script (version 0)
self.nodes[0].onboarduser(kycfile0, 0)
time.sleep(5)
self.nodes[0].generate(101)
time.sleep(5)
Expand Down
3 changes: 2 additions & 1 deletion qa/rpc-tests/onboard_cit.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ def run_test (self):
print("onboard node 0 \n")
print("read kycfile0 node 0 \n")
self.nodes[0].readkycfile(kycfile0, kycfile0_plain)
self.nodes[0].onboarduser(kycfile0)
#Old registeraddresss script (version 0)
self.nodes[0].onboarduser(kycfile0, 0)
print("generate block \n")
self.nodes[0].generate(101)
print("sync all \n")
Expand Down
41 changes: 35 additions & 6 deletions qa/rpc-tests/onboardmanual_cit.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,41 @@ def run_test (self):
self.nodes[0].generate(101)
self.sync_all()

valkyc=self.nodes[0].validatekycfile(kycfile_multisig)
print(valkyc)
assert(valkyc["iswhitelisted"] == True)

#Blacklist
try:
self.nodes[0].blacklistuser(kycfile_multisig)
except JSONRPCException as e:
print(e.error['message'])
assert(False)

self.nodes[0].generate(101)
self.sync_all()

valkyc=self.nodes[0].validatekycfile(kycfile_multisig)
print(valkyc)
assert(valkyc["iswhitelisted"] == False)

#Onboard again using registeraddresss script version 0
try:
self.nodes[0].onboarduser(kycfile_multisig, 0)
except JSONRPCException as e:
print(e.error['message'])
assert(False)

self.nodes[0].generate(101)
self.sync_all()

valkyc=self.nodes[0].validatekycfile(kycfile_multisig)
print(valkyc)
assert(valkyc["iswhitelisted"] == True)

os.remove(kycfile_multisig)



#Test invalid parameters
try:
Expand Down Expand Up @@ -438,12 +473,6 @@ def run_test (self):
assert("Invalid pubkey in multisiglist: " in message)


valkyc=self.nodes[0].validatekycfile(kycfile_multisig)
print(valkyc)
assert(valkyc["iswhitelisted"] == True)

os.remove(kycfile_multisig)

onboardAddress1=self.nodes[1].validateaddress(self.nodes[1].getnewaddress())
onboardAddress2=self.nodes[1].validateaddress(self.nodes[1].getnewaddress())
onboardAddress3=self.nodes[1].validateaddress(self.nodes[1].getnewaddress())
Expand Down
3 changes: 2 additions & 1 deletion src/policy/kycfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ bool CKYCFile::is_empty(){
return true;
}

bool CKYCFile::getOnboardingScript(CScript& script, bool fBlacklist){
bool CKYCFile::getOnboardingScript(CScript& script, bool fBlacklist, int nVersion){
uint256 contract = chainActive.Tip() ? chainActive.Tip()->hashContract : GetContractHash();
if(!contract.IsNull() && Params().ContractInKYCFile()){
if(!_fContractHash_parsed)
Expand All @@ -349,6 +349,7 @@ bool CKYCFile::getOnboardingScript(CScript& script, bool fBlacklist){


COnboardingScript obScript;
if(nVersion >=0) obScript.ScriptVersion(nVersion);
obScript.SetDeregister(fBlacklist);

// Lookup the KYC public key assigned to the user from the whitelist
Expand Down
2 changes: 1 addition & 1 deletion src/policy/kycfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CKYCFile{

const std::stringstream& getStream() const {return _decryptedStream;}

bool getOnboardingScript(CScript& script, bool fBlacklist=false);
bool getOnboardingScript(CScript& script, bool fBlacklist=false, int nVersion=-1);

bool is_whitelisted();

Expand Down
2 changes: 1 addition & 1 deletion src/policy/whitelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ bool CWhiteList::RegisterDecryptedAddresses(const txnouttype& whichType, const s

void CWhiteList::add(CRegisterAddressData* d){
CTxDestination dest = d->GetDest();
if(dest != _noDest) CPolicyList::add_sorted(dest);
if(!(dest == _noDest)) CPolicyList::add_sorted(dest);
}

void CWhiteList::remove(CRegisterAddressData* d){
Expand Down
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CRPCConvertParam
*/
static const CRPCConvertParam vRPCConvertParams[] =
{
{ "onboarduser", 1, "scriptversion"},
{ "topupkycpubkeys", 0, "nkeys" },
{ "whitelistkycpubkeys", 0, "kycpubkeys" },
{ "setmocktime", 0, "timestamp" },
Expand Down
11 changes: 6 additions & 5 deletions src/script/registeraddressscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ bool CRegisterAddressScript::Append(const pubKeyPair& p){
if(_whitelistType != RA_PUBLICKEY && _whitelistType != RA_ONBOARDING)
return false;

if(!Params().ContractInTx()){
if(!Consensus::CheckValidTweakedAddress(p.first, p.second))
if(!Params().ContractInTx() &! Consensus::CheckValidTweakedAddress(p.first, p.second))
return false;

if(!Params().ContractInTx() || _nScriptVersion == 0){

CBitcoinAddress addr(p.first);

if(!addr.IsValid())
Expand Down Expand Up @@ -169,11 +170,11 @@ bool CRegisterAddressScript::Append(const uint8_t nMultisig, const CTxDestinatio
if(_whitelistType != RA_MULTISIG && _whitelistType != RA_ONBOARDING)
return false;

if (!Params().ContractInTx()){

if(!(Consensus::CheckValidTweakedAddress(keyID, keys, nMultisig)))
if(!Params().ContractInTx() &! Consensus::CheckValidTweakedAddress(keyID, keys, nMultisig))
return false;

if (!Params().ContractInTx() || _nScriptVersion == 0){

unsigned int nAppend=0;
if(Append(AddrType::MULTI)) ++nAppend;
AppendChar((unsigned char)nMultisig);
Expand Down
2 changes: 1 addition & 1 deletion src/script/registeraddressscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class CRegisterAddressScript {
return _nScriptVersion;
}


void AppendChar(const unsigned char& c){
_payload.push_back(c);
}


std::size_t getPayloadSize() { return _payload.size(); }

virtual void clear(){_payload.clear(); _encrypted.clear(); ((CScript*)this)->clear();}
Expand Down
15 changes: 11 additions & 4 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,14 @@ static void SendOnboardTx(const CScript& script, CWalletTx& wtxNew){
}

UniValue onboarduser(const JSONRPCRequest& request){
if (request.fHelp || request.params.size() != 1)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error(
"onboarduser \"filename\" \n"
"Read in derived keys and tweaked addresses from kyc file (see dumpkycfile, createkycfile) into the address whitelist. Assign a KYC public key to the user if using encrypted whitelist.\n"
"\nArguments:\n"

"1. \"filename\" (string, required) The kyc file name\n"
"1. \"filename\" (string, required) The kyc file name\n"
"2. \"scriptversion\" (integer, optional) The registeraddress script version (default = latest)\n"

"\nExamples:\n"
+ HelpExampleCli("onboarduser", "\"my filename\"")
Expand All @@ -821,10 +822,16 @@ UniValue onboarduser(const JSONRPCRequest& request){
EnsureWalletIsUnlocked();

CKYCFile file;

file.read(request.params[0].get_str().c_str());

int nVersion=-1;
if(request.params.size() > 1){
nVersion = request.params[1].get_int();
}

CScript script;
if(!file.getOnboardingScript(script))
if(!file.getOnboardingScript(script, false, nVersion))
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot generate onboarding script");

CWalletTx wtx;
Expand Down Expand Up @@ -6039,7 +6046,7 @@ static const CRPCCommand commands[] =
{ "wallet", "dumpkycfile", &dumpkycfile, true, {"filename"} },
{ "wallet", "readkycfile", &readkycfile, true, {"filename", "outfilename", "onboardpubkey"} },
{ "wallet", "validatekycfile", &validatekycfile, true, {"filename"} },
{ "wallet", "onboarduser", &onboarduser, false, {"filename"} },
{ "wallet", "onboarduser", &onboarduser, false, {"filename", "scriptversion"} },
{ "wallet", "blacklistuser", &blacklistuser, false, {"filename"} },
{ "wallet", "topupkycpubkeys", &topupkycpubkeys, false, {"nkeys"} },
{ "wallet", "removekycpubkey", &removekycpubkey, false, {"kycpubkey"} },
Expand Down

0 comments on commit a2cc55f

Please sign in to comment.