Compare commits

...

25 Commits

Author SHA1 Message Date
MoneroOcean 2805366502 Fixed raven block prev hash calc 2020-12-09 01:15:42 +00:00
MoneroOcean 8e2572248d Fixed raven block prev hash calc 2020-12-09 00:39:02 +00:00
MoneroOcean 0fc0e0ac9f Fixed merkle root hash calc 2020-12-08 22:42:29 +00:00
MoneroOcean e4d961cd99 Fixed merkle root hash calc 2020-12-08 22:42:15 +00:00
MoneroOcean 18eedca1e9 constructNewRavenBlob fix 2020-12-07 02:14:52 +00:00
MoneroOcean a697f0fa32 Replaced deleted merkle-bitcoin repo 2020-12-01 17:14:59 +00:00
MoneroOcean bc501fcb4d Fixed extranonce location 2020-11-27 22:04:40 +00:00
MoneroOcean fb0443bb96 Fixed extranonce location 2020-11-27 21:45:46 +00:00
MoneroOcean 12829ba280 Fixed DERO function name 2020-11-04 04:55:17 +00:00
MoneroOcean 24da9926bb Draft implementation of Ravencoin utils 2020-11-01 22:22:07 +00:00
MoneroOcean 444a39c27e Draft implementation of Ravencoin utils 2020-11-01 22:17:48 +00:00
MoneroOcean 6abe65f623 Draft implementation of Ravencoin utils 2020-11-01 21:48:05 +00:00
MoneroOcean 28e4c7a24a Draft implementation of Ravencoin utils 2020-10-31 05:52:24 +00:00
MoneroOcean 9e7b4fdd70 Draft implementation of Ravencoin utils 2020-10-31 05:43:33 +00:00
MoneroOcean b0acdf6a9d Draft implementation of Ravencoin utils 2020-10-31 05:41:52 +00:00
MoneroOcean dc04c5a0dd Draft implementation of Ravencoin utils 2020-10-31 01:53:33 +00:00
MoneroOcean f9c6b2c328 Draft implementation of Ravencoin utils 2020-10-31 00:36:22 +00:00
MoneroOcean d12493f9a9 Draft implementation of Ravencoin utils 2020-10-30 23:12:01 +00:00
MoneroOcean 310fcd9d4a Draft implementation of Ravencoin utils 2020-10-30 22:42:24 +00:00
MoneroOcean e8b9ff4a9f Draft implementation of Ravencoin utils 2020-10-30 22:42:21 +00:00
MoneroOcean 7ed6c83421 Bitcoin based utils 2020-10-30 20:14:17 +00:00
MoneroOcean b0b5d48233 Bitcoin based utils 2020-10-30 20:05:09 +00:00
MoneroOcean a47a2b28cb Added new c29i algo 2020-09-04 03:12:05 +00:00
MoneroOcean e0ca290f87 Merge pull request #15 from italocoin-project/master
add ITALO cycle48
2020-08-14 09:37:13 -07:00
italo 9ca10b3cde add ITALO cycle48 2020-08-14 05:40:29 -04:00
8 changed files with 206 additions and 6 deletions
+180 -1
View File
@@ -1 +1,180 @@
module.exports = require('bindings')('cryptoforknote.node')
module.exports = require('bindings')('cryptoforknote.node');
const SHA3 = require('sha3');
const bignum = require('bignum');
const bitcoin = require('bitcoinjs-lib');
const varuint = require('varuint-bitcoin');
const crypto = require('crypto');
const fastMerkleRoot = require('merkle-lib/fastRoot');
const promise = require('promise');
const merklebitcoin = promise.denodeify(require('merkle-bitcoin'));
function scriptCompile(addrHash) {
return bitcoin.script.compile([
bitcoin.opcodes.OP_DUP,
bitcoin.opcodes.OP_HASH160,
addrHash,
bitcoin.opcodes.OP_EQUALVERIFY,
bitcoin.opcodes.OP_CHECKSIG
]);
}
function reverseBuffer(buff) {
let reversed = new Buffer(buff.length);
for (var i = buff.length - 1; i >= 0; i--) reversed[buff.length - i - 1] = buff[i];
return reversed;
}
function getMerkleRoot(rpcData, generateTxRaw) {
hashes = [ reverseBuffer(new Buffer(generateTxRaw, 'hex')).toString('hex') ];
rpcData.transactions.forEach(function (value) {
hashes.push(value.txid ? value.txid : value.hash);
});
if (hashes.length === 1) return hashes[0];
return Object.values(merklebitcoin(hashes))[2].root;
}
function txesHaveWitnessCommit(transactions) {
return (
transactions instanceof Array &&
transactions[0] &&
transactions[0].ins &&
transactions[0].ins instanceof Array &&
transactions[0].ins[0] &&
transactions[0].ins[0].witness &&
transactions[0].ins[0].witness instanceof Array &&
transactions[0].ins[0].witness.length > 0
);
}
function getMerkleRoot2(transactions) {
if (transactions.length === 0) return null;
const forWitness = txesHaveWitnessCommit(transactions);
const hashes = transactions.map(transaction => transaction.getHash(forWitness));
const hash256 = function (buffer) { return crypto.createHash('sha256').update(buffer).digest(); };
const rootHash = fastMerkleRoot(hashes, hash256);
return forWitness ? hash256(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
}
let last_epoch_number;
let last_seed_hash;
const diff1 = 0x00000000ff000000000000000000000000000000000000000000000000000000;
module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
const poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash;
let txCoinbase = new bitcoin.Transaction();
let bytesHeight;
{ // input for coinbase tx
let blockHeightSerial = rpcData.height.toString(16).length % 2 === 0 ?
rpcData.height.toString(16) :
'0' + rpcData.height.toString(16);
bytesHeight = Math.ceil((rpcData.height << 1).toString(2).length / 8);
const lengthDiff = blockHeightSerial.length/2 - bytesHeight;
for (let i = 0; i < lengthDiff; i++) blockHeightSerial = blockHeightSerial + '00';
const serializedBlockHeight = new Buffer.concat([
new Buffer('0' + bytesHeight, 'hex'),
reverseBuffer(new Buffer(blockHeightSerial, 'hex')),
new Buffer('00', 'hex') // OP_0
]);
txCoinbase.addInput(
// will be used for our reserved_offset extra_nonce
new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
0xFFFFFFFF, 0xFFFFFFFF,
new Buffer.concat([serializedBlockHeight, Buffer('CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC', 'hex')]) // 17 bytes
);
txCoinbase.addOutput(scriptCompile(poolAddrHash), Math.floor(rpcData.coinbasevalue));
if (rpcData.default_witness_commitment) {
txCoinbase.addOutput(new Buffer(rpcData.default_witness_commitment, 'hex'), 0);
}
}
const merkleRoot = getMerkleRoot(rpcData, txCoinbase.getHash().toString('hex'));
let header = new Buffer(80);
{ let position = 0;
header.writeUInt32BE(rpcData.height, position, 4); // height 42-46
header.write(rpcData.bits, position += 4, 4, 'hex'); // bits 47-50
header.writeUInt32BE(rpcData.curtime, position += 4, 4, 'hex'); // nTime 51-54
header.write(merkleRoot, position += 4, 32, 'hex'); // merkelRoot 55-87
header.write(rpcData.previousblockhash, position += 32, 32, 'hex'); // prevblockhash 88-120
header.writeUInt32BE(rpcData.version, position += 32, 4); // version 121-153
header = reverseBuffer(header);
}
let blob = new Buffer.concat([
header, // 80 bytes
new Buffer('AAAAAAAAAAAAAAAA', 'hex'), // 8 bytes
new Buffer('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', 'hex'), // 32 bytes
varuint.encode(rpcData.transactions.length + 1, new Buffer(varuint.encodingLength(rpcData.transactions.length + 1)), 0)
]);
const offset1 = blob.length;
blob = new Buffer.concat([ blob, new Buffer(txCoinbase.toHex(), 'hex') ]);
rpcData.transactions.forEach(function (value) {
blob = new Buffer.concat([ blob, new Buffer(value.data, 'hex') ]);
});
const EPOCH_LENGTH = 7500;
const epoch_number = Math.floor(rpcData.height / EPOCH_LENGTH);
if (last_epoch_number !== epoch_number) {
let sha3 = new SHA3.SHA3Hash(256);
if (last_epoch_number && last_epoch_number + 1 === epoch_number) {
last_seed_hash = sha3.update(last_seed_hash).digest();
} else {
last_seed_hash = new Buffer(32, 0);
for (let i = 0; i < epoch_number; i++) {
last_seed_hash = sha3.update(last_seed_hash).digest();
sha3.reset();
}
}
last_epoch_number = epoch_number;
}
const difficulty = parseFloat((diff1 / bignum(rpcData.target, 16).toNumber()).toFixed(9));
return {
blocktemplate_blob: blob.toString('hex'),
// reserved_offset to CCCCCC....
reserved_offset: offset1 + 4 /* txCoinbase.version */ + 1 /* vinLen */ + 32 /* hash */ + 4 /* index */ +
1 /* vScript len */ + 1 /* coinbase height len */ + bytesHeight + 1 /* trailing zero byte */,
seed_hash: last_seed_hash.toString('hex'),
difficulty: difficulty,
height: rpcData.height,
bits: rpcData.bits,
};
};
function update_merkle_root_hash(blob_in, blob_out) {
let offset = 80 + 8 + 32;
const nTransactions = varuint.decode(blob_in, offset);
offset += varuint.decode.bytes;
let transactions = [];
for (let i = 0; i < nTransactions; ++i) {
const tx = bitcoin.Transaction.fromBuffer(blob_in.slice(offset), true);
transactions.push(tx);
offset += tx.byteLength();
}
const rpcData = { transactions: transactions.slice(1) };
reverseBuffer(new Buffer(getMerkleRoot(rpcData, transactions[0].getHash().toString('hex')), 'hex')).copy(blob_out, 4 + 32);
};
module.exports.convertRavenBlob = function(blobBuffer) {
let header = blobBuffer.slice(0, 80);
update_merkle_root_hash(blobBuffer, header);
return reverseBuffer(crypto.createHash('sha256').update(header).digest());
};
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
update_merkle_root_hash(blockTemplate, blockTemplate);
nonceBuff.copy (blockTemplate, 80, 0, 8);
mixhashBuff.copy(blockTemplate, 88, 0, 32);
return blockTemplate;
};
module.exports.constructNewDeroBlob = function(blockTemplate, nonceBuff) {
nonceBuff.copy(blockTemplate, 39, 0, 4);
return blockTemplate;
};
+8 -2
View File
@@ -1,6 +1,6 @@
{
"name": "cryptoforknote-util",
"version": "8.1.1",
"version": "9.0.8",
"main": "cryptoforknote-util",
"author": {
"name": "LucasJones",
@@ -11,8 +11,14 @@
"url": "https://github.com/MoneroOcean/node-cryptoforknote-util.git"
},
"dependencies": {
"promise": "*",
"bindings": "*",
"nan": "^2.0.0"
"nan": "^2.0.0",
"bignum": "^0.13.1",
"sha3": "*",
"varuint-bitcoin": "^1.0.4",
"bitcoinjs-lib": "git+https://github.com/bitcoinjs/bitcoinjs-lib.git#533d6c2e6d0aa4111f7948b1c12003cf6ef83137",
"merkle-bitcoin": "git+https://github.com/CloudMining/merkle-bitcoin.git#ec00ae20ba60d444e150ead03c747695ddaa83a1"
},
"keywords": [
"cryptonight",
+4
View File
@@ -24,6 +24,10 @@ namespace crypto {
public:
uint32_t data[40];
};
POD_CLASS cycle48 {
public:
uint32_t data[48];
};
POD_CLASS hash {
char data[HASH_SIZE];
};
+1
View File
@@ -16,4 +16,5 @@ enum BLOB_TYPE {
BLOB_TYPE_CRYPTONOTE_XTNC = 9, // XTNC
BLOB_TYPE_CRYPTONOTE_TUBE = 10, // TUBE
BLOB_TYPE_CRYPTONOTE_XHV = 11, // Haven
BLOB_TYPE_CRYPTONOTE_XTA = 12, // ITALO
};
+3 -1
View File
@@ -494,13 +494,14 @@ namespace cryptonote
offshore::pricing_record pricing_record;
crypto::cycle cycle;
crypto::cycle40 cycle40;
crypto::cycle48 cycle48;
BEGIN_SERIALIZE()
VARINT_FIELD(major_version)
VARINT_FIELD(minor_version)
if (blob_type != BLOB_TYPE_FORKNOTE2) VARINT_FIELD(timestamp)
FIELD(prev_id)
if (blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(nonce8)
if (blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || blob_type == BLOB_TYPE_CRYPTONOTE_TUBE || blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(nonce8)
if (blob_type != BLOB_TYPE_FORKNOTE2) {
if (blob_type == BLOB_TYPE_AEON) {
FIELD(nonce)
@@ -513,6 +514,7 @@ namespace cryptonote
}
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTNC || blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO) FIELD(cycle)
if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40)
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48)
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) FIELD(pricing_record)
END_SERIALIZE()
@@ -475,7 +475,7 @@ namespace cryptonote
//---------------------------------------------------------------
bool get_block_hashing_blob(const block& b, blobdata& blob)
{
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_XTNC || b.blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || b.blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) {
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_XTNC || b.blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || b.blob_type == BLOB_TYPE_CRYPTONOTE_TUBE || b.blob_type == BLOB_TYPE_CRYPTONOTE_XTA) {
blob = t_serializable_object_to_blob(b.major_version);
blob.append(reinterpret_cast<const char*>(&b.minor_version), sizeof(b.minor_version));
blob.append(reinterpret_cast<const char*>(&b.timestamp), sizeof(b.timestamp));
@@ -490,7 +490,7 @@ namespace cryptonote
if (b.blob_type == BLOB_TYPE_CRYPTONOTE3) {
blob.append(reinterpret_cast<const char*>(&b.uncle), sizeof(b.uncle));
}
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || b.blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) {
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || b.blob_type == BLOB_TYPE_CRYPTONOTE_TUBE || b.blob_type == BLOB_TYPE_CRYPTONOTE_XTA) {
blob.append(reinterpret_cast<const char*>(&b.nonce8), sizeof(b.nonce8));
}
return true;
+6
View File
@@ -231,6 +231,12 @@ NAN_METHOD(construct_block_blob) { // (parentBlockTemplateBuffer, nonceBuffer, c
for (int i = 0; i < 40; i++ ) b.cycle40.data[i] = cycle->Get(isolate->GetCurrentContext(), i).ToLocalChecked()->NumberValue(isolate->GetCurrentContext()).ToChecked();
}
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) {
if (info.Length() != 4) return THROW_ERROR_EXCEPTION("You must provide 4 arguments.");
Local<Array> cycle = Local<Array>::Cast(info[3]);
for (int i = 0; i < 48; i++ ) b.cycle48.data[i] = cycle->Get(isolate->GetCurrentContext(), i).ToLocalChecked()->NumberValue(isolate->GetCurrentContext()).ToChecked();
}
if (!block_to_blob(b, output)) return THROW_ERROR_EXCEPTION("Failed to convert block to blob");
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
+2
View File
@@ -55,6 +55,7 @@ BLOB_SERIALIZER(crypto::chacha8_iv);
BLOB_SERIALIZER(crypto::hash);
BLOB_SERIALIZER(crypto::cycle);
BLOB_SERIALIZER(crypto::cycle40);
BLOB_SERIALIZER(crypto::cycle48);
BLOB_SERIALIZER(crypto::hash8);
BLOB_SERIALIZER(crypto::public_key);
BLOB_SERIALIZER(crypto::secret_key);
@@ -63,6 +64,7 @@ BLOB_SERIALIZER(crypto::key_image);
BLOB_SERIALIZER(crypto::signature);
VARIANT_TAG(debug_archive, crypto::cycle, "cycle");
VARIANT_TAG(debug_archive, crypto::cycle40, "cycle40");
VARIANT_TAG(debug_archive, crypto::cycle48, "cycle48");
VARIANT_TAG(debug_archive, crypto::hash, "hash");
VARIANT_TAG(debug_archive, crypto::hash8, "hash8");
VARIANT_TAG(debug_archive, crypto::public_key, "public_key");