Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jagerman committed Aug 31, 2022
2 parents 02124b9 + f1ee71a commit 1ba2086
Show file tree
Hide file tree
Showing 38 changed files with 599 additions and 2,573 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ message(STATUS "CMake version ${CMAKE_VERSION}")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12 CACHE STRING "macOS deployment target (Apple clang only)")

project(oxen
VERSION 10.1.3
VERSION 10.2.0
LANGUAGES CXX C)
set(OXEN_RELEASE_CODENAME "Wistful Wagyu")
# Version update notes:
# - bump the version above.
# - for a new major release, make a new codename
# - (if update needed) required SS/lokinet versions are in cryptonote_core/service_node_rules.h

# String value to append to the full version string; this is intended to easily identify whether a
# binary was build from the release or development branches. This should be permanently set to an
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain_db/sqlite/db_sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace cryptonote {
CREATE INDEX batched_payments_accrued_payout_offset_idx ON batched_payments_accrued(payout_offset);
DROP TRIGGER rollback_payment;
DROP TRIGGER IF EXISTS rollback_payment;
CREATE TRIGGER rollback_payment INSTEAD OF DELETE ON batched_payments_paid
FOR EACH ROW BEGIN
DELETE FROM batched_payments_raw WHERE address = OLD.address AND height_paid = OLD.height_paid;
Expand Down
16 changes: 7 additions & 9 deletions src/checkpoints/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ namespace cryptonote
return result;
}
//---------------------------------------------------------------------------
bool checkpoints::block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs, checkpoint_t const *checkpoint)
void checkpoints::block_add(const block_add_info& info)
{
uint64_t const height = get_block_height(block);
if (height < service_nodes::CHECKPOINT_STORE_PERSISTENTLY_INTERVAL || block.major_version < hf::hf12_checkpointing)
return true;
uint64_t const height = get_block_height(info.block);
if (height < service_nodes::CHECKPOINT_STORE_PERSISTENTLY_INTERVAL || info.block.major_version < hf::hf12_checkpointing)
return;

uint64_t end_cull_height = 0;
{
Expand Down Expand Up @@ -203,13 +203,11 @@ namespace cryptonote
}
}

if (checkpoint)
update_checkpoint(*checkpoint);

