Compare commits

...

66 Commits

Author SHA1 Message Date
MoneroOcean 4d15a85e70 GR support 2021-11-30 21:45:33 +00:00
MoneroOcean 494e6aa059 GR support 2021-11-30 16:27:45 +00:00
MoneroOcean 5d33cf7e90 GR support 2021-11-30 16:22:57 +00:00
MoneroOcean f4ff9bc8cb GR support 2021-11-30 16:12:59 +00:00
MoneroOcean acc0039b14 GR support 2021-11-30 07:07:19 +00:00
MoneroOcean 57d2f65800 GR support 2021-11-29 23:53:10 +00:00
MoneroOcean be85a60436 GR support 2021-11-28 20:28:29 +00:00
MoneroOcean 1f0941edd8 GR support 2021-11-28 20:22:49 +00:00
MoneroOcean 626fd45757 Haven 2.0 support 2021-11-18 15:41:29 +00:00
MoneroOcean dd7fc1aa05 Better source sync 2021-11-18 15:41:29 +00:00
Neil Coggins f5ccc22d2c updated to support Haven 2.0 (untested) 2021-11-18 15:41:29 +00:00
MoneroOcean 22f9cf0bca Merge pull request #17 from Ghost-ai-cpu/master
Boost compatibility fix
2021-08-25 15:50:24 -07:00
Ghost-ai-cpu 8f3052679a Merge pull request #1 from Ghost-ai-cpu/patch-1
Patch 1
2021-08-23 11:11:27 +05:30
Ghost-ai-cpu 0d0da4af7b Update portable_storage.h 2021-08-23 11:09:54 +05:30
MoneroOcean 3da08f4e74 Fixed tx version 2021-07-21 02:13:19 +00:00
MoneroOcean d9778fd1ef Fixed tx version 2021-07-21 02:13:01 +00:00
MoneroOcean f212be897e XHV fix 2021-07-20 20:27:23 +00:00
Neil Coggins d1a0cf9439 updated pricing record to support timestamps 2021-07-20 20:26:52 +00:00
MoneroOcean b402ceb37f Updated to new nan version 2021-07-20 17:23:14 +00:00
MoneroOcean f31a2751ab Added autolykos2 support 2021-07-20 04:27:04 +00:00
MoneroOcean af5a7c2186 Added new XHV fork support 2021-04-20 19:41:22 +00:00
Neil Coggins 916e440fb6 added support for xAssets 2021-04-09 13:28:04 +01:00
Neil Coggins bd305271cd added support for xAssets 2021-04-09 13:27:50 +01:00
Neil Coggins e86f0a8afd added support for xAssets 2021-04-09 13:27:12 +01:00
MoneroOcean 80b9b2be12 Eth draft support 2021-01-22 21:14:28 +00:00
MoneroOcean d405a871a4 Eth draft support 2021-01-22 21:07:24 +00:00
MoneroOcean de78291246 Eth draft support 2021-01-22 08:42:47 +00:00
MoneroOcean 04ba92e6fd Eth draft support 2021-01-22 08:38:27 +00:00
MoneroOcean 9021066354 Eth support 2021-01-22 05:55:16 +00:00
MoneroOcean 7c139874ce Removed extra debug output 2020-12-27 07:37:50 +00:00
MoneroOcean 58f8aeb67b Removed extra debug output 2020-12-11 16:16:22 +00:00
MoneroOcean 2c6f6e6dd2 Fixed raven block processing 2020-12-09 06:53:08 +00:00
MoneroOcean 8729782845 Fixed raven block processing 2020-12-09 04:26:14 +00:00
MoneroOcean df11d9c2bf Fixed raven block processing 2020-12-09 04:21:22 +00:00
MoneroOcean 9d722a83a3 Fixed raven block processing 2020-12-09 04:19:26 +00:00
MoneroOcean 16acb844d7 Fixed raven block processing 2020-12-09 04:19:15 +00:00
MoneroOcean 1647e8ccd6 Fixed raven block processing 2020-12-09 03:45:40 +00:00
MoneroOcean 95870f3f47 Fixed raven block processing 2020-12-09 03:07:40 +00:00
MoneroOcean f8941cbe83 Fixed raven block processing 2020-12-09 03:02:01 +00:00
MoneroOcean a0153d8eb3 Fixed raven block processing 2020-12-09 02:58:01 +00:00
MoneroOcean 3ddf060490 Fixed raven block prev hash calc 2020-12-09 01:44:45 +00:00
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
17 changed files with 1268 additions and 211 deletions
+219 -1
View File
@@ -1 +1,219 @@
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 rtm = require('cryptoforknote-util/rtm');
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 = Buffer.alloc(buff.length);
for (var i = buff.length - 1; i >= 0; i--) reversed[buff.length - i - 1] = buff[i];
return reversed;
}
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 sha256(buffer) {
return crypto.createHash('sha256').update(buffer).digest();
};
function hash256(buffer) {
return sha256(sha256(buffer));
};
function getMerkleRoot(transactions) {
if (transactions.length === 0) return Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
const forWitness = txesHaveWitnessCommit(transactions);
const hashes = transactions.map(transaction => transaction.getHash(forWitness));
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;
module.exports.baseDiff = function() {
return bignum('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 16);
};
module.exports.baseRavenDiff = function() {
return parseInt('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 = Buffer.concat([
Buffer.from('0' + bytesHeight, 'hex'),
reverseBuffer(Buffer.from(blockHeightSerial, 'hex')),
Buffer.from('00', 'hex') // OP_0
]);
txCoinbase.addInput(
// will be used for our reserved_offset extra_nonce
Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
0xFFFFFFFF, 0xFFFFFFFF,
Buffer.concat([serializedBlockHeight, Buffer.alloc(17, 0xCC)]) // 17 bytes
);
txCoinbase.addOutput(scriptCompile(poolAddrHash), Math.floor(rpcData.coinbasevalue));
if (rpcData.default_witness_commitment) {
txCoinbase.addOutput(Buffer.from(rpcData.default_witness_commitment, 'hex'), 0);
}
}
let header = Buffer.alloc(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('DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD', 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 = Buffer.concat([
header, // 80 bytes
Buffer.from('AAAAAAAAAAAAAAAA', 'hex'), // 8 bytes
Buffer.from('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', 'hex'), // 32 bytes
varuint.encode(rpcData.transactions.length + 1, Buffer.alloc(varuint.encodingLength(rpcData.transactions.length + 1)), 0)
]);
const offset1 = blob.length;
blob = Buffer.concat([ blob, Buffer.from(txCoinbase.toHex(), 'hex') ]);
rpcData.transactions.forEach(function (value) {
blob = Buffer.concat([ blob, Buffer.from(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 = Buffer.alloc(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((module.exports.baseRavenDiff() / 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,
prev_hash: rpcData.previousblockhash,
};
};
function update_merkle_root_hash(offset, payload, blob_in, blob_out) {
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, payload && i == 0);
transactions.push(tx);
offset += tx.byteLength();
}
getMerkleRoot(transactions).copy(blob_out, 4 + 32);
};
module.exports.convertRavenBlob = function(blobBuffer) {
let header = blobBuffer.slice(0, 80);
update_merkle_root_hash(80 + 8 + 32, false, blobBuffer, header);
return reverseBuffer(hash256(header));
};
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
update_merkle_root_hash(80 + 8 + 32, false, 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;
};
module.exports.EthBlockTemplate = function(rpcData) {
const difficulty = module.exports.baseDiff().div(bignum(rpcData[2].substr(2), 16)).toNumber();
return {
hash: rpcData[0].substr(2),
seed_hash: rpcData[1].substr(2),
difficulty: difficulty,
height: parseInt(rpcData[3])
};
};
module.exports.ErgBlockTemplate = function(rpcData) {
const difficulty = module.exports.baseDiff().div(bignum(rpcData.b)).toNumber();
return {
hash: rpcData.msg,
hash2: rpcData.pk,
difficulty: difficulty,
height: parseInt(rpcData.h)
};
};
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
return rtm.RtmBlockTemplate(rpcData, poolAddress);
};
module.exports.convertRtmBlob = function(blobBuffer) {
let header = blobBuffer.slice(0, 80);
update_merkle_root_hash(80, true, blobBuffer, header);
return header;
};
module.exports.constructNewRtmBlob = function(blockTemplate, nonceBuff) {
update_merkle_root_hash(80, true, blockTemplate, blockTemplate);
nonceBuff.copy(blockTemplate, 76, 0, 4);
return blockTemplate;
};
+10 -3
View File
@@ -1,6 +1,6 @@
{
"name": "cryptoforknote-util",
"version": "8.1.1",
"version": "11.0.0",
"main": "cryptoforknote-util",
"author": {
"name": "LucasJones",
@@ -8,11 +8,18 @@
},
"repository": {
"type": "git",
"url": "https://github.com/MoneroOcean/node-cryptoforknote-util.git"
"url": "https://github.com/haven-protocol-org/node-cryptoforknote-util.git"
},
"dependencies": {
"promise": "*",
"bindings": "*",
"nan": "^2.0.0"
"nan": "^2.14.2",
"bignum": "^0.13.1",
"sha3": "*",
"base58-native": "*",
"varuint-bitcoin": "^1.0.4",
"merkle-lib": "^2.0.10",
"bitcoinjs-lib": "git+https://github.com/MoneroOcean/bitcoinjs-lib.git"
},
"keywords": [
"cryptonight",
+266
View File
@@ -0,0 +1,266 @@
const bignum = require('bignum');
const base58 = require('base58-native');
const diff1 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
function reverseBuffer(buff) {
let reversed = Buffer.alloc(buff.length);
for (let i = buff.length - 1; i >= 0; i--) reversed[buff.length - i - 1] = buff[i];
return reversed;
}
function reverseByteOrder(buff) {
for (let i = 0; i < 8; i++) buff.writeUInt32LE(buff.readUInt32BE(i * 4), i * 4);
return reverseBuffer(buff);
}
function packInt32LE(num) {
let buff = Buffer.alloc(4);
buff.writeInt32LE(num, 0);
return buff;
}
function packInt32BE(num) {
let buff = Buffer.alloc(4);
buff.writeInt32BE(num, 0);
return buff;
}
function packUInt16LE(num) {
let buff = Buffer.alloc(2);
buff.writeUInt16LE(num, 0);
return buff;
}
function packUInt32LE(num) {
let buff = Buffer.alloc(4);
buff.writeUInt32LE(num, 0);
return buff;
}
function packUInt32BE(num) {
let buff = Buffer.alloc(4);
buff.writeUInt32BE(num, 0);
return buff;
}
function packInt64LE(num){
let buff = Buffer.alloc(8);
buff.writeUInt32LE(num % Math.pow(2, 32), 0);
buff.writeUInt32LE(Math.floor(num / Math.pow(2, 32)), 4);
return buff;
}
// Defined in bitcoin protocol here:
// https://en.bitcoin.it/wiki/Protocol_specification#Variable_length_integer
function varIntBuffer(n) {
if (n < 0xfd) {
return Buffer.from([n]);
} else if (n <= 0xffff) {
let buff = Buffer.alloc(3);
buff[0] = 0xfd;
buff.writeUInt16LE(n, 1);
return buff;
} else if (n <= 0xffffffff) {
let buff = Buffer.alloc(5);
buff[0] = 0xfe;
buff.writeUInt32LE(n, 1);
return buff;
} else{
let buff = Buffer.alloc(9);
buff[0] = 0xff;
packUInt16LE(n).copy(buff, 1);
return buff;
}
}
// "serialized CScript" formatting as defined here:
// https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki#specification
// Used to format height and date when putting into script signature:
// https://en.bitcoin.it/wiki/Script
function serializeNumber(n) {
// New version from TheSeven
if (n >= 1 && n <= 16) return Buffer.from([0x50 + n]);
var l = 1;
var buff = Buffer.alloc(9);
while (n > 0x7f) {
buff.writeUInt8(n & 0xff, l++);
n >>= 8;
}
buff.writeUInt8(l, 0);
buff.writeUInt8(n, l++);
return buff.slice(0, l);
}
// Used for serializing strings used in script signature
function serializeString(s) {
if (s.length < 253) {
return Buffer.concat([ Buffer.from([s.length]), Buffer.from(s) ]);
} else if (s.length < 0x10000) {
return Buffer.concat([ Buffer.from([253]), packUInt16LE(s.length), Buffer.from(s) ]);
} else if (s.length < 0x100000000) {
return Buffer.concat([ Buffer.from([254]), packUInt32LE(s.length), Buffer.from(s) ]);
} else {
return Buffer.concat([ Buffer.from([255]), packUInt16LE(s.length), Buffer.from(s) ]);
}
}
// An exact copy of python's range feature. Written by Tadeck:
// http://stackoverflow.com/a/8273091
function range(start, stop, step) {
if (typeof stop === 'undefined') {
stop = start;
start = 0;
}
if (typeof step === 'undefined') {
step = 1;
}
if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) {
return [];
}
let result = [];
for (let i = start; step > 0 ? i < stop : i > stop; i += step) {
result.push(i);
}
return result;
}
function uint256BufferFromHash(hex) {
let fromHex = Buffer.from(hex, 'hex');
if (fromHex.length != 32) {
let empty = Buffer.alloc(32);
empty.fill(0);
fromHex.copy(empty);
fromHex = empty;
}
return reverseBuffer(fromHex);
}
function getTransactionBuffers(txs) {
let txHashes = txs.map(function(tx) {
if (tx.txid !== undefined) {
return uint256BufferFromHash(tx.txid);
}
return uint256BufferFromHash(tx.hash);
});
return [null].concat(txHashes);
}
function addressToScript(addr) {
const decoded = base58.decode(addr);
if (decoded.length != 25) throw new Error('Invalid address length for ' + addr);
if (!decoded) throw new Error('Base58 decode failed for ' + addr);
const pubkey = decoded.slice(1, -4);
return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), pubkey, Buffer.from([0x88, 0xac])]);
}
function createOutputTransaction(amount, payee, rewardToPool, reward, txOutputBuffers, payeeScript) {
const payeeReward = amount;
if (!payeeScript) payeeScript = addressToScript(payee);
txOutputBuffers.push(Buffer.concat([
packInt64LE(payeeReward),
varIntBuffer(payeeScript.length),
payeeScript
]));
return { reward: reward - amount, rewardToPool: rewardToPool - amount };
}
function generateOutputTransactions(rpcData, poolAddress) {
let reward = rpcData.coinbasevalue;
let rewardToPool = reward;
let txOutputBuffers = [];
if (rpcData.smartnode) {
if (rpcData.smartnode.payee) {
const rewards = createOutputTransaction(rpcData.smartnode.amount, rpcData.smartnode.payee, rewardToPool, reward, txOutputBuffers);
reward = rewards.reward;
rewardToPool = rewards.rewardToPool;
} else if (Array.isArray(rpcData.smartnode)) {
for (let i in rpcData.smartnode) {
const rewards = createOutputTransaction(rpcData.smartnode[i].amount, rpcData.smartnode[i].payee, rewardToPool, reward, txOutputBuffers);
reward = rewards.reward;
rewardToPool = rewards.rewardToPool;
}
}
}
if (rpcData.superblock) {
for (let i in rpcData.superblock) {
const rewards = createOutputTransaction(rpcData.superblock[i].amount, rpcData.superblock[i].payee, rewardToPool, reward, txOutputBuffers);
reward = rewards.reward;
rewardToPool = rewards.rewardToPool;
}
}
if (rpcData.founder_payments_started && rpcData.founder) {
const founderReward = rpcData.founder.amount || 0;
const rewards = createOutputTransaction(founderReward, rpcData.founder.payee, rewardToPool, reward, txOutputBuffers);
reward = rewards.reward;
rewardToPool = rewards.rewardToPool;
}
createOutputTransaction(rewardToPool, null, rewardToPool, reward, txOutputBuffers, Buffer.from(addressToScript(poolAddress), "hex"));
if (rpcData.default_witness_commitment !== undefined) {
const witness_commitment = Buffer.from(rpcData.default_witness_commitment, 'hex');
txOutputBuffers.unshift(Buffer.concat([
packInt64LE(0),
varIntBuffer(witness_commitment.length),
witness_commitment
]));
}
return Buffer.concat([ varIntBuffer(txOutputBuffers.length), Buffer.concat(txOutputBuffers)]);
}
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
const extraNoncePlaceholderLength = 17;
const coinbaseVersion = Buffer.concat([packUInt16LE(3), packUInt16LE(5)]);
const scriptSigPart1 = Buffer.concat([
serializeNumber(rpcData.height),
Buffer.from(rpcData.coinbaseaux.flags, 'hex'),
serializeNumber(Date.now() / 1000 | 0),
Buffer.from([extraNoncePlaceholderLength])
]);
const scriptSigPart2 = serializeString('/nodeStratum/');
const blob1 = Buffer.concat([
coinbaseVersion,
// transaction input
varIntBuffer(1), // txInputsCount
uint256BufferFromHash(""), // txInPrevOutHash
packUInt32LE(Math.pow(2, 32) - 1), // txInPrevOutIndex
varIntBuffer(scriptSigPart1.length + extraNoncePlaceholderLength + scriptSigPart2.length),
scriptSigPart1
]);
let blob2 = Buffer.concat([
scriptSigPart2,
packUInt32LE(0), // txInSequence
// end transaction input
// transaction output
generateOutputTransactions(rpcData, poolAddress),
// end transaction ouput
packUInt32LE(0), // txLockTime
varIntBuffer(rpcData.coinbase_payload.length / 2),
Buffer.from(rpcData.coinbase_payload, 'hex')
]);
const version = packInt32LE(rpcData.version).toString('hex');
const curtime = packUInt32LE(rpcData.curtime).toString('hex');
let bits = Buffer.from(rpcData.bits, 'hex');
bits.writeUInt32LE(bits.readUInt32BE());
const txn = varIntBuffer(rpcData.transactions.length + 1);
return {
difficulty: parseFloat((diff1 / bignum(rpcData.target, 16).toNumber()).toFixed(9)),
height: rpcData.height,
prev_hash: rpcData.previousblockhash,
blocktemplate_blob: version + rpcData.previousblockhash + Buffer.alloc(32, 0).toString('hex') + curtime + bits.toString('hex') + Buffer.alloc(4, 0).toString('hex') +
txn.toString('hex') + blob1.toString('hex') + Buffer.alloc(extraNoncePlaceholderLength, 0xCC).toString('hex') + blob2.toString('hex') +
Buffer.concat(rpcData.transactions.map(function(tx) { return Buffer.from(tx.data, 'hex'); })).toString('hex'),
reserved_offset: 80 + txn.length + blob1.length
}
}
@@ -37,6 +37,7 @@
#include "portable_storage_val_converters.h"
#include "span.h"
#include "int-util.h"
#include <boost/mpl/contains.hpp>
namespace epee
{
+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];
};
+3
View File
@@ -2,6 +2,8 @@
#define CURRENT_TRANSACTION_VERSION 1
#define OFFSHORE_TRANSACTION_VERSION 3
#define HF_VERSION_XASSET_FEES_V2 17
#define HF_VERSION_HAVEN2 18
enum BLOB_TYPE {
BLOB_TYPE_CRYPTONOTE = 0,
@@ -16,4 +18,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
};
+43 -4
View File
@@ -81,6 +81,19 @@ namespace cryptonote
crypto::public_key key;
};
struct txout_xasset
{
txout_xasset() { }
txout_xasset(const crypto::public_key &_key, const std::string &_asset_type) : key(_key), asset_type(_asset_type) { }
crypto::public_key key;
std::string asset_type;
BEGIN_SERIALIZE_OBJECT()
FIELD(key)
FIELD(asset_type)
END_SERIALIZE()
};
/* inputs */
struct txin_gen
@@ -159,9 +172,24 @@ namespace cryptonote
END_SERIALIZE()
};
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore> txin_v;
struct txin_xasset
{
uint64_t amount;
std::string asset_type;
std::vector<uint64_t> key_offsets;
crypto::key_image k_image; // double spending protection
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore> txout_target_v;
BEGIN_SERIALIZE_OBJECT()
VARINT_FIELD(amount)
FIELD(asset_type)
FIELD(key_offsets)
FIELD(k_image)
END_SERIALIZE()
};
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset> txin_v;
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore, txout_xasset> txout_target_v;
//typedef std::pair<uint64_t, txout> out_t;
struct tx_out
@@ -245,7 +273,8 @@ namespace cryptonote
}
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV && version >= OFFSHORE_TRANSACTION_VERSION) {
VARINT_FIELD(pricing_record_height)
FIELD(offshore_data)
if (version < 5)
FIELD(offshore_data)
VARINT_FIELD(amount_burnt)
VARINT_FIELD(amount_minted)
}
@@ -321,6 +350,7 @@ namespace cryptonote
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 :
vin.size() > 0 && vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(vin[0]).key_offsets.size() - 1 :
vin.size() > 0 && vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(vin[0]).key_offsets.size() - 1 :
vin.size() > 0 && vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(vin[0]).key_offsets.size() - 1 :
0);
}
if (!r || !ar.stream().good()) return false;
@@ -372,6 +402,7 @@ namespace cryptonote
size_t operator()(const txin_to_key& txin) const {return txin.key_offsets.size();}
size_t operator()(const txin_offshore& txin) const {return txin.key_offsets.size();}
size_t operator()(const txin_onshore& txin) const {return txin.key_offsets.size();}
size_t operator()(const txin_xasset& txin) const {return txin.key_offsets.size();}
};
return boost::apply_visitor(txin_signature_size_visitor(), tx_in);
@@ -494,13 +525,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 +545,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()
@@ -610,10 +643,12 @@ VARIANT_TAG(binary_archive, cryptonote::txin_to_scripthash, 0x1);
VARIANT_TAG(binary_archive, cryptonote::txin_to_key, 0x2);
VARIANT_TAG(binary_archive, cryptonote::txin_offshore, 0x3);
VARIANT_TAG(binary_archive, cryptonote::txin_onshore, 0x4);
VARIANT_TAG(binary_archive, cryptonote::txin_xasset, 0x5);
VARIANT_TAG(binary_archive, cryptonote::txout_to_script, 0x0);
VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1);
VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2);
VARIANT_TAG(binary_archive, cryptonote::txout_offshore, 0x3);
VARIANT_TAG(binary_archive, cryptonote::txout_xasset, 0x5);
VARIANT_TAG(binary_archive, cryptonote::transaction, 0xcc);
VARIANT_TAG(binary_archive, cryptonote::block, 0xbb);
@@ -623,10 +658,12 @@ VARIANT_TAG(json_archive, cryptonote::txin_to_scripthash, "scripthash");
VARIANT_TAG(json_archive, cryptonote::txin_to_key, "key");
VARIANT_TAG(json_archive, cryptonote::txin_offshore, "offshore");
VARIANT_TAG(json_archive, cryptonote::txin_onshore, "onshore");
VARIANT_TAG(json_archive, cryptonote::txin_xasset, "xasset");
VARIANT_TAG(json_archive, cryptonote::txout_to_script, "script");
VARIANT_TAG(json_archive, cryptonote::txout_to_scripthash, "scripthash");
VARIANT_TAG(json_archive, cryptonote::txout_to_key, "key");
VARIANT_TAG(json_archive, cryptonote::txout_offshore, "offshore");
VARIANT_TAG(json_archive, cryptonote::txout_xasset, "xasset");
VARIANT_TAG(json_archive, cryptonote::transaction, "tx");
VARIANT_TAG(json_archive, cryptonote::block, "block");
@@ -636,9 +673,11 @@ VARIANT_TAG(debug_archive, cryptonote::txin_to_scripthash, "scripthash");
VARIANT_TAG(debug_archive, cryptonote::txin_to_key, "key");
VARIANT_TAG(debug_archive, cryptonote::txin_offshore, "offshore");
VARIANT_TAG(debug_archive, cryptonote::txin_onshore, "onshore");
VARIANT_TAG(debug_archive, cryptonote::txin_xasset, "xasset");
VARIANT_TAG(debug_archive, cryptonote::txout_to_script, "script");
VARIANT_TAG(debug_archive, cryptonote::txout_to_scripthash, "scripthash");
VARIANT_TAG(debug_archive, cryptonote::txout_to_key, "key");
VARIANT_TAG(debug_archive, cryptonote::txout_offshore, "offshore");
VARIANT_TAG(debug_archive, cryptonote::txout_xasset, "xasset");
VARIANT_TAG(debug_archive, cryptonote::transaction, "tx");
VARIANT_TAG(debug_archive, cryptonote::block, "block");
+76 -18
View File
@@ -85,15 +85,39 @@ namespace cryptonote
{
uint64_t amount_in = 0;
uint64_t amount_out = 0;
if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_XHV)
{
// This is the correct way to get the fee for Haven, because outs may be in different currencies to ins
switch (tx.version) {
case 5:
fee = tx.rct_signatures.txnFee + tx.rct_signatures.txnOffshoreFee;
break;
case 4:
case 3:
if (tx.vin[0].type() == typeid(txin_to_key)) {
fee = tx.rct_signatures.txnFee + tx.rct_signatures.txnOffshoreFee;
} else if (tx.vin[0].type() == typeid(txin_offshore)) {
fee = tx.rct_signatures.txnFee_usd + tx.rct_signatures.txnOffshoreFee_usd;
} else if (tx.vin[0].type() == typeid(txin_onshore)) {
fee = tx.rct_signatures.txnFee_usd + tx.rct_signatures.txnOffshoreFee_usd;
} else if (tx.vin[0].type() == typeid(txin_xasset)) {
fee = tx.rct_signatures.txnFee_xasset + tx.rct_signatures.txnOffshoreFee_xasset;
} else {
CHECK_AND_ASSERT_MES(false, false, "unexpected type id in transaction");
return false;
}
break;
case 2:
case 1:
fee = tx.rct_signatures.txnFee;
break;
}
return true;
}
BOOST_FOREACH(auto& in, tx.vin)
{
if (tx.blob_type != BLOB_TYPE_CRYPTONOTE_XHV) {
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), 0, "unexpected type id in transaction");
amount_in += boost::get<txin_to_key>(in).amount;
} else {
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_offshore) || in.type() == typeid(txin_onshore), 0, "unexpected type id in transaction");
amount_in += in.type() == typeid(txin_to_key) ? boost::get<txin_to_key>(in).amount : in.type() == typeid(txin_onshore) ? boost::get<txin_onshore>(in).amount : boost::get<txin_offshore>(in).amount;
}
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), 0, "unexpected type id in transaction");
amount_in += boost::get<txin_to_key>(in).amount;
}
BOOST_FOREACH(auto& o, tx.vout)
amount_out += o.amount;
@@ -245,9 +269,12 @@ namespace cryptonote
<< in.type().name() << ", expected " << typeid(txin_to_key).name()
<< ", in transaction id=" << get_transaction_hash(tx));
} else {
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_offshore) || in.type() == typeid(txin_onshore), false, "wrong variant type: "
<< in.type().name() << ", expected " << typeid(txin_to_key).name() << "or " << typeid(txin_onshore).name()
<< ", in transaction id=" << get_transaction_hash(tx));
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_offshore) || in.type() == typeid(txin_onshore) || in.type() == typeid(txin_xasset), false, "wrong variant type: "
<< in.type().name() << ", expected " << typeid(txin_to_key).name()
<< "or " << typeid(txin_offshore).name()
<< "or " << typeid(txin_onshore).name()
<< "or " << typeid(txin_xasset).name()
<< ", in transaction id=" << get_transaction_hash(tx));
}
}
return true;
@@ -262,10 +289,13 @@ namespace cryptonote
<< out.target.type().name() << ", expected " << typeid(txout_to_key).name()
<< ", in transaction id=" << get_transaction_hash(tx));
} else {
CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key) || out.target.type() == typeid(txout_offshore), false, "wrong variant type: "
<< out.target.type().name() << ", expected " << typeid(txout_to_key).name()
<< "or " << typeid(txout_offshore).name()
<< ", in transaction id=" << get_transaction_hash(tx));
CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key) ||
out.target.type() == typeid(txout_offshore) ||
out.target.type() == typeid(txout_xasset), false, "wrong variant type: "
<< out.target.type().name() << ", expected " << typeid(txout_to_key).name()
<< "or " << typeid(txout_offshore).name()
<< "or " << typeid(txout_xasset).name()
<< ", in transaction id=" << get_transaction_hash(tx));
}
if (tx.version == 1)
@@ -277,7 +307,9 @@ namespace cryptonote
if(!check_key(boost::get<txout_to_key>(out.target).key))
return false;
} else {
if(!check_key(out.target.type() == typeid(txout_to_key) ? boost::get<txout_to_key>(out.target).key : boost::get<txout_offshore>(out.target).key))
if(!check_key(out.target.type() == typeid(txout_to_key) ? boost::get<txout_to_key>(out.target).key :
out.target.type() == typeid(txout_offshore) ? boost::get<txout_offshore>(out.target).key :
boost::get<txout_xasset>(out.target).key))
return false;
}
}
@@ -294,7 +326,12 @@ namespace cryptonote
uint64_t money = 0;
BOOST_FOREACH(const auto& in, tx.vin)
{
if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_XHV && tx.vin[0].type() == typeid(txin_offshore)) {
if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_XHV && tx.vin[0].type() == typeid(txin_xasset)) {
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_xasset, tokey_in, false);
if(money > tokey_in.amount + money)
return false;
money += tokey_in.amount;
} else if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_XHV && tx.vin[0].type() == typeid(txin_offshore)) {
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_offshore, tokey_in, false);
if(money > tokey_in.amount + money)
return false;
@@ -325,6 +362,7 @@ namespace cryptonote
}
return true;
}
/*
//---------------------------------------------------------------
uint64_t get_outs_money_amount(const transaction& tx)
{
@@ -333,6 +371,25 @@ namespace cryptonote
outputs_amount += o.amount;
return outputs_amount;
}
*/
//---------------------------------------------------------------
std::map<std::string, uint64_t> get_outs_money_amount(const transaction& tx)
{
std::map<std::string, uint64_t> outputs_amount;
for(const auto& o: tx.vout) {
std::string asset_type;
if (o.target.type() == typeid(txout_offshore)) {
asset_type = "XUSD";
} else if (o.target.type() == typeid(txout_xasset)) {;
asset_type = boost::get<txout_xasset>(o.target).asset_type;
} else {
// this close covers miner tx and normal XHV ouputs.
asset_type = "XHV";
}
outputs_amount[asset_type] += o.amount;
}
return outputs_amount;
}
//---------------------------------------------------------------
std::string short_hash_str(const crypto::hash& h)
{
@@ -451,6 +508,7 @@ namespace cryptonote
t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 :
t.vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(t.vin[0]).key_offsets.size() - 1 :
t.vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(t.vin[0]).key_offsets.size() - 1 :
t.vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(t.vin[0]).key_offsets.size() - 1 :
0;
}
bool r = tt.rct_signatures.p.serialize_rctsig_prunable(ba, t.rct_signatures.type, inputs, outputs, mixin);
@@ -475,7 +533,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 +548,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;
@@ -85,7 +85,8 @@ namespace cryptonote
bool get_bytecoin_block_longhash(const block& blk, crypto::hash& res);
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b);
bool get_inputs_money_amount(const transaction& tx, uint64_t& money);
uint64_t get_outs_money_amount(const transaction& tx);
//uint64_t get_outs_money_amount(const transaction& tx);
std::map<std::string, uint64_t> get_outs_money_amount(const transaction& tx);
bool check_inputs_types_supported(const transaction& tx);
bool check_outs_valid(const transaction& tx);
+27
View File
@@ -32,12 +32,16 @@
#define TX_EXTRA_PADDING_MAX_COUNT 255
#define TX_EXTRA_NONCE_MAX_COUNT 255
#define TX_EXTRA_OFFSHORE_MAX_COUNT 255
#define TX_EXTRA_MEMO_MAX_COUNT 255
#define TX_EXTRA_TAG_PADDING 0x00
#define TX_EXTRA_TAG_PUBKEY 0x01
#define TX_EXTRA_NONCE 0x02
#define TX_EXTRA_MERGE_MINING_TAG 0x03
#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS 0x04
#define TX_EXTRA_TAG_OFFSHORE 0x17
#define TX_EXTRA_TAG_MEMO 0x18
#define TX_EXTRA_TAG_SERVICE_NODE_REGISTER 0x70
#define TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER 0x71
#define TX_EXTRA_TAG_SERVICE_NODE_WINNER 0x72
@@ -186,6 +190,25 @@ namespace cryptonote
END_SERIALIZE()
};
struct tx_extra_offshore
{
std::string data;
BEGIN_SERIALIZE()
FIELD(data)
END_SERIALIZE()
};
struct tx_extra_memo
{
// Actual memo data as string
std::string data;
BEGIN_SERIALIZE()
FIELD(data)
END_SERIALIZE()
};
struct tx_extra_service_node_winner
{
crypto::public_key m_service_node_key;
@@ -301,6 +324,8 @@ namespace cryptonote
tx_extra_merge_mining_tag,
tx_extra_additional_pub_keys,
tx_extra_mysterious_minergate,
tx_extra_offshore,
tx_extra_memo,
tx_extra_service_node_pubkey,
tx_extra_service_node_register,
tx_extra_service_node_contributor,
@@ -321,6 +346,8 @@ VARIANT_TAG(binary_archive, cryptonote::tx_extra_nonce, TX_EX
VARIANT_TAG(binary_archive, cryptonote::tx_extra_merge_mining_tag, TX_EXTRA_MERGE_MINING_TAG);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_additional_pub_keys, TX_EXTRA_TAG_ADDITIONAL_PUBKEYS);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_mysterious_minergate, TX_EXTRA_MYSTERIOUS_MINERGATE_TAG);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_offshore, TX_EXTRA_TAG_OFFSHORE);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_memo, TX_EXTRA_TAG_MEMO);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_register, TX_EXTRA_TAG_SERVICE_NODE_REGISTER);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_deregister, TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_contributor, TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR);
+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();
+143
View File
@@ -0,0 +1,143 @@
// Copyright (c) 2021, Haven Protocol
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <string>
#include <vector>
namespace offshore {
const std::vector<std::string> ASSET_TYPES = {"XHV", "XAG", "XAU", "XAUD", "XBTC", "XCAD", "XCHF", "XCNY", "XEUR", "XGBP", "XJPY", "XNOK", "XNZD", "XUSD"};
class asset_type_counts
{
public:
// Fields
uint64_t XHV;
uint64_t XAG;
uint64_t XAU;
uint64_t XAUD;
uint64_t XBTC;
uint64_t XCAD;
uint64_t XCHF;
uint64_t XCNY;
uint64_t XEUR;
uint64_t XGBP;
uint64_t XJPY;
uint64_t XNOK;
uint64_t XNZD;
uint64_t XUSD;
asset_type_counts() noexcept
: XHV(0)
, XAG(0)
, XAU(0)
, XAUD(0)
, XBTC(0)
, XCAD(0)
, XCHF(0)
, XCNY(0)
, XEUR(0)
, XGBP(0)
, XJPY(0)
, XNOK(0)
, XNZD(0)
, XUSD(0)
{
}
uint64_t operator[](const std::string asset_type) const noexcept
{
if (asset_type == "XHV") {
return XHV;
} else if (asset_type == "XUSD") {
return XUSD;
} else if (asset_type == "XAG") {
return XAG;
} else if (asset_type == "XAU") {
return XAU;
} else if (asset_type == "XAUD") {
return XAUD;
} else if (asset_type == "XBTC") {
return XBTC;
} else if (asset_type == "XCAD") {
return XCAD;
} else if (asset_type == "XCHF") {
return XCHF;
} else if (asset_type == "XCNY") {
return XCNY;
} else if (asset_type == "XEUR") {
return XEUR;
} else if (asset_type == "XGBP") {
return XGBP;
} else if (asset_type == "XJPY") {
return XJPY;
} else if (asset_type == "XNOK") {
return XNOK;
} else if (asset_type == "XNZD") {
return XNZD;
}
return 0;
}
void add(const std::string asset_type, const uint64_t val)
{
if (asset_type == "XHV") {
XHV += val;
} else if (asset_type == "XUSD") {
XUSD += val;
} else if (asset_type == "XAG") {
XAG += val;
} else if (asset_type == "XAU") {
XAU += val;
} else if (asset_type == "XAUD") {
XAUD += val;
} else if (asset_type == "XBTC") {
XBTC += val;
} else if (asset_type == "XCAD") {
XCAD += val;
} else if (asset_type == "XCHF") {
XCHF += val;
} else if (asset_type == "XCNY") {
XCNY += val;
} else if (asset_type == "XEUR") {
XEUR += val;
} else if (asset_type == "XGBP") {
XGBP += val;
} else if (asset_type == "XJPY") {
XJPY += val;
} else if (asset_type == "XNOK") {
XNOK += val;
} else if (asset_type == "XNZD") {
XNZD += val;
}
}
};
}
+162 -45
View File
@@ -29,20 +29,14 @@
#include "pricing_record.h"
#include <cstring>
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/ecdsa.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include <openssl/ssl.h>
#include "serialization/keyvalue_serialization.h"
#include "storages/portable_storage.h"
#include "string_tools.h"
#define PRICING_RECORD_VALID_BLOCKS 10
#define PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK 120 // seconds
namespace offshore
{
@@ -66,6 +60,7 @@ namespace offshore
uint64_t unused1;
uint64_t unused2;
uint64_t unused3;
uint64_t timestamp;
std::string signature;
BEGIN_KV_SERIALIZE_MAP()
@@ -85,6 +80,7 @@ namespace offshore
KV_SERIALIZE(unused1)
KV_SERIALIZE(unused2)
KV_SERIALIZE(unused3)
KV_SERIALIZE(timestamp)
KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP()
};
@@ -107,6 +103,7 @@ namespace offshore
, unused1(0)
, unused2(0)
, unused3(0)
, timestamp(0)
{
std::memset(signature, 0, sizeof(signature));
}
@@ -133,9 +130,10 @@ namespace offshore
unused1 = in.unused1;
unused2 = in.unused2;
unused3 = in.unused3;
timestamp = in.timestamp;
for (unsigned int i = 0; i < in.signature.length(); i += 2) {
std::string byteString = in.signature.substr(i, 2);
signature[i>>1] = (char) strtol(byteString.c_str(), NULL, 16);
std::string byteString = in.signature.substr(i, 2);
signature[i>>1] = (char) strtol(byteString.c_str(), NULL, 16);
}
return true;
}
@@ -152,7 +150,7 @@ namespace offshore
ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature[i]);
sig_hex += ss.str();
}
const pr_serialized out{xAG,xAU,xAUD,xBTC,xCAD,xCHF,xCNY,xEUR,xGBP,xJPY,xNOK,xNZD,xUSD,unused1,unused2,unused3,sig_hex};
const pr_serialized out{xAG,xAU,xAUD,xBTC,xCAD,xCHF,xCNY,xEUR,xGBP,xJPY,xNOK,xNZD,xUSD,unused1,unused2,unused3,timestamp,sig_hex};
return out.store(dest, hparent);
}
@@ -173,6 +171,7 @@ namespace offshore
, unused1(orig.unused1)
, unused2(orig.unused2)
, unused3(orig.unused3)
, timestamp(orig.timestamp)
{
std::memcpy(signature, orig.signature, sizeof(signature));
}
@@ -195,10 +194,46 @@ namespace offshore
unused1 = orig.unused1;
unused2 = orig.unused2;
unused3 = orig.unused3;
timestamp = orig.timestamp;
::memcpy(signature, orig.signature, sizeof(signature));
return *this;
}
uint64_t pricing_record::operator[](const std::string& asset_type) const
{
if (asset_type == "XHV") {
return 1000000000000;
} else if (asset_type == "XUSD") {
return unused1;
} else if (asset_type == "XAG") {
return xAG;
} else if (asset_type == "XAU") {
return xAU;
} else if (asset_type == "XAUD") {
return xAUD;
} else if (asset_type == "XBTC") {
return xBTC;
} else if (asset_type == "XCAD") {
return xCAD;
} else if (asset_type == "XCHF") {
return xCHF;
} else if (asset_type == "XCNY") {
return xCNY;
} else if (asset_type == "XEUR") {
return xEUR;
} else if (asset_type == "XGBP") {
return xGBP;
} else if (asset_type == "XJPY") {
return xJPY;
} else if (asset_type == "XNOK") {
return xNOK;
} else if (asset_type == "XNZD") {
return xNZD;
} else {
CHECK_AND_ASSERT_THROW_MES(false, "Asset type doesn't exist in pricing record!");
}
}
bool pricing_record::equal(const pricing_record& other) const noexcept
{
return ((xAG == other.xAG) &&
@@ -217,19 +252,50 @@ namespace offshore
(unused1 == other.unused1) &&
(unused2 == other.unused2) &&
(unused3 == other.unused3) &&
(timestamp == other.timestamp) &&
!::memcmp(signature, other.signature, sizeof(signature)));
}
bool pricing_record::verifySignature() const noexcept
bool pricing_record::empty() const noexcept
{
// Sanity check - accept empty pricing records
unsigned char test_sig[64];
std::memset(test_sig, 0, sizeof(test_sig));
if (std::memcmp(test_sig, signature, sizeof(signature)) == 0) {
return true;
}
const pricing_record empty_pr = offshore::pricing_record();
return (*this).equal(empty_pr);
}
bool pricing_record::verifySignature() const
{
// Oracle public keys
std::string const mainnet_public_key = "-----BEGIN PUBLIC KEY-----\n"
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE5YBxWx1AZCA9jTUk8Pr2uZ9jpfRt\n"
"KWv3Vo1/Gny+1vfaxsXhBQiG1KlHkafNGarzoL0WHW4ocqaaqF5iv8i35A==\n"
"-----END PUBLIC KEY-----\n";
std::string const testnet_public_key = "-----BEGIN PUBLIC KEY-----\n"
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtWqvQh7OdXrdgXcDeBMRVfLWTW3F\n"
"wByeoVJFBfZymScJIJl46j66xG6ngnyj4ai4/QPFnSZ1I9jjMRlTWC4EPA==\n"
"-----END PUBLIC KEY-----\n";
std::string const stagenet_public_key = "-----BEGIN PUBLIC KEY-----\n"
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtWqvQh7OdXrdgXcDeBMRVfLWTW3F\n"
"wByeoVJFBfZymScJIJl46j66xG6ngnyj4ai4/QPFnSZ1I9jjMRlTWC4EPA==\n"
"-----END PUBLIC KEY-----\n";
// Comment out all but 1 of the following lines to select the correct Oracle PK
std::string const public_key = mainnet_public_key;
//std::string const public_key = testnet_public_key;
//std::string const public_key = stagenet_public_key;
CHECK_AND_ASSERT_THROW_MES(!public_key.empty(), "Pricing record verification failed. NULL public key. PK Size: " << public_key.size()); // TODO: is this necessary or the one below already covers this case, meannin it will produce empty pubkey?
// extract the key
EVP_PKEY* pubkey;
BIO* bio = BIO_new_mem_buf(public_key.c_str(), public_key.size());
if (!bio) {
return false;
}
pubkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL);
BIO_free(bio);
CHECK_AND_ASSERT_THROW_MES(pubkey != NULL, "Pricing record verification failed. NULL public key.");
// Convert our internal 64-byte binary representation into 128-byte hex string
std::string sig_hex;
for (unsigned int i=0; i<64; i++) {
@@ -284,6 +350,8 @@ namespace offshore
oss << ",\"unused1\":" << unused1;
oss << ",\"unused2\":" << unused2;
oss << ",\"unused3\":" << unused3;
if (timestamp > 0)
oss << ",\"timestamp\":" << timestamp;
oss << "}";
std::string message = oss.str();
@@ -295,39 +363,24 @@ namespace offshore
compact += (byte);
}
// HERE BE DRAGONS!!!
// NEAC: the public key should be in a file
static const char public_key[] = "-----BEGIN PUBLIC KEY-----\n"
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE5YBxWx1AZCA9jTUk8Pr2uZ9jpfRt\n"
"KWv3Vo1/Gny+1vfaxsXhBQiG1KlHkafNGarzoL0WHW4ocqaaqF5iv8i35A==\n"
"-----END PUBLIC KEY-----\n";
// LAND AHOY!!!
// Grab the public key and make it usable
BIO* bio = BIO_new_mem_buf(public_key, (int)sizeof(public_key));
assert(bio != NULL);
EVP_PKEY* pubkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL);
BIO_free(bio);
assert(pubkey != NULL);
// Create a verify digest from the message
EVP_MD_CTX *ctx = EVP_MD_CTX_create();
int ret = 0;
if (ctx) {
ret=EVP_DigestVerifyInit(ctx, NULL, EVP_sha256(), NULL, pubkey);
ret = EVP_DigestVerifyInit(ctx, NULL, EVP_sha256(), NULL, pubkey);
if (ret == 1) {
ret=EVP_DigestVerifyUpdate(ctx, message.data(), message.length());
if (ret == 1) {
ret=EVP_DigestVerifyFinal(ctx, (const unsigned char *)compact.data(), compact.length());
}
ret = EVP_DigestVerifyUpdate(ctx, message.data(), message.length());
if (ret == 1) {
ret = EVP_DigestVerifyFinal(ctx, (const unsigned char *)compact.data(), compact.length());
}
}
}
// Cleanup the context we created
EVP_MD_CTX_destroy(ctx);
// Cleanup the openssl stuff
EVP_PKEY_free(pubkey);
if (ret == 1)
return true;
@@ -336,4 +389,68 @@ namespace offshore
return false;
}
}
void pricing_record::set_for_height_821428() {
const std::string pr_821428 = "9b3f6f2f8f0000003d620e1202000000be71be2555120000b8627010000000000000000000000000ea0885b2270d00000000000000000000f797ff9be00b0000ddbdb005270a0000fc90cfe02b01060000000000000000000000000000000000d0a28224000e000000d643be960e0000002e8bb6a40e000000f8a817f80d00002f5d27d45cdbfbac3d0f6577103f68de30895967d7562fbd56c161ae90130f54301b1ea9d5fd062f37dac75c3d47178bc6f149d21da1ff0e8430065cb762b93a";
this->xAG = 614976143259;
this->xAU = 8892867133;
this->xAUD = 20156914758078;
this->xBTC = 275800760;
this->xCAD = 0;
this->xCHF = 14464149948650;
this->xCNY = 0;
this->xEUR = 13059317798903;
this->xGBP = 11162715471325;
this->xJPY = 1690137827184892;
this->xNOK = 0;
this->xNZD = 0;
this->xUSD = 15393775330000;
this->unused1 = 16040600000000;
this->unused2 = 16100600000000;
this->unused3 = 15359200000000;
this->timestamp = 0;
std::string sig = "2f5d27d45cdbfbac3d0f6577103f68de30895967d7562fbd56c161ae90130f54301b1ea9d5fd062f37dac75c3d47178bc6f149d21da1ff0e8430065cb762b93a";
int j=0;
for (unsigned int i = 0; i < sig.size(); i += 2) {
std::string byteString = sig.substr(i, 2);
this->signature[j++] = (char) strtol(byteString.c_str(), NULL, 16);
}
}
// overload for pr validation for block
bool pricing_record::valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const
{
// check for empty pr
if (hf_version >= HF_VERSION_XASSET_FEES_V2) {
if (this->empty())
return true;
} else {
unsigned char test_sig[64];
std::memset(test_sig, 0, sizeof(test_sig));
if (std::memcmp(test_sig, this->signature, sizeof(this->signature)) == 0) {
return true;
}
}
// verify the signature
if (!verifySignature()) {
LOG_ERROR("Invalid pricing record signature.");
return false;
}
// valiadte the timestmap
if (hf_version >= HF_VERSION_XASSET_FEES_V2) {
if (this->timestamp > bl_timestamp + PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK) {
LOG_ERROR("Pricing record timestamp is too far in the future.");
return false;
}
if (this->timestamp <= last_bl_timestamp) {
LOG_ERROR("Pricing record timestamp is too old.");
return false;
}
}
return true;
}
}
+112 -27
View File
@@ -30,7 +30,21 @@
#pragma once
#include "common/pod-class.h"
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/ecdsa.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include <openssl/ssl.h>
#include <cstdint>
#include <string>
#include <cstring>
#include "cryptonote_config.h"
#include "crypto/hash.h"
namespace epee
{
@@ -69,9 +83,61 @@ namespace offshore
class pricing_record
{
public:
public:
// Fields
// Fields
uint64_t xAG;
uint64_t xAU;
uint64_t xAUD;
uint64_t xBTC;
uint64_t xCAD;
uint64_t xCHF;
uint64_t xCNY;
uint64_t xEUR;
uint64_t xGBP;
uint64_t xJPY;
uint64_t xNOK;
uint64_t xNZD;
uint64_t xUSD;
uint64_t unused1;
uint64_t unused2;
uint64_t unused3;
uint64_t timestamp;
unsigned char signature[64];
// Default c'tor
pricing_record() noexcept;
//! Load from epee p2p format
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
//! Store in epee p2p format
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
pricing_record(const pricing_record& orig) noexcept;
~pricing_record() = default;
void set_for_height_821428();
bool equal(const pricing_record& other) const noexcept;
bool empty() const noexcept;
bool verifySignature() const;
bool valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const;
pricing_record& operator=(const pricing_record& orig) noexcept;
uint64_t operator[](const std::string& asset_type) const;
};
inline bool operator==(const pricing_record& a, const pricing_record& b) noexcept
{
return a.equal(b);
}
inline bool operator!=(const pricing_record& a, const pricing_record& b) noexcept
{
return !a.equal(b);
}
// did not have a timestamp
class pricing_record_v1
{
public:
uint64_t xAG;
uint64_t xAU;
uint64_t xAUD;
@@ -90,31 +156,50 @@ namespace offshore
uint64_t unused3;
unsigned char signature[64];
// Default c'tor
pricing_record() noexcept;
//! Load from epee p2p format
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
//! Store in epee p2p format
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
pricing_record(const pricing_record& orig) noexcept;
~pricing_record() = default;
pricing_record& operator=(const pricing_record& orig) noexcept;
bool equal(const pricing_record& other) const noexcept;
bool write_to_pr(offshore::pricing_record &pr)
{
pr.xAG = xAG;
pr.xAU = xAU;
pr.xAUD = xAUD;
pr.xBTC = xBTC;
pr.xCAD = xCAD;
pr.xCHF = xCHF;
pr.xCNY = xCNY;
pr.xEUR = xEUR;
pr.xGBP = xGBP;
pr.xJPY = xJPY;
pr.xNOK = xNOK;
pr.xNZD = xNZD;
pr.xUSD = xUSD;
pr.unused1 = unused1;
pr.unused2 = unused2;
pr.unused3 = unused3;
pr.timestamp = 0;
::memcpy(pr.signature, signature, sizeof(pr.signature));
return true;
};
bool verifySignature() const noexcept;
bool read_from_pr(offshore::pricing_record &pr)
{
xAG = pr.xAG;
xAU = pr.xAU;
xAUD = pr.xAUD;
xBTC = pr.xBTC;
xCAD = pr.xCAD;
xCHF = pr.xCHF;
xCNY = pr.xCNY;
xEUR = pr.xEUR;
xGBP = pr.xGBP;
xJPY = pr.xJPY;
xNOK = pr.xNOK;
xNZD = pr.xNZD;
xUSD = pr.xUSD;
unused1 = pr.unused1;
unused2 = pr.unused2;
unused3 = pr.unused3;
::memcpy(signature, pr.signature, sizeof(signature));
return true;
};
};
inline bool operator==(const pricing_record& a, const pricing_record& b) noexcept
{
return a.equal(b);
}
inline bool operator!=(const pricing_record& a, const pricing_record& b) noexcept
{
return !a.equal(b);
}
} // offshore
} // offshore
+149 -99
View File
@@ -48,6 +48,7 @@ extern "C" {
#include "hex.h"
#include "span.h"
#include "memwipe.h"
#include "serialization/vector.h"
#include "serialization/debug_archive.h"
#include "serialization/binary_archive.h"
@@ -106,6 +107,8 @@ namespace rct {
key L;
key R;
key ki;
~multisig_kLRki() { memwipe(&k, sizeof(k)); }
};
struct multisig_out {
@@ -254,6 +257,8 @@ namespace rct {
RCTTypeBulletproof = 3,
RCTTypeBulletproof2 = 4,
RCTTypeCLSAG = 5,
RCTTypeCLSAGN = 6,
RCTTypeHaven2 = 7, // Add public mask sum terms, remove extraneous fields (txnFee_usd,txnFee_xasset,txnOffshoreFee_usd,txnOffshoreFee_xasset)
};
enum RangeProofType { RangeProofBorromean, RangeProofBulletproof, RangeProofMultiOutputBulletproof, RangeProofPaddedBulletproof };
struct RCTConfig {
@@ -261,113 +266,158 @@ namespace rct {
int bp_version;
};
struct rctSigBase {
uint8_t type;
key message;
ctkeyM mixRing; //the set of all pubkeys / copy
//pairs that you mix with
keyV pseudoOuts; //C - for simple rct
std::vector<ecdhTuple> ecdhInfo;
ctkeyV outPk;
ctkeyV outPk_usd;
xmr_amount txnFee; // contains b
xmr_amount txnFee_usd;
xmr_amount txnOffshoreFee;
xmr_amount txnOffshoreFee_usd;
uint8_t type;
key message;
ctkeyM mixRing; //the set of all pubkeys / copy
//pairs that you mix with
keyV pseudoOuts; //C - for simple rct
std::vector<ecdhTuple> ecdhInfo;
ctkeyV outPk;
ctkeyV outPk_usd;
ctkeyV outPk_xasset;
xmr_amount txnFee = 0; // contains b
xmr_amount txnFee_usd = 0;
xmr_amount txnFee_xasset = 0;
xmr_amount txnOffshoreFee = 0;
xmr_amount txnOffshoreFee_usd = 0;
xmr_amount txnOffshoreFee_xasset = 0;
keyV maskSums; // contains 2 elements. 1. is the sum of masks of inputs. 2. is the sum of masks of changes.
template<bool W, template <bool> class Archive>
bool serialize_rctsig_base(Archive<W> &ar, size_t inputs, size_t outputs)
template<bool W, template <bool> class Archive>
bool serialize_rctsig_base(Archive<W> &ar, size_t inputs, size_t outputs)
{
FIELD(type)
if (type == RCTTypeNull)
return ar.stream().good();
if (type != RCTTypeFull && type != RCTTypeSimple && type != RCTTypeBulletproof && type != RCTTypeBulletproof2 && type != RCTTypeCLSAG && type != RCTTypeCLSAGN && type != RCTTypeHaven2)
return false;
VARINT_FIELD(txnFee)
if (type == RCTTypeHaven2) {
// serialize offshore fee
VARINT_FIELD(txnOffshoreFee)
} else if (type == RCTTypeCLSAG || type == RCTTypeCLSAGN) {
VARINT_FIELD(txnFee_usd)
if (type == RCTTypeCLSAGN)
{
VARINT_FIELD(txnFee_xasset)
}
VARINT_FIELD(txnOffshoreFee)
VARINT_FIELD(txnOffshoreFee_usd)
if (type == RCTTypeCLSAGN)
{
VARINT_FIELD(txnOffshoreFee_xasset)
}
} else {
txnFee_usd = 0;
txnFee_xasset = 0;
txnOffshoreFee = 0;
txnOffshoreFee_usd = 0;
txnOffshoreFee_xasset = 0;
}
// inputs/outputs not saved, only here for serialization help
// FIELD(message) - not serialized, it can be reconstructed
// FIELD(mixRing) - not serialized, it can be reconstructed
if (type == RCTTypeSimple) // moved to prunable with bulletproofs
{
FIELD(type)
if (type == RCTTypeNull)
return ar.stream().good();
if (type != RCTTypeFull && type != RCTTypeSimple && type != RCTTypeBulletproof && type != RCTTypeBulletproof2 && type != RCTTypeCLSAG)
ar.tag("pseudoOuts");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(inputs, pseudoOuts);
if (pseudoOuts.size() != inputs)
return false;
VARINT_FIELD(txnFee)
if (type == RCTTypeCLSAG)
for (size_t i = 0; i < inputs; ++i)
{
VARINT_FIELD(txnFee_usd)
VARINT_FIELD(txnOffshoreFee)
VARINT_FIELD(txnOffshoreFee_usd)
} else {
txnFee_usd = 0;
txnOffshoreFee = 0;
txnOffshoreFee_usd = 0;
}
// inputs/outputs not saved, only here for serialization help
// FIELD(message) - not serialized, it can be reconstructed
// FIELD(mixRing) - not serialized, it can be reconstructed
if (type == RCTTypeSimple) // moved to prunable with bulletproofs
FIELDS(pseudoOuts[i])
if (inputs - i > 1)
ar.delimit_array();
}
ar.end_array();
}
ar.tag("ecdhInfo");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, ecdhInfo);
if (ecdhInfo.size() != outputs)
return false;
for (size_t i = 0; i < outputs; ++i)
{
if (type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2)
{
ar.tag("pseudoOuts");
ar.begin_object();
if (!typename Archive<W>::is_saving())
memset(ecdhInfo[i].amount.bytes, 0, sizeof(ecdhInfo[i].amount.bytes));
crypto::hash8 &amount = (crypto::hash8&)ecdhInfo[i].amount;
FIELD(amount);
ar.end_object();
}
else
{
FIELDS(ecdhInfo[i])
}
if (outputs - i > 1)
ar.delimit_array();
}
ar.end_array();
ar.tag("outPk");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, outPk);
if (outPk.size() != outputs)
return false;
for (size_t i = 0; i < outputs; ++i)
{
FIELDS(outPk[i].mask)
if (outputs - i > 1)
ar.delimit_array();
}
ar.end_array();
if (type == RCTTypeHaven2) {
ar.tag("maskSums");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(2, maskSums);
if (maskSums.size() != 2)
return false;
FIELDS(maskSums[0])
ar.delimit_array();
FIELDS(maskSums[1])
ar.end_array();
} else {
if ((type == RCTTypeCLSAG) || (type == RCTTypeCLSAGN))
{
ar.tag("outPk_usd");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(inputs, pseudoOuts);
if (pseudoOuts.size() != inputs)
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, outPk_usd);
if (outPk_usd.size() != outputs)
return false;
for (size_t i = 0; i < inputs; ++i)
for (size_t i = 0; i < outputs; ++i)
{
FIELDS(pseudoOuts[i])
if (inputs - i > 1)
ar.delimit_array();
FIELDS(outPk_usd[i].mask)
if (outputs - i > 1)
ar.delimit_array();
}
ar.end_array();
}
ar.tag("ecdhInfo");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, ecdhInfo);
if (ecdhInfo.size() != outputs)
return false;
for (size_t i = 0; i < outputs; ++i)
if (type == RCTTypeCLSAGN)
{
if (type == RCTTypeBulletproof2 || type == RCTTypeCLSAG)
ar.tag("outPk_xasset");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, outPk_xasset);
if (outPk_xasset.size() != outputs)
return false;
for (size_t i = 0; i < outputs; ++i)
{
ar.begin_object();
if (!typename Archive<W>::is_saving())
memset(ecdhInfo[i].amount.bytes, 0, sizeof(ecdhInfo[i].amount.bytes));
crypto::hash8 &amount = (crypto::hash8&)ecdhInfo[i].amount;
FIELD(amount);
ar.end_object();
FIELDS(outPk_xasset[i].mask)
if (outputs - i > 1)
ar.delimit_array();
}
else
{
FIELDS(ecdhInfo[i])
}
if (outputs - i > 1)
ar.delimit_array();
ar.end_array();
}
ar.end_array();
ar.tag("outPk");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, outPk);
if (outPk.size() != outputs)
return false;
for (size_t i = 0; i < outputs; ++i)
{
FIELDS(outPk[i].mask)
if (outputs - i > 1)
ar.delimit_array();
}
ar.end_array();
if (type == RCTTypeCLSAG)
{
ar.tag("outPk_usd");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, outPk_usd);
if (outPk_usd.size() != outputs)
return false;
for (size_t i = 0; i < outputs; ++i)
{
FIELDS(outPk_usd[i].mask)
if (outputs - i > 1)
ar.delimit_array();
}
ar.end_array();
}
return ar.stream().good();
}
}
return ar.stream().good();
}
};
struct rctSigPrunable {
std::vector<rangeSig> rangeSigs;
@@ -382,12 +432,12 @@ namespace rct {
{
if (type == RCTTypeNull)
return ar.stream().good();
if (type != RCTTypeFull && type != RCTTypeSimple && type != RCTTypeBulletproof && type != RCTTypeBulletproof2 && type != RCTTypeCLSAG)
if (type != RCTTypeFull && type != RCTTypeSimple && type != RCTTypeBulletproof && type != RCTTypeBulletproof2 && type != RCTTypeCLSAG && type != RCTTypeCLSAGN && type != RCTTypeHaven2)
return false;
if (type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG)
if (type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2)
{
uint32_t nbp = bulletproofs.size();
if (type == RCTTypeBulletproof2 || type == RCTTypeCLSAG)
if (type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2)
VARINT_FIELD(nbp)
else
FIELD(nbp)
@@ -422,7 +472,7 @@ namespace rct {
ar.end_array();
}
if (type == RCTTypeCLSAG)
if ((type == RCTTypeCLSAG) || (type == RCTTypeCLSAGN) || (type == RCTTypeHaven2))
{
ar.tag("CLSAGs");
ar.begin_array();
@@ -513,7 +563,7 @@ namespace rct {
}
ar.end_array();
}
if (type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG)
if (type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2)
{
ar.tag("pseudoOuts");
ar.begin_array();
@@ -537,12 +587,12 @@ namespace rct {
keyV& get_pseudo_outs()
{
return type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG ? p.pseudoOuts : pseudoOuts;
return type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 ? p.pseudoOuts : pseudoOuts;
}
keyV const& get_pseudo_outs() const
{
return type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG ? p.pseudoOuts : pseudoOuts;
return type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 ? p.pseudoOuts : pseudoOuts;
}
};
+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");
+43 -13
View File
@@ -35,33 +35,63 @@
#include "serialization.h"
#include "debug_archive.h"
#include "offshore/pricing_record.h"
#include "cryptonote_config.h"
/*
// read
template <template <bool> class Archive>
bool do_serialize(Archive<false> &ar, offshore::pricing_record &pr)
bool do_serialize(Archive<false> &ar, offshore::pricing_record &pr, uint8_t version)
{
// very basic sanity check
if (ar.remaining_bytes() < sizeof(offshore::pricing_record)) {
ar.stream().setstate(std::ios::failbit);
return false;
if (version < HF_VERSION_XASSET_FEES_V2)
{
// very basic sanity check
if (ar.remaining_bytes() < sizeof(offshore::pricing_record_v1)) {
ar.stream().setstate(std::ios::failbit);
return false;
}
offshore::pricing_record_v1 pr_v1;
ar.serialize_blob(&pr_v1, sizeof(offshore::pricing_record_v1), "");
if (!ar.stream().good())
return false;
if (!pr_v1.write_to_pr(pr))
return false;
}
else
{
// very basic sanity check
if (ar.remaining_bytes() < sizeof(offshore::pricing_record)) {
ar.stream().setstate(std::ios::failbit);
return false;
}
ar.serialize_blob(&pr, sizeof(offshore::pricing_record), "");
if (!ar.stream().good())
return false;
}
ar.serialize_blob(&pr, sizeof(offshore::pricing_record), "");
if (!ar.stream().good())
return false;
return true;
}
// write
template <template <bool> class Archive>
bool do_serialize(Archive<true> &ar, offshore::pricing_record &pr)
bool do_serialize(Archive<true> &ar, offshore::pricing_record &pr, uint8_t version)
{
ar.begin_string();
ar.serialize_blob(&pr, sizeof(offshore::pricing_record), "");
if (version < HF_VERSION_XASSET_FEES_V2)
{
offshore::pricing_record_v1 pr_v1;
if (!pr_v1.read_from_pr(pr))
return false;
ar.serialize_blob(&pr_v1, sizeof(offshore::pricing_record_v1), "");
}
else
{
ar.serialize_blob(&pr, sizeof(offshore::pricing_record), "");
}
if (!ar.stream().good())
return false;
ar.end_string();
return true;
}
*/
BLOB_SERIALIZER(offshore::pricing_record);
BLOB_SERIALIZER(offshore::pricing_record);