forked from hush/hush3
Jonathan "Duke" Leto
5 years ago
73 changed files with 5581 additions and 1845 deletions
@ -1,5 +0,0 @@ |
|||
Building Zcash |
|||
|
|||
See the Zcash github wiki (https://github.com/zcash/zcash/wiki) for instructions on building zcashd, |
|||
the intended-for-services, no-graphical-interface, reference |
|||
implementation of Zcash. |
@ -0,0 +1,80 @@ |
|||
# Installing Hush |
|||
|
|||
## Build HUSH dependencies |
|||
|
|||
The following build process generally applies to Ubuntu (and similar) Linux |
|||
distributions. For best results it is recommended to use Ubuntu Linux 16.04 |
|||
or later. |
|||
|
|||
## Swap Space (Optional) |
|||
You will need at least 4GB of RAM to build hush from git source, OR you can |
|||
enable a swap file. To enable a 4GB swap file on modern Linux distributions: |
|||
|
|||
```sh |
|||
sudo fallocate -l 4G /swapfile |
|||
sudo chmod 600 /swapfile |
|||
sudo mkswap /swapfile |
|||
sudo swapon /swapfile |
|||
``` |
|||
|
|||
## Build on Linux: |
|||
|
|||
|
|||
```sh |
|||
# install build depedencies |
|||
sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib \ |
|||
autoconf libtool ncurses-dev unzip git python zlib1g-dev wget \ |
|||
bsdmainutils automake curl unzip nano |
|||
# pull |
|||
git clone https://github.com/MyHush/hush3.git |
|||
cd hush3 |
|||
# Build |
|||
./zcutil/build.sh -j$(nproc) |
|||
``` |
|||
|
|||
## Download proving key: |
|||
```sh |
|||
./zcutil/fetch-params.sh |
|||
``` |
|||
|
|||
## Run a HUSH Node |
|||
|
|||
```sh |
|||
./src/hushd |
|||
``` |
|||
|
|||
## Windows (cross-compiled on Linux) |
|||
Get dependencies: |
|||
```ssh |
|||
sudo apt-get install \ |
|||
build-essential pkg-config libc6-dev m4 g++-multilib \ |
|||
autoconf libtool ncurses-dev unzip git python \ |
|||
zlib1g-dev wget bsdmainutils automake mingw-w64 cmake |
|||
``` |
|||
|
|||
Downloading Git source repo, building and running Hush: |
|||
|
|||
```sh |
|||
# pull |
|||
git clone https://github.com/MyHush/hush3.git |
|||
cd hush |
|||
# fetch key |
|||
./zcutil/fetch-params.sh |
|||
# Build |
|||
./zcutil/build-win.sh -j$(nproc) |
|||
# Run a HUSH node |
|||
./src/hushd |
|||
``` |
|||
|
|||
Currently Linux, Windows and Mac OS X are our supported platforms. If you |
|||
are interested in porting Hush to a new operating system, we are interested |
|||
to talk with you. Experimental FreeBSD support is in progress, thanks to radix42. |
|||
|
|||
We aim to support all platforms, but there is only so much time in the day. |
|||
|
|||
Currently, any ARMv7 machine will not be able to build this repo, because the |
|||
underlying tech (zcash and the zksnark library) do not support that instruction |
|||
set. |
|||
|
|||
This also means that RaspberryPi devices will not work, unless they have a |
|||
newer ARMv8-based Raspberry Pi. |
@ -0,0 +1,2 @@ |
|||
#!/bin/bash |
|||
./komodo-cli -ac_name=K64 $1 $2 $3 $4 $5 $6 |
@ -0,0 +1,2 @@ |
|||
#!/bin/bash |
|||
./komodo-cli -ac_name=KOIN $1 $2 $3 $4 $5 $6 |
@ -1,2 +0,0 @@ |
|||
#!/bin/bash |
|||
./komodo-cli -ac_name=ZEX $1 $2 $3 $4 $5 $6 |
@ -0,0 +1,2 @@ |
|||
#!/bin/bash |
|||
./komodo-cli -ac_name=ZEXO $1 $2 $3 $4 $5 $6 |
@ -0,0 +1,116 @@ |
|||
/*Descriptson and examples of COptCCParams class found in:
|
|||
script/standard.h/cpp |
|||
class COptCCParams |
|||
|
|||
structure of data in vData payload attached to end of CCvout: |
|||
param |
|||
OP_1 |
|||
param |
|||
OP_2 ... etc until OP_16 |
|||
OP_PUSHDATA4 is the last OP code to tell things its at the end. |
|||
|
|||
taken from standard.cpp line 22: COptCCParams::COptCCParams(std::vector<unsigned char> &vch) |
|||
|
|||
EXAMPLE taken from Verus how to create scriptPubKey from COptCCParams class: |
|||
EXAMPLE taken from Verus how to decode scriptPubKey from COptCCParams class: |
|||
*/ |
|||
|
|||
bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxOut &vout) |
|||
{ |
|||
CCcontract_info *cp, C; |
|||
cp = CCinit(&C,EVAL_STAKEGUARD); |
|||
|
|||
CPubKey ccAddress = CPubKey(ParseHex(cp->CChexstr)); |
|||
|
|||
// return an output that is bound to the stake transaction and can be spent by presenting either a signed condition by the original
|
|||
// destination address or a properly signed stake transaction of the same utxo on a fork
|
|||
vout = MakeCC1of2vout(EVAL_STAKEGUARD, value, dest, ccAddress); |
|||
|
|||
std::vector<CPubKey> vPubKeys = std::vector<CPubKey>(); |
|||
vPubKeys.push_back(dest); |
|||
vPubKeys.push_back(ccAddress); |
|||
|
|||
std::vector<std::vector<unsigned char>> vData = std::vector<std::vector<unsigned char>>(); |
|||
|
|||
CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); |
|||
|
|||
hw << stakeTx.vin[0].prevout.hash; |
|||
hw << stakeTx.vin[0].prevout.n; |
|||
|
|||
uint256 utxo = hw.GetHash(); |
|||
vData.push_back(std::vector<unsigned char>(utxo.begin(), utxo.end())); // Can we use any data here to construct vector?
|
|||
|
|||
CStakeParams p; |
|||
if (GetStakeParams(stakeTx, p)) |
|||
{ |
|||
// prev block hash and height is here to make validation easy
|
|||
vData.push_back(std::vector<unsigned char>(p.prevHash.begin(), p.prevHash.end())); |
|||
std::vector<unsigned char> height = std::vector<unsigned char>(4); |
|||
for (int i = 0; i < 4; i++) |
|||
{ |
|||
height[i] = (p.blkHeight >> (8 * i)) & 0xff; |
|||
} |
|||
vData.push_back(height); |
|||
|
|||
COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_STAKEGUARD, 1, 2, vPubKeys, vData); |
|||
|
|||
vout.scriptPubKey << ccp.AsVector() << OP_DROP; |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTransaction &stakeTx, bool &cheating) |
|||
{ |
|||
// an invalid or non-matching stake transaction cannot cheat
|
|||
cheating = false; |
|||
|
|||
//printf("ValidateMatchingStake: ccTx.vin[0].prevout.hash: %s, ccTx.vin[0].prevout.n: %d\n", ccTx.vin[0].prevout.hash.GetHex().c_str(), ccTx.vin[0].prevout.n);
|
|||
|
|||
if (ccTx.IsCoinBase()) |
|||
{ |
|||
CStakeParams p; |
|||
if (ValidateStakeTransaction(stakeTx, p)) |
|||
{ |
|||
std::vector<std::vector<unsigned char>> vParams = std::vector<std::vector<unsigned char>>(); |
|||
CScript dummy; |
|||
|
|||
if (ccTx.vout[voutNum].scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) && vParams.size() > 0) |
|||
{ |
|||
COptCCParams ccp = COptCCParams(vParams[0]); |
|||
if (ccp.IsValid() & ccp.vData.size() >= 3 && ccp.vData[2].size() <= 4) |
|||
{ |
|||
CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); |
|||
|
|||
hw << stakeTx.vin[0].prevout.hash; |
|||
hw << stakeTx.vin[0].prevout.n; |
|||
uint256 utxo = hw.GetHash(); |
|||
|
|||
uint32_t height = 0; |
|||
int i, dataLen = ccp.vData[2].size(); |
|||
for (i = dataLen - 1; i >= 0; i--) |
|||
{ |
|||
height = (height << 8) + ccp.vData[2][i]; |
|||
} |
|||
// for debugging strange issue
|
|||
// printf("iterator: %d, height: %d, datalen: %d\n", i, height, dataLen);
|
|||
|
|||
if (utxo == uint256(ccp.vData[0])) |
|||
{ |
|||
if (p.prevHash != uint256(ccp.vData[1]) && p.blkHeight >= height) |
|||
{ |
|||
cheating = true; |
|||
return true; |
|||
} |
|||
// if block height is equal and we are at the else, prevHash must have been equal
|
|||
else if (p.blkHeight == height) |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
@ -0,0 +1,65 @@ |
|||
How this works: |
|||
- earlytxid must be a transaction included in the chain before block 100. The chain MUST not have any other of these type of tx before block 100, or someone may be able to change it and mess things up. |
|||
- When it gets to block 100, it takes the txid specified by the -earlytxid param (does not affect magic) |
|||
- Looks up the transaction searches for the opreturn, then permenantly appends it to the end of ac_script in RAM. |
|||
- After every daemon restart, the first time the daemon mines a block, or receives a block that pays ac_script it will look up the op_return and save it again. |
|||
- this enables it to always reach consensus but doesnt need to constantly keep looking up the tx in the chain. |
|||
- The trick is to use ac_founders=101 or higher so that nothing is ever paid to the unspendable CC address. Although it should still work without this it burns coins. |
|||
|
|||
-ac_script can be any Global CC address you can spend to with an OP_RETURN. Here we use example of paymentsCC being used to fund a rewards plan, and a set of founders address's. |
|||
you can get the ac_script from another chain, but the op_return payload must generated on the chain itself. this command gives you the needed info to get the scripPubKey Hex: |
|||
./komodo-cli -ac_name=TEST paymentsfund '["5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682",1000]' |
|||
append: b8, to the end of ac_script, this changes magic value for -earlytxid chains vs normal ac_script and allows bypass of ac_supply paid to the scritpt as it would be unspendable and you would be unable to create the needed plans with no coins. |
|||
-ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 |
|||
|
|||
-testnode=1 is not affecting magic and allows mining on a single node, we can use this to bootstrap the chain before syncing a second node to save time. |
|||
|
|||
start chain and make sure to do the following steps before block 100 (set generate false/true is a good idea between steps) |
|||
./komodod -ac_name=TESTHC -ac_supply=1000000 -ac_reward=100000000000 -ac_cc=2 -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 -ac_founders=150 -ac_blocktime=20 -ac_nk=96,5 -testnode=1 |
|||
|
|||
create rewards plan and fund it with all or a % of the premine. Must be some amount. eg. |
|||
./komodo-cli -ac_name=TESTHC rewardscreatefunding test 50000 25 0 2 500 |
|||
|
|||
do rewards add funding: |
|||
./komodo-cli -ac_name=TESTHC rewardsaddfunding test 47a3150150bd196bd2086cae5e0c6b01a23785a04139fa660d169121a534b38e 1000 |
|||
|
|||
and get the script pubkey and op_return from this tx (no need to send it) |
|||
./komodo-cli -ac_name=TESTHC decoderawtransaction 010000000204ca4c7aaae62bb8fc9412ac010e047fa8d33c3f87d2adeb3e02170642ddfe370000000049483045022100d7b9a |
|||
4f28ca3a35f34dcdb6075e905cde1eaa962bd0619d0a8ed8e17e952bc99022077308e12325fc2a02c752ec3df9aeee1fc219ea54a4d3884834582b75c89815e01ffffffff08800132da3233d80c65e87b6db6a76dcf |
|||
188e4fdfa23198d69f647e67754cfb0000000049483045022100d6a8f7a1c4f6013f5897768ae0117fe61dfb72352d3e6652e64a6588db3ffcb102202aa1d041b24f9cbbf7028295b7c5e7f18b4f95ae39c13031dab |
|||
7f06634438e6801ffffffff0300e8764817000000302ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401ccf0c0764817000000232103bbec93af84 |
|||
0933ae2d35fc56eff24f34dbe26871402552f84c44f690945ccd79ac00000000000000002c6a2ae54174657374000000008eb334a52191160d66fa3941a08537a2016b0c5eae6c08d26b19bd500115a34700000000 |
|||
|
|||
From the return of this you need the scriptpubkey hex of vout 0: |
|||
scriptPubKey: 2ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401cc |
|||
and the scriptpubkey hex of the OP_RETURN in vout 2. |
|||
OP_RETURN: 6a2ae54174657374000000008eb334a52191160d66fa3941a08537a2016b0c5eae6c08d26b19bd500115a347 |
|||
|
|||
create txidopreturn for this payment: |
|||
./komodo-cli -ac_name=TESTHC paymentstxidopret '[50,"2ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401cc","6a2ae54174657374000000008eb334a52191160d66fa3941a08537a2016b0c5eae6c08d26b19bd500115a347"]' |
|||
|
|||
create the txidopret for the founders reward(s) pubkeys: should be able to be a few here, not sure of max number yet. These can pay anything that does not need an opreturn. allocation and scriptpubkey hex. |
|||
./komodo-cli -ac_name=TESTHC paymentstxidopret '[50,"76a9146bf5dd9f679c87a3f83ea176f82148d26653c04388ac"]' |
|||
|
|||
create payments plan: |
|||
./komodo-cli -ac_name=TESTHC paymentscreate '[0,0,"61f55f2f87dad3a37d42731a8cb73b3ebea1817abfa176218162c360a8bd7145","0550014823ffa0aa99d7dd7ca5292f4dd0a1b9156eddec03412c953f095181bc"]' |
|||
gives plan txid: ee7765be874fb084c00538b1b0488e8ecb857de253f09a9ba6ea8d3579b77d33 |
|||
|
|||
paymentsfund: |
|||
To do this you first need to change the type of tx generated by paymentsfund RPC. in payments.cpp go to line: 639 and comment it out, then uncomment the block of code under this. |
|||
change the line 646 to line 647 with comments, and line 650/651 aswell. This enables the RPC to generate the ccvout opreturn payload you need without sending the payment on the chain. Just decode the raw hex. |
|||
./komodo-cli -ac_name=TESTHC paymentsfund '["ee7765be874fb084c00538b1b0488e8ecb857de253f09a9ba6ea8d3579b77d33",1000,1]' |
|||
|
|||
get the payment fund scriptpubkey hex from vout 0: (the split it at OP_CHECKCRYPTOCONDITION or 'cc' ) |
|||
2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401cc 2a0401f00101246a22f046337db779358deaa69b9af053e27d85cb8e8e48b0b13805c084b04f87be6577ee75 |
|||
|
|||
put the second half into an OP_RETURN: (the remaining part of the the above scriptpubkey) eg. |
|||
./komodo-cli -ac_name=TESTHC opreturn_burn 1 2a0401f00101246a22f046337db779358deaa69b9af053e27d85cb8e8e48b0b13805c084b04f87be6577ee75 |
|||
opret_burn takes any burn amount and arbitrary hex string. (RPC works, but may have bugs, likely use this for LABS too with some fixes) |
|||
this gives a raw hex. Decode it and check the OP_RETURN is right before sending. |
|||
-earlytxid=810bd62fb8353fad20267ff2050684b8829affa3edf6b366633931530791dfce |
|||
restart the chain with earlytxid param before height 100 on all nodes (if not using -testnode=1) |
|||
./komodod -ac_name=TESTHC -ac_supply=1000000 -ac_reward=100000000000 -ac_cc=2 -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 -ac_founders=150 -ac_blocktime=20 -ac_nk=96,5 -earlytxid=810bd62fb8353fad20267ff2050684b8829affa3edf6b366633931530791dfce |
|||
|
|||
once the payments plan has been funded with the mined coinbase you can issue payments release when conditions of the plan are met to fund founders reward/rewards plan. eg. |
|||
./komodo-cli -ac_name=TESTHC paymentsrelease '["ee7765be874fb084c00538b1b0488e8ecb857de253f09a9ba6ea8d3579b77d33",500]' |
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -1,134 +1,134 @@ |
|||
// (C) 2018 Michael Toutonghi
|
|||
// Distributed under the MIT software license, see the accompanying
|
|||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|||
|
|||
/*
|
|||
This provides the PoW hash function for Verus, enabling CPU mining. |
|||
*/ |
|||
#ifndef VERUS_HASH_H_ |
|||
#define VERUS_HASH_H_ |
|||
|
|||
#include <cstring> |
|||
#include <vector> |
|||
|
|||
#include <cpuid.h> |
|||
|
|||
extern "C" |
|||
{ |
|||
#include "crypto/haraka.h" |
|||
#include "crypto/haraka_portable.h" |
|||
} |
|||
|
|||
class CVerusHash |
|||
{ |
|||
public: |
|||
static void Hash(void *result, const void *data, size_t len); |
|||
static void (*haraka512Function)(unsigned char *out, const unsigned char *in); |
|||
|
|||
static void init(); |
|||
|
|||
CVerusHash() { } |
|||
|
|||
CVerusHash &Write(const unsigned char *data, size_t len); |
|||
|
|||
CVerusHash &Reset() |
|||
{ |
|||
curBuf = buf1; |
|||
result = buf2; |
|||
curPos = 0; |
|||
std::fill(buf1, buf1 + sizeof(buf1), 0); |
|||
return *this; |
|||
} |
|||
|
|||
int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } |
|||
void ClearExtra() |
|||
{ |
|||
if (curPos) |
|||
{ |
|||
std::fill(curBuf + 32 + curPos, curBuf + 64, 0); |
|||
} |
|||
} |
|||
void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } |
|||
|
|||
void Finalize(unsigned char hash[32]) |
|||
{ |
|||
if (curPos) |
|||
{ |
|||
std::fill(curBuf + 32 + curPos, curBuf + 64, 0); |
|||
(*haraka512Function)(hash, curBuf); |
|||
} |
|||
else |
|||
std::memcpy(hash, curBuf, 32); |
|||
} |
|||
|
|||
private: |
|||
// only buf1, the first source, needs to be zero initialized
|
|||
unsigned char buf1[64] = {0}, buf2[64]; |
|||
unsigned char *curBuf = buf1, *result = buf2; |
|||
size_t curPos = 0; |
|||
}; |
|||
|
|||
class CVerusHashV2 |
|||
{ |
|||
public: |
|||
static void Hash(void *result, const void *data, size_t len); |
|||
static void (*haraka512Function)(unsigned char *out, const unsigned char *in); |
|||
|
|||
static void init(); |
|||
|
|||
CVerusHashV2() {} |
|||
|
|||
CVerusHashV2 &Write(const unsigned char *data, size_t len); |
|||
|
|||
CVerusHashV2 &Reset() |
|||
{ |
|||
curBuf = buf1; |
|||
result = buf2; |
|||
curPos = 0; |
|||
std::fill(buf1, buf1 + sizeof(buf1), 0); |
|||
return *this; |
|||
} |
|||
|
|||
int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } |
|||
void ClearExtra() |
|||
{ |
|||
if (curPos) |
|||
{ |
|||
std::fill(curBuf + 32 + curPos, curBuf + 64, 0); |
|||
} |
|||
} |
|||
void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } |
|||
|
|||
void Finalize(unsigned char hash[32]) |
|||
{ |
|||
if (curPos) |
|||
{ |
|||
std::fill(curBuf + 32 + curPos, curBuf + 64, 0); |
|||
(*haraka512Function)(hash, curBuf); |
|||
} |
|||
else |
|||
std::memcpy(hash, curBuf, 32); |
|||
} |
|||
|
|||
private: |
|||
// only buf1, the first source, needs to be zero initialized
|
|||
unsigned char buf1[64] = {0}, buf2[64]; |
|||
unsigned char *curBuf = buf1, *result = buf2; |
|||
size_t curPos = 0; |
|||
}; |
|||
|
|||
extern void verus_hash(void *result, const void *data, size_t len); |
|||
extern void verus_hash_v2(void *result, const void *data, size_t len); |
|||
|
|||
inline bool IsCPUVerusOptimized() |
|||
{ |
|||
unsigned int eax,ebx,ecx,edx; |
|||
|
|||
if (!__get_cpuid(1,&eax,&ebx,&ecx,&edx)) |
|||
{ |
|||
return false; |
|||
} |
|||
return ((ecx & (bit_AVX | bit_AES)) == (bit_AVX | bit_AES)); |
|||
}; |
|||
|
|||
#endif |
|||
// (C) 2018 Michael Toutonghi
|
|||
// Distributed under the MIT software license, see the accompanying
|
|||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|||
|
|||
/*
|
|||
This provides the PoW hash function for Verus, enabling CPU mining. |
|||
*/ |
|||
#ifndef VERUS_HASH_H_ |
|||
#define VERUS_HASH_H_ |
|||
|
|||
#include <cstring> |
|||
#include <vector> |
|||
|
|||
#include <cpuid.h> |
|||
|
|||
extern "C" |
|||
{ |
|||
#include "crypto/haraka.h" |
|||
#include "crypto/haraka_portable.h" |
|||
} |
|||
|
|||
class CVerusHash |
|||
{ |
|||
public: |
|||
static void Hash(void *result, const void *data, size_t len); |
|||
static void (*haraka512Function)(unsigned char *out, const unsigned char *in); |
|||
|
|||
static void init(); |
|||
|
|||
CVerusHash() { } |
|||
|
|||
CVerusHash &Write(const unsigned char *data, size_t len); |
|||
|
|||
CVerusHash &Reset() |
|||
{ |
|||
curBuf = buf1; |
|||
result = buf2; |
|||
curPos = 0; |
|||
std::fill(buf1, buf1 + sizeof(buf1), 0); |
|||
return *this; |
|||
} |
|||
|
|||
int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } |
|||
void ClearExtra() |
|||
{ |
|||
if (curPos) |
|||
{ |
|||
std::fill(curBuf + 32 + curPos, curBuf + 64, 0); |
|||
} |
|||
} |
|||
void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } |
|||
|
|||
void Finalize(unsigned char hash[32]) |
|||
{ |
|||
if (curPos) |
|||
{ |
|||
std::fill(curBuf + 32 + curPos, curBuf + 64, 0); |
|||
(*haraka512Function)(hash, curBuf); |
|||
} |
|||
else |
|||
std::memcpy(hash, curBuf, 32); |
|||
} |
|||
|
|||
private: |
|||
// only buf1, the first source, needs to be zero initialized
|
|||
unsigned char buf1[64] = {0}, buf2[64]; |
|||
unsigned char *curBuf = buf1, *result = buf2; |
|||
size_t curPos = 0; |
|||
}; |
|||
|
|||
class CVerusHashV2 |
|||
{ |
|||
public: |
|||
static void Hash(void *result, const void *data, size_t len); |
|||
static void (*haraka512Function)(unsigned char *out, const unsigned char *in); |
|||
|
|||
static void init(); |
|||
|
|||
CVerusHashV2() {} |
|||
|
|||
CVerusHashV2 &Write(const unsigned char *data, size_t len); |
|||
|
|||
CVerusHashV2 &Reset() |
|||
{ |
|||
curBuf = buf1; |
|||
result = buf2; |
|||
curPos = 0; |
|||
std::fill(buf1, buf1 + sizeof(buf1), 0); |
|||
return *this; |
|||
} |
|||
|
|||
int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } |
|||
void ClearExtra() |
|||
{ |
|||
if (curPos) |
|||
{ |
|||
std::fill(curBuf + 32 + curPos, curBuf + 64, 0); |
|||
} |
|||
} |
|||
void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } |
|||
|
|||
void Finalize(unsigned char hash[32]) |
|||
{ |
|||
if (curPos) |
|||
{ |
|||
std::fill(curBuf + 32 + curPos, curBuf + 64, 0); |
|||
(*haraka512Function)(hash, curBuf); |
|||
} |
|||
else |
|||
std::memcpy(hash, curBuf, 32); |
|||
} |
|||
|
|||
private: |
|||
// only buf1, the first source, needs to be zero initialized
|
|||
unsigned char buf1[64] = {0}, buf2[64]; |
|||
unsigned char *curBuf = buf1, *result = buf2; |
|||
size_t curPos = 0; |
|||
}; |
|||
|
|||
extern void verus_hash(void *result, const void *data, size_t len); |
|||
extern void verus_hash_v2(void *result, const void *data, size_t len); |
|||
|
|||
inline bool IsCPUVerusOptimized() |
|||
{ |
|||
unsigned int eax,ebx,ecx,edx; |
|||
|
|||
if (!__get_cpuid(1,&eax,&ebx,&ecx,&edx)) |
|||
{ |
|||
return false; |
|||
} |
|||
return ((ecx & (bit_AVX | bit_AES)) == (bit_AVX | bit_AES)); |
|||
}; |
|||
|
|||
#endif |
|||
|
@ -0,0 +1,2 @@ |
|||
#!/bin/bash |
|||
./komodo-cli -ac_name=K64 $1 $2 $3 $4 $5 $6 |
@ -0,0 +1,2 @@ |
|||
#!/bin/bash |
|||
./komodo-cli -ac_name=KOIN $1 $2 $3 $4 $5 $6 |
@ -1,2 +0,0 @@ |
|||
#!/bin/bash |
|||
./komodo-cli -ac_name=ZEX $1 $2 $3 $4 $5 $6 |
@ -0,0 +1,2 @@ |
|||
#!/bin/bash |
|||
./komodo-cli -ac_name=ZEXO $1 $2 $3 $4 $5 $6 |
@ -0,0 +1,268 @@ |
|||
// Copyright (c) 2010 Satoshi Nakamoto
|
|||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
|||
// Distributed under the MIT software license, see the accompanying
|
|||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2019 The SuperNET Developers. * |
|||
* * |
|||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * |
|||
* the top-level directory of this distribution for the individual copyright * |
|||
* holder information and the developer policies on copyright and licensing. * |
|||
* * |
|||
* Unless otherwise agreed in a custom licensing agreement, no part of the * |
|||
* SuperNET software, including this file may be copied, modified, propagated * |
|||
* or distributed except according to the terms contained in the LICENSE file * |
|||
* * |
|||
* Removal or modification of this copyright notice is prohibited. * |
|||
* * |
|||
******************************************************************************/ |
|||
|
|||
#include <stdexcept> |
|||
|
|||
#include "amount.h" |
|||
#include "chain.h" |
|||
#include "chainparams.h" |
|||
#include "checkpoints.h" |
|||
#include "crosschain.h" |
|||
#include "base58.h" |
|||
#include "consensus/validation.h" |
|||
#include "cc/eval.h" |
|||
#include "main.h" |
|||
#include "primitives/transaction.h" |
|||
#include "rpc/server.h" |
|||
#include "streams.h" |
|||
#include "sync.h" |
|||
#include "util.h" |
|||
#include "script/script.h" |
|||
#include "script/script_error.h" |
|||
#include "script/sign.h" |
|||
#include "script/standard.h" |
|||
|
|||
#include <stdint.h> |
|||
|
|||
#include <univalue.h> |
|||
|
|||
#include <regex> |
|||
|
|||
|
|||
#include "cc/CCinclude.h" |
|||
#include "cc/CCPrices.h" |
|||
|
|||
using namespace std; |
|||
|
|||
int32_t ensure_CCrequirements(uint8_t evalcode); |
|||
|
|||
UniValue test_ac(const UniValue& params, bool fHelp) |
|||
{ |
|||
// make fake token tx:
|
|||
struct CCcontract_info *cp, C; |
|||
|
|||
if (fHelp || (params.size() != 4)) |
|||
throw runtime_error("incorrect params\n"); |
|||
if (ensure_CCrequirements(EVAL_HEIR) < 0) |
|||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); |
|||
|
|||
std::vector<unsigned char> pubkey1; |
|||
std::vector<unsigned char> pubkey2; |
|||
|
|||
pubkey1 = ParseHex(params[0].get_str().c_str()); |
|||
pubkey2 = ParseHex(params[1].get_str().c_str()); |
|||
|
|||
CPubKey pk1 = pubkey2pk(pubkey1); |
|||
CPubKey pk2 = pubkey2pk(pubkey2); |
|||
|
|||
if (!pk1.IsValid() || !pk2.IsValid()) |
|||
throw runtime_error("invalid pubkey\n"); |
|||
|
|||
int64_t txfee = 10000; |
|||
int64_t amount = atoll(params[2].get_str().c_str()) * COIN; |
|||
uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); |
|||
|
|||
CPubKey myPubkey = pubkey2pk(Mypubkey()); |
|||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|||
|
|||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60); |
|||
|
|||
if (normalInputs < txfee + amount) |
|||
throw runtime_error("not enough normals\n"); |
|||
|
|||
mtx.vout.push_back(MakeCC1of2vout(EVAL_HEIR, amount, pk1, pk2)); |
|||
|
|||
CScript opret; |
|||
fundingtxid = revuint256(fundingtxid); |
|||
|
|||
opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'A' << fundingtxid << (uint8_t)0); |
|||
|
|||
cp = CCinit(&C, EVAL_HEIR); |
|||
return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); |
|||
} |
|||
|
|||
UniValue test_heirmarker(const UniValue& params, bool fHelp) |
|||
{ |
|||
// make fake token tx:
|
|||
struct CCcontract_info *cp, C; |
|||
|
|||
if (fHelp || (params.size() != 1)) |
|||
throw runtime_error("incorrect params\n"); |
|||
if (ensure_CCrequirements(EVAL_HEIR) < 0) |
|||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); |
|||
|
|||
uint256 fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); |
|||
|
|||
CPubKey myPubkey = pubkey2pk(Mypubkey()); |
|||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|||
|
|||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); |
|||
if (normalInputs < 10000) |
|||
throw runtime_error("not enough normals\n"); |
|||
|
|||
mtx.vin.push_back(CTxIn(fundingtxid, 1)); |
|||
mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey)); |
|||
|
|||
CScript opret; |
|||
fundingtxid = revuint256(fundingtxid); |
|||
|
|||
opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'C' << fundingtxid << (uint8_t)0); |
|||
|
|||
cp = CCinit(&C, EVAL_HEIR); |
|||
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret)); |
|||
} |
|||
|
|||
UniValue test_burntx(const UniValue& params, bool fHelp) |
|||
{ |
|||
// make fake token tx:
|
|||
struct CCcontract_info *cp, C; |
|||
|
|||
if (fHelp || (params.size() != 1)) |
|||
throw runtime_error("incorrect params\n"); |
|||
if (ensure_CCrequirements(EVAL_TOKENS) < 0) |
|||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); |
|||
|
|||
uint256 tokenid = Parseuint256((char *)params[0].get_str().c_str()); |
|||
|
|||
CPubKey myPubkey = pubkey2pk(Mypubkey()); |
|||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|||
|
|||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); |
|||
if (normalInputs < 10000) |
|||
throw runtime_error("not enough normals\n"); |
|||
|
|||
CPubKey burnpk = pubkey2pk(ParseHex(CC_BURNPUBKEY)); |
|||
|
|||
mtx.vin.push_back(CTxIn(tokenid, 0)); |
|||
mtx.vin.push_back(CTxIn(tokenid, 1)); |
|||
mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS, 1, burnpk)); |
|||
|
|||
std::vector<CPubKey> voutPubkeys; |
|||
voutPubkeys.push_back(burnpk); |
|||
|
|||
cp = CCinit(&C, EVAL_TOKENS); |
|||
|
|||
std::vector<uint8_t> vopret; |
|||
GetNonfungibleData(tokenid, vopret); |
|||
if (vopret.size() > 0) |
|||
cp->additionalTokensEvalcode2 = vopret.begin()[0]; |
|||
|
|||
uint8_t tokenpriv[33]; |
|||
char unspendableTokenAddr[64]; |
|||
CPubKey unspPk = GetUnspendable(cp, tokenpriv); |
|||
GetCCaddress(cp, unspendableTokenAddr, unspPk); |
|||
CCaddr2set(cp, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr); |
|||
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, EncodeTokenOpRet(tokenid, voutPubkeys, std::make_pair(0, vscript_t())))); |
|||
} |
|||
|
|||
UniValue test_proof(const UniValue& params, bool fHelp) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
std::vector<uint8_t>proof; |
|||
|
|||
if (fHelp || (params.size() != 2)) |
|||
throw runtime_error("incorrect params\n"); |
|||
|
|||
|
|||
proof = ParseHex(params[0].get_str()); |
|||
uint256 cointxid = Parseuint256((char *)params[1].get_str().c_str()); |
|||
|
|||
std::vector<uint256> txids; |
|||
|
|||
CMerkleBlock merkleBlock; |
|||
if (!E_UNMARSHAL(proof, ss >> merkleBlock)) { |
|||
result.push_back(Pair("error", "could not unmarshal proof")); |
|||
return result; |
|||
} |
|||
uint256 merkleRoot = merkleBlock.txn.ExtractMatches(txids); |
|||
|
|||
result.push_back(Pair("source_root", merkleRoot.GetHex())); |
|||
|
|||
for (int i = 0; i < txids.size(); i++) |
|||
std::cerr << "merkle block txid=" << txids[0].GetHex() << std::endl; |
|||
|
|||
|
|||
std::vector<bool> vMatches(txids.size()); |
|||
for (auto v : vMatches) v = true; |
|||
CPartialMerkleTree verifTree(txids, vMatches); |
|||
|
|||
result.push_back(Pair("verif_root", verifTree.ExtractMatches(txids).GetHex())); |
|||
|
|||
if (std::find(txids.begin(), txids.end(), cointxid) == txids.end()) { |
|||
fprintf(stderr, "invalid proof for this cointxid\n"); |
|||
} |
|||
|
|||
std::vector<uint256> vMerkleTree; |
|||
bool f; |
|||
::BuildMerkleTree(&f, txids, vMerkleTree); |
|||
|
|||
std::vector<uint256> vMerkleBranch = ::GetMerkleBranch(0, txids.size(), vMerkleTree); |
|||
|
|||
uint256 ourResult = SafeCheckMerkleBranch(zeroid, vMerkleBranch, 0); |
|||
result.push_back(Pair("SafeCheckMerkleBranch", ourResult.GetHex())); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
extern CScript prices_costbasisopret(uint256 bettxid, CPubKey mypk, int32_t height, int64_t costbasis); |
|||
UniValue test_pricesmarker(const UniValue& params, bool fHelp) |
|||
{ |
|||
// make fake token tx:
|
|||
struct CCcontract_info *cp, C; |
|||
|
|||
if (fHelp || (params.size() != 1)) |
|||
throw runtime_error("incorrect params\n"); |
|||
if (ensure_CCrequirements(EVAL_PRICES) < 0) |
|||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); |
|||
|
|||
uint256 bettxid = Parseuint256((char *)params[0].get_str().c_str()); |
|||
|
|||
cp = CCinit(&C, EVAL_PRICES); |
|||
CPubKey myPubkey = pubkey2pk(Mypubkey()); |
|||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|||
|
|||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); |
|||
if (normalInputs < 10000) |
|||
throw runtime_error("not enough normals\n"); |
|||
|
|||
mtx.vin.push_back(CTxIn(bettxid, 1)); |
|||
mtx.vout.push_back(CTxOut(1000, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG)); |
|||
|
|||
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, prices_costbasisopret(bettxid, myPubkey, 100, 100))); |
|||
} |
|||
|
|||
|
|||
static const CRPCCommand commands[] = |
|||
{ // category name actor (function) okSafeMode
|
|||
// --------------------- ------------------------ ----------------------- ----------
|
|||
|
|||
/* Not shown in help */ |
|||
{ "hidden", "test_ac", &test_ac, true }, |
|||
{ "hidden", "test_heirmarker", &test_heirmarker, true }, |
|||
{ "hidden", "test_proof", &test_proof, true }, |
|||
{ "hidden", "test_burntx", &test_burntx, true }, |
|||
{ "hidden", "test_pricesmarker", &test_pricesmarker, true } |
|||
}; |
|||
|
|||
void RegisterTesttransactionsRPCCommands(CRPCTable &tableRPC) |
|||
{ |
|||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) |
|||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); |
|||
} |
Loading…
Reference in new issue