return true;
if (info.checkpoint)
update_checkpoint(*info.checkpoint);
}
//---------------------------------------------------------------------------
void checkpoints::blockchain_detached(uint64_t height, bool /*by_pop_blocks*/)
void checkpoints::blockchain_detached(uint64_t height)
{
m_last_cull_height = std::min(m_last_cull_height, height);

Expand Down
6 changes: 2 additions & 4 deletions src/checkpoints/checkpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ namespace cryptonote
* either from a json file or via DNS from a checkpoint-hosting server.
*/
class checkpoints
: public cryptonote::BlockAddedHook,
public cryptonote::BlockchainDetachedHook
{
public:
bool block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs, checkpoint_t const *checkpoint) override;
void blockchain_detached(uint64_t height, bool by_pop_blocks) override;
void block_add(const block_add_info& info);
void blockchain_detached(uint64_t height);

bool get_checkpoint(uint64_t height, checkpoint_t &checkpoint) const;
/**
Expand Down
49 changes: 22 additions & 27 deletions src/common/notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
// 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.

#include <boost/algorithm/string.hpp>
#include <stdarg.h>
#include "string_util.h"
#include "epee/misc_log_ex.h"
#include "spawn.h"
#include "notify.h"
Expand All @@ -43,40 +42,36 @@ namespace tools
- Improve tokenization to handle paths containing whitespaces, quotes, etc.
- Windows unicode support (implies implementing unicode command line parsing code)
*/
Notify::Notify(const char *spec)
Notify::Notify(std::string_view spec)
{
CHECK_AND_ASSERT_THROW_MES(spec, "Null spec");
CHECK_AND_ASSERT_THROW_MES(!spec.empty(), "Empty spec");

boost::split(args, spec, boost::is_any_of(" \t"), boost::token_compress_on);
CHECK_AND_ASSERT_THROW_MES(args.size() > 0, "Failed to parse spec");
if (strchr(spec, '\'') || strchr(spec, '\"') || strchr(spec, '\\'))
MWARNING("A notification spec contains a quote or backslash: note that these are handled verbatim, which may not be the intent");
filename = fs::u8path(args[0]);
auto pieces = tools::split_any(spec, " \t", true);
CHECK_AND_ASSERT_THROW_MES(pieces.size() > 0, "Failed to parse spec");
filename = fs::u8path(pieces[0]);
CHECK_AND_ASSERT_THROW_MES(fs::exists(filename), "File not found: " << filename);
}

static void replace(std::vector<std::string> &v, const char *tag, const char *s)
{
for (std::string &str: v)
boost::replace_all(str, tag, s);
args.reserve(pieces.size());
for (const auto& piece : pieces)
args.emplace_back(piece);
}

int Notify::notify(const char *tag, const char *s, ...)
void Notify::replace_tag(std::vector<std::string>& margs, std::string_view tag, std::string_view value)
{
std::vector<std::string> margs = args;

replace(margs, tag, s);

va_list ap;
va_start(ap, s);
while ((tag = va_arg(ap, const char*)))
{
s = va_arg(ap, const char*);
replace(margs, tag, s);
if (tag.empty())
return;
// Skip margs[0], it's the binary name
for (size_t i = 1; i < margs.size(); i++) {
size_t pos = 0;
while ((pos = margs[i].find(tag, pos)) != std::string::npos) {
margs[i].replace(pos, tag.size(), value);
pos += value.size();
}
}
va_end(ap);
}

return tools::spawn(filename, margs, false);
int Notify::spawn(const std::vector<std::string>& margs) const {
return tools::spawn(filename, margs, false);
}

}
22 changes: 20 additions & 2 deletions src/common/notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#pragma once

#include <string>
#include <string_view>
#include <vector>
#include <fmt/core.h>
#include "fs.h"

namespace tools
Expand All @@ -38,13 +40,29 @@ namespace tools
class Notify
{
public:
Notify(const char *spec);
explicit Notify(std::string_view spec);

int notify(const char *tag, const char *s, ...);
template <typename T, typename... MoreTags>
int notify(std::string_view tag, const T& value, MoreTags&&... more) const {
std::vector<std::string> margs{args};
replace_tags(margs, tag, value, std::forward<MoreTags>(more)...);
return spawn(margs);
}

private:
fs::path filename;
std::vector<std::string> args;

int spawn(const std::vector<std::string>& margs) const;

template <typename T, typename... MoreTags>
static void replace_tags(std::vector<std::string>& margs, std::string_view tag, const T& value, MoreTags&&... more) {
replace_tag(margs, tag, fmt::format("{}", value));
if constexpr (sizeof...(MoreTags) > 0)
replace_tags(margs, std::forward<MoreTags>(more)...);
}

static void replace_tag(std::vector<std::string>& margs, std::string_view tag, std::string_view value);
};

}
2 changes: 1 addition & 1 deletion src/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ add_library(cncrypto
hmac-keccak.c
jh.c
keccak.c
oaes_lib.c
oaes_lib_expand.c
random.c
skein.c
cn_heavy_hash_hard_arm.cpp
Expand Down
41 changes: 16 additions & 25 deletions src/crypto/cn_monero_slow_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

#include "epee/int-util.h"
#include "hash-ops.h"
#include "oaes_lib.h"
#include "oaes_lib_expand.h"
#include "variant2_int_sqrt.h"

#define MEMORY (1 << 21) // 2MB scratchpad
#define ITER (1 << 20)
#define AES_BLOCK_SIZE 16
#define AES_KEY_SIZE 32
#define AES_EXPANDED_KEY_SIZE 240
#define INIT_SIZE_BLK 8
#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE)

Expand Down Expand Up @@ -695,7 +697,7 @@ void monero_hash_free_state(void)
*/
void cn_monero_hash(const void *data, size_t length, char *hash, int variant, int prehashed)
{
RDATA_ALIGN16 uint8_t expandedKey[240]; /* These buffers are aligned to use later with SSE functions */
RDATA_ALIGN16 uint8_t expandedKey[AES_EXPANDED_KEY_SIZE]; /* These buffers are aligned to use later with SSE functions */

uint8_t text[INIT_SIZE_BYTE];
RDATA_ALIGN16 uint64_t a[2];
Expand All @@ -707,7 +709,6 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in

size_t i, j;
uint64_t *p = NULL;
oaes_ctx *aes_ctx = NULL;
int useAes = !force_software_aes() && check_aes_hw();

static void (*const extra_hashes[4])(const void *, size_t, char *) =
Expand Down Expand Up @@ -745,12 +746,11 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
}
else
{
aes_ctx = (oaes_ctx *) oaes_alloc();
oaes_key_import_data(aes_ctx, state.hs.b, AES_KEY_SIZE);
oaes_expand_key_256(state.hs.b, expandedKey);
for(i = 0; i < MEMORY / INIT_SIZE_BYTE; i++)
{
for(j = 0; j < INIT_SIZE_BLK; j++)
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], aes_ctx->key->exp_data);
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], expandedKey);

memcpy(&hp_state[i * INIT_SIZE_BYTE], text, INIT_SIZE_BYTE);
}
Expand Down Expand Up @@ -805,16 +805,15 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
}
else
{
oaes_key_import_data(aes_ctx, &state.hs.b[32], AES_KEY_SIZE);
oaes_expand_key_256(&state.hs.b[32], expandedKey);
for(i = 0; i < MEMORY / INIT_SIZE_BYTE; i++)
{
for(j = 0; j < INIT_SIZE_BLK; j++)
{
xor_blocks(&text[j * AES_BLOCK_SIZE], &hp_state[i * INIT_SIZE_BYTE + j * AES_BLOCK_SIZE]);
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], aes_ctx->key->exp_data);
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], expandedKey);
}
}
oaes_free((OAES_CTX **) &aes_ctx);
}

