diff --git a/package.json b/package.json index e06d479..c0c46a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cryptoforknote-util", - "version": "11.0.2", + "version": "11.1.0", "main": "cryptoforknote-util", "author": { "name": "LucasJones", diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 3158f60..aff6d2f 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -1,10 +1,21 @@ #pragma once #define CURRENT_TRANSACTION_VERSION 1 +#define POU_TRANSACTION_VERSION 6 #define OFFSHORE_TRANSACTION_VERSION 3 #define HF_VERSION_XASSET_FEES_V2 17 #define HF_VERSION_HAVEN2 18 +// UNLOCK TIMES +#define TX_V6_OFFSHORE_UNLOCK_BLOCKS 21*720 // 21 day unlock time +#define TX_V6_ONSHORE_UNLOCK_BLOCKS 360 // 12 hour unlock time +#define TX_V6_XASSET_UNLOCK_BLOCKS 1440 // 2 day unlock time +#define TX_V6_OFFSHORE_UNLOCK_BLOCKS_TESTNET 60 // 2 hour unlock time - FOR TESTING ONLY +#define TX_V6_ONSHORE_UNLOCK_BLOCKS_TESTNET 30 // 1 hour unlock time - FOR TESTING ONLY +#define TX_V6_XASSET_UNLOCK_BLOCKS_TESTNET 60 // 2 hour unlock time - FOR TESTING ONLY + +#define PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK 120 // seconds + enum BLOB_TYPE { BLOB_TYPE_CRYPTONOTE = 0, BLOB_TYPE_FORKNOTE1 = 1, diff --git a/src/cryptonote_core/cryptonote_basic.h b/src/cryptonote_core/cryptonote_basic.h index b2134a9..e22d6e0 100644 --- a/src/cryptonote_core/cryptonote_basic.h +++ b/src/cryptonote_core/cryptonote_basic.h @@ -258,7 +258,8 @@ namespace cryptonote if (version == loki_version_3_per_output_unlock_times) FIELD(is_deregister) } - VARINT_FIELD(unlock_time) + if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV || version < POU_TRANSACTION_VERSION) + VARINT_FIELD(unlock_time) FIELD(vin) FIELD(vout) if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) @@ -275,6 +276,11 @@ namespace cryptonote VARINT_FIELD(pricing_record_height) if (version < 5) FIELD(offshore_data) + if (version >= POU_TRANSACTION_VERSION) + { + FIELD(output_unlock_times) + } + if (version >= POU_TRANSACTION_VERSION && vout.size() != output_unlock_times.size()) return false; VARINT_FIELD(amount_burnt) VARINT_FIELD(amount_minted) } @@ -389,6 +395,7 @@ namespace cryptonote offshore_data.clear(); amount_burnt = 0; amount_minted = 0; + output_unlock_times.clear(); } inline diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 4244b03..81e5fe3 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -89,6 +89,7 @@ namespace cryptonote { // This is the correct way to get the fee for Haven, because outs may be in different currencies to ins switch (tx.version) { + case 6: case 5: fee = tx.rct_signatures.txnFee + tx.rct_signatures.txnOffshoreFee; break; @@ -282,6 +283,10 @@ namespace cryptonote //----------------------------------------------------------------------------------------------- bool check_outs_valid(const transaction& tx) { + if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_XHV && tx.version >= POU_TRANSACTION_VERSION) + { + CHECK_AND_ASSERT_MES(tx.vout.size() == tx.output_unlock_times.size(), false, "tx version 6+ must have equal number of output unlock times and outputs"); + } BOOST_FOREACH(const tx_out& out, tx.vout) { if (tx.blob_type != BLOB_TYPE_CRYPTONOTE_XHV) { diff --git a/src/offshore/pricing_record.cpp b/src/offshore/pricing_record.cpp index 2847b09..e293d19 100644 --- a/src/offshore/pricing_record.cpp +++ b/src/offshore/pricing_record.cpp @@ -33,10 +33,6 @@ #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 { @@ -262,27 +258,8 @@ namespace offshore return (*this).equal(empty_pr); } - bool pricing_record::verifySignature() const + bool pricing_record::verifySignature(const std::string& public_key) 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 @@ -432,8 +409,27 @@ namespace offshore } } + // 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; + // verify the signature - if (!verifySignature()) { + if (!verifySignature(public_key)) { LOG_ERROR("Invalid pricing record signature."); return false; } @@ -453,4 +449,4 @@ namespace offshore return true; } -} +} \ No newline at end of file diff --git a/src/offshore/pricing_record.h b/src/offshore/pricing_record.h index 74c76b6..b20bbd2 100644 --- a/src/offshore/pricing_record.h +++ b/src/offshore/pricing_record.h @@ -116,7 +116,7 @@ namespace offshore void set_for_height_821428(); bool equal(const pricing_record& other) const noexcept; bool empty() const noexcept; - bool verifySignature() const; + bool verifySignature(const std::string& public_key) 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;