Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nav-io/navio-core into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
alex v committed Dec 15, 2024
2 parents 7442cdf + da90159 commit b98e42d
Show file tree
Hide file tree
Showing 103 changed files with 3,354 additions and 1,074 deletions.
14 changes: 0 additions & 14 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,6 @@ task:
env:
FILE_ENV: "./ci/test/00_setup_env_native_msan.sh"

task:
name: 'ASan + LSan + UBSan + integer, no depends, USDT'
enable_bpfcc_script:
# In the image build step, no external environment variables are available,
# so any settings will need to be written to the settings env file:
- sed -i "s|\${CIRRUS_CI}|true|g" ./ci/test/00_setup_env_native_asan.sh
<< : *GLOBAL_TASK_TEMPLATE
persistent_worker:
labels:
type: noble # Must use this specific worker (needed for USDT functional tests)
timeout_in: 300m # Use longer timeout for the *rare* case where a full build (llvm + msan + depends + ...) needs to be done.
env:
FILE_ENV: "./ci/test/00_setup_env_native_asan.sh"

task:
name: 'fuzzer,address,undefined,integer, no depends'
<< : *GLOBAL_TASK_TEMPLATE
Expand Down
1 change: 1 addition & 0 deletions build_msvc/common.init.vcxproj.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<CharacterSet>Unicode</CharacterSet>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<MaxConcurrentBuilds>1</MaxConcurrentBuilds>
</PropertyGroup>

<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
Expand Down
23 changes: 21 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,18 @@ BLSCT_H = \
blsct/set_mem_proof/set_mem_proof_prover.h \
blsct/set_mem_proof/set_mem_proof_setup.h \
blsct/signature.h \
blsct/tokens/info.h \
blsct/tokens/predicate.h \
blsct/tokens/predicate_exec.h \
blsct/tokens/predicate_parser.h \
blsct/tokens/rpc.h \
blsct/wallet/address.h \
blsct/wallet/hdchain.h \
blsct/wallet/helpers.h \
blsct/wallet/import_wallet_type.h \
blsct/wallet/keyman.h \
blsct/wallet/keyring.h \
blsct/wallet/rpc.h \
blsct/wallet/txfactory.h \
blsct/wallet/txfactory_base.h \
blsct/wallet/txfactory_global.h \
Expand Down Expand Up @@ -250,6 +256,9 @@ BLSCT_CPP = \
blsct/set_mem_proof/set_mem_proof_prover.cpp \
blsct/set_mem_proof/set_mem_proof_setup.cpp \
blsct/signature.cpp \
blsct/tokens/info.cpp \
blsct/tokens/predicate_exec.cpp \
blsct/tokens/predicate_parser.cpp \
blsct/wallet/address.cpp \
blsct/wallet/helpers.cpp \
blsct/wallet/keyman.cpp \
Expand Down Expand Up @@ -568,6 +577,9 @@ libbitcoin_node_a_SOURCES = \
blsct/set_mem_proof/set_mem_proof.cpp \
blsct/set_mem_proof/set_mem_proof_setup.cpp \
blsct/set_mem_proof/set_mem_proof_prover.cpp \
blsct/tokens/info.cpp \
blsct/tokens/rpc.cpp \
blsct/wallet/rpc.cpp \
blsct/wallet/verification.cpp \
blsct/signature.cpp \
chain.cpp \
Expand Down Expand Up @@ -725,6 +737,7 @@ libbitcoin_wallet_a_SOURCES = \
blsct/wallet/helpers.cpp \
blsct/wallet/keyman.cpp \
blsct/wallet/keyring.cpp \
blsct/wallet/rpc.cpp \
blsct/wallet/txfactory.cpp \
blsct/wallet/txfactory_base.cpp \
blsct/wallet/txfactory_global.cpp \
Expand Down Expand Up @@ -877,13 +890,15 @@ libbitcoin_consensus_a_SOURCES = \
blsct/range_proof/bulletproofs/range_proof.cpp \
blsct/range_proof/bulletproofs/range_proof_logic.cpp \
blsct/range_proof/bulletproofs/range_proof_with_transcript.cpp \
blsct/range_proof/bulletproofs_plus/amount_recovery_result.cpp \
blsct/range_proof/bulletproofs_plus/amount_recovery_request.cpp \
blsct/range_proof/bulletproofs_plus/range_proof.cpp \
blsct/range_proof/bulletproofs_plus/range_proof_logic.cpp \
blsct/range_proof/bulletproofs_plus/range_proof_with_transcript.cpp \
blsct/range_proof/common.cpp \
blsct/range_proof/generators.cpp \
blsct/range_proof/proof_base.cpp \
blsct/range_proof/msg_amt_cipher.cpp \
blsct/range_proof/bulletproofs/range_proof.cpp \
blsct/range_proof/bulletproofs_plus/range_proof.cpp \
blsct/range_proof/bulletproofs_plus/util.cpp \
blsct/set_mem_proof/set_mem_proof.cpp \
blsct/set_mem_proof/set_mem_proof_setup.cpp \
Expand Down Expand Up @@ -966,6 +981,8 @@ libbitcoin_common_a_SOURCES = \
blsct/set_mem_proof/set_mem_proof_prover.cpp \
blsct/set_mem_proof/set_mem_proof_setup.cpp \
blsct/signature.cpp \
blsct/tokens/predicate_exec.cpp \
blsct/tokens/predicate_parser.cpp \
blsct/wallet/address.cpp \
blsct/wallet/txfactory_global.cpp \
chainparams.cpp \
Expand Down Expand Up @@ -1295,6 +1312,8 @@ libnaviokernel_la_SOURCES = \
blsct/set_mem_proof/set_mem_proof_prover.cpp \
blsct/set_mem_proof/set_mem_proof_setup.cpp \
blsct/signature.cpp \
blsct/tokens/predicate_exec.cpp \
blsct/tokens/predicate_parser.cpp \
blsct/wallet/txfactory_global.cpp \
blsct/wallet/verification.cpp \
chain.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test_util.include
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ libtest_util_a_SOURCES = \
blsct/public_key.cpp \
blsct/public_keys.cpp \
blsct/signature.cpp \
blsct/wallet/rpc.cpp \
blsct/wallet/txfactory_global.cpp \
test/util/blockfilter.cpp \
test/util/coins.cpp \
Expand Down
2 changes: 2 additions & 0 deletions src/blsct/arith/mcl/mcl_g1point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ bool MclG1Point::IsValid() const