/* CryptoNight Step 5: Apply Keccak to the state again, and then
Expand Down Expand Up @@ -1286,13 +1285,12 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
uint8_t c1[AES_BLOCK_SIZE];
uint8_t d[AES_BLOCK_SIZE];
uint8_t aes_key[AES_KEY_SIZE];
RDATA_ALIGN16 uint8_t expandedKey[256];
RDATA_ALIGN16 uint8_t expandedKey[AES_EXPANDED_KEY_SIZE];

union cn_monero_hash_state state;

size_t i, j;
uint8_t *p = NULL;
oaes_ctx *aes_ctx;
static void (*const extra_hashes[4])(const void *, size_t, char *) =
{
hash_extra_blake, hash_extra_groestl, hash_extra_jh, hash_extra_skein
Expand All @@ -1311,14 +1309,11 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
}
memcpy(text, state.init, INIT_SIZE_BYTE);

aes_ctx = (oaes_ctx *) oaes_alloc();
oaes_key_import_data(aes_ctx, state.hs.b, AES_KEY_SIZE);

VARIANT1_INIT64();
VARIANT2_INIT64();

// use aligned data
memcpy(expandedKey, aes_ctx->key->exp_data, aes_ctx->key->exp_data_len);
oaes_expand_key_256(state.hs.b, expandedKey);
for(i = 0; i < MEMORY / INIT_SIZE_BYTE; i++)
{
for(j = 0; j < INIT_SIZE_BLK; j++)
Expand Down Expand Up @@ -1368,8 +1363,7 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
}

memcpy(text, state.init, INIT_SIZE_BYTE);
oaes_key_import_data(aes_ctx, &state.hs.b[32], AES_KEY_SIZE);
memcpy(expandedKey, aes_ctx->key->exp_data, aes_ctx->key->exp_data_len);
oaes_expand_key_256(&state.hs.b[32], expandedKey);
for(i = 0; i < MEMORY / INIT_SIZE_BYTE; i++)
{
for(j = 0; j < INIT_SIZE_BLK; j++)
Expand All @@ -1379,7 +1373,6 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
}
}

oaes_free((OAES_CTX **) &aes_ctx);
memcpy(state.init, text, INIT_SIZE_BYTE);
hash_permutation(&state.hs);
extra_hashes[state.hs.b[0] & 3](&state, 200, hash);
Expand Down Expand Up @@ -1491,7 +1484,7 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
uint8_t d[AES_BLOCK_SIZE];
size_t i, j;
uint8_t aes_key[AES_KEY_SIZE];
oaes_ctx *aes_ctx;
uint8_t expandedKey[AES_EXPANDED_KEY_SIZE];

if (prehashed) {
memcpy(&state.hs, data, length);
Expand All @@ -1500,15 +1493,14 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
}
memcpy(text, state.init, INIT_SIZE_BYTE);
memcpy(aes_key, state.hs.b, AES_KEY_SIZE);
aes_ctx = (oaes_ctx *) oaes_alloc();

VARIANT1_PORTABLE_INIT();
VARIANT2_PORTABLE_INIT();

oaes_key_import_data(aes_ctx, aes_key, AES_KEY_SIZE);
oaes_expand_key_256(aes_key, expandedKey);
for (i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) {
for (j = 0; j < INIT_SIZE_BLK; j++) {
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], aes_ctx->key->exp_data);
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], expandedKey);
}
memcpy(&long_state[i * INIT_SIZE_BYTE], text, INIT_SIZE_BYTE);
}
Expand Down Expand Up @@ -1554,18 +1546,17 @@ void cn_monero_hash(const void *data, size_t length, char *hash, int variant, in
}

memcpy(text, state.init, INIT_SIZE_BYTE);
oaes_key_import_data(aes_ctx, &state.hs.b[32], AES_KEY_SIZE);
oaes_expand_key_256(&state.hs.b[32], expandedKey);
for (i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) {
for (j = 0; j < INIT_SIZE_BLK; j++) {
xor_blocks(&text[j * AES_BLOCK_SIZE], &long_state[i * INIT_SIZE_BYTE + j * AES_BLOCK_SIZE]);
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], aes_ctx->key->exp_data);
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], expandedKey);
}
}
memcpy(state.init, text, INIT_SIZE_BYTE);
hash_permutation(&state.hs);
/*memcpy(hash, &state, 32);*/
extra_hashes[state.hs.b[0] & 3](&state, 200, hash);
oaes_free((OAES_CTX **) &aes_ctx);

#ifdef FORCE_USE_HEAP
free(long_state);
Expand Down
Loading

0 comments on commit 1ba2086

Please sign in to comment.