bool MclG1Point::IsZero() const
{
MclG1Point zero;
if (std::memcmp(&m_point, &zero.m_point, sizeof(MclG1Point::Underlying)) == 0) return true;
return mclBnG1_isZero(&m_point);
}

Expand Down
9 changes: 9 additions & 0 deletions src/blsct/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class Common
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0'};

inline static const std::vector<uint8_t> BLSCTFEE = {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'B', 'L', 'S', 'C', 'T', 'F', 'E', 'E', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0'};

static std::vector<uint8_t> DataStreamToVector(const DataStream& st);

/**
Expand Down
16 changes: 16 additions & 0 deletions src/blsct/eip_2333/bls12_381_keygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,19 @@ MclScalar BLS12_381_KeyGen::derive_child_SK(const MclScalar& parent_SK, const ui
auto SK = HKDF_mod_r(std::vector<uint8_t>(comp_PK.cbegin(), comp_PK.cend()));
return SK;
}

MclScalar BLS12_381_KeyGen::derive_child_SK_hash(const MclScalar& parent_SK, const uint256& hash)
{
auto ret = parent_SK;
for (auto i = 0; i < 8; i++) {
const uint8_t* pos = hash.begin() + i * 4;
uint32_t index = (static_cast<uint32_t>(pos[0]) << 24) |
(static_cast<uint32_t>(pos[1]) << 16) |
(static_cast<uint32_t>(pos[2]) << 8) |
(static_cast<uint32_t>(pos[3]));

auto comp_PK = parent_SK_to_lamport_PK(ret, index);
ret = HKDF_mod_r(std::vector<uint8_t>(comp_PK.cbegin(), comp_PK.cend()));
}
return ret;
}
13 changes: 7 additions & 6 deletions src/blsct/eip_2333/bls12_381_keygen.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@ class BLS12_381_KeyGen
public:
static MclScalar derive_master_SK(const std::vector<uint8_t>& seed);
static MclScalar derive_child_SK(const MclScalar& parent_SK, const uint32_t& index);
static MclScalar derive_child_SK_hash(const MclScalar& parent_SK, const uint256& hash);

#ifndef BOOST_UNIT_TEST
private:
#endif
inline static const uint32_t DigestSize = CSHA256::OUTPUT_SIZE;
inline static const uint32_t NumLamportChunks = 255;

using LamportChunks = std::array<std::array<uint8_t,DigestSize>,NumLamportChunks>;
using LamportChunks = std::array<std::array<uint8_t, DigestSize>, NumLamportChunks>;

static std::array<uint8_t,DigestSize> HKDF_Extract(const std::vector<uint8_t>& salt, const std::vector<uint8_t>& IKM);
static std::array<uint8_t, DigestSize> HKDF_Extract(const std::vector<uint8_t>& salt, const std::vector<uint8_t>& IKM);

template <size_t L>
static std::array<uint8_t,L> HKDF_Expand(const std::array<uint8_t,DigestSize>& PRK, const std::vector<uint8_t>& info);
static std::array<uint8_t, L> HKDF_Expand(const std::array<uint8_t, DigestSize>& PRK, const std::vector<uint8_t>& info);

static std::vector<uint8_t> I2OSP(const MclScalar& x, const size_t& xLen);
static MclScalar OS2IP(const std::array<uint8_t,48ul>& X);
static MclScalar OS2IP(const std::array<uint8_t, 48ul>& X);
static std::vector<uint8_t> flip_bits(const std::vector<uint8_t>& vec);
static LamportChunks bytes_split(const std::array<uint8_t,8160>& octet_string);
static LamportChunks bytes_split(const std::array<uint8_t, 8160>& octet_string);
static MclScalar HKDF_mod_r(const std::vector<uint8_t>& IKM);
static LamportChunks IKM_to_lamport_SK(const std::vector<uint8_t>& IKM, const std::vector<uint8_t>& salt);
static std::array<uint8_t,DigestSize> parent_SK_to_lamport_PK(const MclScalar& parent_SK, const uint32_t& index);
static std::array<uint8_t, DigestSize> parent_SK_to_lamport_PK(const MclScalar& parent_SK, const uint32_t& index);
};

#endif // NAVIO_BLSCT_EIP_2333_BLS12_381_KEYGEN_H
Expand Down
39 changes: 23 additions & 16 deletions src/blsct/external_api/blsct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,51 +881,58 @@ const BlsctPoint* get_tx_out_range_proof_A(const CTxOut* tx_out) {
return copy;
}

const BlsctPoint* get_tx_out_range_proof_S(const CTxOut* tx_out) {
const BlsctPoint* get_tx_out_range_proof_A_wip(const CTxOut* tx_out)
{
auto copy = static_cast<BlsctPoint*>(malloc(POINT_SIZE));
auto org = tx_out->blsctData.rangeProof.S.GetVch();
auto org = tx_out->blsctData.rangeProof.A_wip.GetVch();
std::memcpy(copy, &org[0], POINT_SIZE);
return copy;
}

const BlsctPoint* get_tx_out_range_proof_T1(const CTxOut* tx_out) {
const BlsctPoint* get_tx_out_range_proof_B(const CTxOut* tx_out)
{
auto copy = static_cast<BlsctPoint*>(malloc(POINT_SIZE));
auto org = tx_out->blsctData.rangeProof.T1.GetVch();
auto org = tx_out->blsctData.rangeProof.B.GetVch();
std::memcpy(copy, &org[0], POINT_SIZE);
return copy;
}

const BlsctPoint* get_tx_out_range_proof_T2(const CTxOut* tx_out) {
auto copy = static_cast<BlsctPoint*>(malloc(POINT_SIZE));
auto org = tx_out->blsctData.rangeProof.T2.GetVch();
std::memcpy(copy, &org[0], POINT_SIZE);
const BlsctScalar* get_tx_out_range_proof_r_prime(const CTxOut* tx_out)
{
auto copy = static_cast<BlsctScalar*>(malloc(SCALAR_SIZE));
auto org = tx_out->blsctData.rangeProof.r_prime.GetVch();
std::memcpy(copy, &org[0], SCALAR_SIZE);
return copy;
}

const BlsctScalar* get_tx_out_range_proof_mu(const CTxOut* tx_out) {
const BlsctScalar* get_tx_out_range_proof_s_prime(const CTxOut* tx_out)
{
auto copy = static_cast<BlsctScalar*>(malloc(SCALAR_SIZE));
auto org = tx_out->blsctData.rangeProof.mu.GetVch();
auto org = tx_out->blsctData.rangeProof.s_prime.GetVch();
std::memcpy(copy, &org[0], SCALAR_SIZE);
return copy;
}

const BlsctScalar* get_tx_out_range_proof_a(const CTxOut* tx_out) {
const BlsctScalar* get_tx_out_range_proof_delta_prime(const CTxOut* tx_out)
{
auto copy = static_cast<BlsctScalar*>(malloc(SCALAR_SIZE));
auto org = tx_out->blsctData.rangeProof.a.GetVch();
auto org = tx_out->blsctData.rangeProof.delta_prime.GetVch();
std::memcpy(copy, &org[0], SCALAR_SIZE);
return copy;
}

const BlsctScalar* get_tx_out_range_proof_b(const CTxOut* tx_out) {
const BlsctScalar* get_tx_out_range_proof_alpha_hat(const CTxOut* tx_out)
{
auto copy = static_cast<BlsctScalar*>(malloc(SCALAR_SIZE));
auto org = tx_out->blsctData.rangeProof.b.GetVch();
auto org = tx_out->blsctData.rangeProof.alpha_hat.GetVch();
std::memcpy(copy, &org[0], SCALAR_SIZE);
return copy;
}

const BlsctScalar* get_tx_out_range_proof_t_hat(const CTxOut* tx_out) {
const BlsctScalar* get_tx_out_range_proof_tau_x(const CTxOut* tx_out)
{
auto copy = static_cast<BlsctScalar*>(malloc(SCALAR_SIZE));
auto org = tx_out->blsctData.rangeProof.t_hat.GetVch();
auto org = tx_out->blsctData.rangeProof.tau_x.GetVch();
std::memcpy(copy, &org[0], SCALAR_SIZE);
return copy;
}
Expand Down
20 changes: 7 additions & 13 deletions src/blsct/external_api/blsct.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,13 @@ const BlsctPoint* get_tx_out_blinding_key(const CTxOut* tx_out);
uint16_t get_tx_out_view_tag(const CTxOut* tx_out);

const BlsctPoint* get_tx_out_range_proof_A(const CTxOut* tx_out);
const BlsctPoint* get_tx_out_range_proof_S(const CTxOut* tx_out);
const BlsctPoint* get_tx_out_range_proof_T1(const CTxOut* tx_out);
const BlsctPoint* get_tx_out_range_proof_T2(const CTxOut* tx_out);

const BlsctScalar* get_tx_out_range_proof_mu(const CTxOut* tx_out);
const BlsctScalar* get_tx_out_range_proof_a(const CTxOut* tx_out);
const BlsctScalar* get_tx_out_range_proof_b(const CTxOut* tx_out);
const BlsctScalar* get_tx_out_range_proof_t_hat(const CTxOut* tx_out);

const BlsctSignature* sign_message(
const BlsctScalar* blsct_priv_key,
const char* blsct_msg
);
const BlsctPoint* get_tx_out_range_proof_A_wip(const CTxOut* tx_out);
const BlsctPoint* get_tx_out_range_proof_B(const CTxOut* tx_out);
const BlsctScalar* get_tx_out_range_proof_r_prime(const CTxOut* tx_out);
const BlsctScalar* get_tx_out_range_proof_s_prime(const CTxOut* tx_out);
const BlsctScalar* get_tx_out_range_proof_delta_prime(const CTxOut* tx_out);
const BlsctScalar* get_tx_out_range_proof_alpha_hat(const CTxOut* tx_out);
const BlsctScalar* get_tx_out_range_proof_tau_x(const CTxOut* tx_out);

bool verify_msg_sig(
const BlsctPubKey* blsct_pub_key,
Expand Down
4 changes: 2 additions & 2 deletions src/blsct/pos/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

namespace blsct {
uint256
CalculateKernelHash(const uint32_t& prevTime, const uint64_t& stakeModifier, const MclG1Point& phi, const uint32_t& time)
CalculateKernelHash(const uint32_t& prevTime, const uint64_t& stakeModifier, const uint32_t& time)
{
HashWriter ss{};

ss << prevTime << stakeModifier << phi << time;
ss << prevTime << stakeModifier << time;

return ss.GetHash();
}
Expand Down
2 changes: 1 addition & 1 deletion src/blsct/pos/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define MODIFIER_INTERVAL_RATIO 3

namespace blsct {
uint256 CalculateKernelHash(const uint32_t& prevTime, const uint64_t& stakeModifier, const MclG1Point& phi, const uint32_t& time);
uint256 CalculateKernelHash(const uint32_t& prevTime, const uint64_t& stakeModifier, const uint32_t& time);
} // namespace blsct

#endif // BLSCT_POS_H
6 changes: 3 additions & 3 deletions src/blsct/pos/pos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ std::vector<unsigned char> CalculateSetMemProofRandomness(const CBlockIndex* pin


blsct::Message
CalculateSetMemProofGeneratorSeed(const CBlockIndex* pindexPrev)
CalculateSetMemProofGeneratorSeed(const CBlockIndex* pindexPrev, const CBlock& block)
{
HashWriter ss{};

ss << pindexPrev->nHeight << pindexPrev->nStakeModifier;
ss << pindexPrev->nHeight << pindexPrev->nStakeModifier << TX_NO_WITNESS(block.vtx);

auto hash = ss.GetHash();

Expand All @@ -132,6 +132,6 @@ CalculateSetMemProofGeneratorSeed(const CBlockIndex* pindexPrev)

uint256 CalculateKernelHash(const CBlockIndex* pindexPrev, const CBlock& block)
{
return CalculateKernelHash(pindexPrev->nTime, pindexPrev->nStakeModifier, block.posProof.setMemProof.phi, block.nTime);
return CalculateKernelHash(pindexPrev->nTime, pindexPrev->nStakeModifier, block.nTime);
}
} // namespace blsct
2 changes: 1 addition & 1 deletion src/blsct/pos/pos.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool GetLastStakeModifier(const CBlockIndex* pindex, uint64_t& nStakeModifier, i
int64_t GetStakeModifierSelectionIntervalSection(int nSection, const Consensus::Params& params);
int64_t GetStakeModifierSelectionInterval(const Consensus::Params& params);
std::vector<unsigned char> CalculateSetMemProofRandomness(const CBlockIndex* pindexPrev);
blsct::Message CalculateSetMemProofGeneratorSeed(const CBlockIndex* pindexPrev);
blsct::Message CalculateSetMemProofGeneratorSeed(const CBlockIndex* pindexPrev, const CBlock& block);
uint256 CalculateKernelHash(const CBlockIndex* pindexPrev, const CBlock& block);
} // namespace blsct

Expand Down
12 changes: 6 additions & 6 deletions src/blsct/pos/proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ using Point = Arith::Point;
using Scalar = Arith::Scalar;
using Points = Elements<Point>;
using Scalars = Elements<Scalar>;
using RangeProof = bulletproofs::RangeProof<Arith>;
using RangeProver = bulletproofs::RangeProofLogic<Arith>;
using RangeProof = bulletproofs_plus::RangeProof<Arith>;
using RangeProver = bulletproofs_plus::RangeProofLogic<Arith>;
using SetProof = SetMemProof<Arith>;
using SetProver = SetMemProofProver<Arith>;

Expand All @@ -35,7 +35,7 @@ ProofOfStake::ProofOfStake(const Points& staked_commitments, const Scalar& eta_f

setMemProof = SetProver::Prove(setup, staked_commitments, sigma, m, f, eta_fiat_shamir, eta_phi);

auto kernel_hash = CalculateKernelHash(prev_time, stake_modifier, setMemProof.phi, time);
auto kernel_hash = CalculateKernelHash(prev_time, stake_modifier, time);
uint256 min_value = CalculateMinValue(kernel_hash, next_target);

range_proof::GammaSeed<Arith> gamma_seed(Scalars({f}));
Expand All @@ -55,7 +55,7 @@ ProofOfStake::ProofOfStake(const Points& staked_commitments, const Scalar& eta_f

ProofOfStake::VerificationResult ProofOfStake::Verify(const Points& staked_commitments, const Scalar& eta_fiat_shamir, const blsct::Message& eta_phi, const uint32_t& prev_time, const uint64_t& stake_modifier, const uint32_t& time, const unsigned int& next_target) const
{
return Verify(staked_commitments, eta_fiat_shamir, eta_phi, CalculateKernelHash(prev_time, stake_modifier, setMemProof.phi, time), next_target);
return Verify(staked_commitments, eta_fiat_shamir, eta_phi, CalculateKernelHash(prev_time, stake_modifier, time), next_target);
}

ProofOfStake::VerificationResult ProofOfStake::Verify(const Points& staked_commitments, const Scalar& eta_fiat_shamir, const blsct::Message& eta_phi, const uint256& kernel_hash, const unsigned int& next_target) const
Expand Down Expand Up @@ -106,8 +106,8 @@ bool ProofOfStake::VerifyKernelHash(const RangeProof& range_proof, const uint256
range_proof_with_value.Vs.Add(phi);

RangeProver rp;
std::vector<bulletproofs::RangeProofWithSeed<Arith>> proofs;
bulletproofs::RangeProofWithSeed<Arith> proof{range_proof_with_value, eta_phi, (CAmount)min_value.GetUint64(0)};
std::vector<bulletproofs_plus::RangeProofWithSeed<Arith>> proofs;
bulletproofs_plus::RangeProofWithSeed<Arith> proof{range_proof_with_value, eta_phi, (CAmount)min_value.GetUint64(0)};

proofs.emplace_back(proof);

Expand Down
Loading

0 comments on commit b98e42d

Please sign in to comment.