Skip to content

Commit

Permalink
consensus: add arith_uint256, auxpow, pow, uint256 and validation files
Browse files Browse the repository at this point in the history
  • Loading branch information
xanimo committed Jun 17, 2023
1 parent c62536e commit fc20793
Show file tree
Hide file tree
Showing 24 changed files with 1,570 additions and 11 deletions.
10 changes: 10 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ noinst_HEADERS = \
include/bip39/index.h \
include/dogecoin/address.h \
include/dogecoin/aes.h \
include/dogecoin/arith_uint256.h \
include/dogecoin/auxpow.h \
include/dogecoin/base58.h \
include/dogecoin/bip32.h \
include/dogecoin/bip39.h \
Expand All @@ -33,6 +35,7 @@ noinst_HEADERS = \
include/dogecoin/byteswap.h \
include/dogecoin/chainparams.h \
include/dogecoin/common.h \
include/dogecoin/consensus.h \
include/dogecoin/cstr.h \
include/dogecoin/ctaes.h \
include/dogecoin/ecc.h \
Expand All @@ -44,6 +47,7 @@ noinst_HEADERS = \
include/dogecoin/mem.h \
include/dogecoin/moon.h \
include/dogecoin/portable_endian.h \
include/dogecoin/pow.h \
include/qr/png.h \
include/qr/qr.h \
include/qr/jpeg.h \
Expand All @@ -58,6 +62,7 @@ noinst_HEADERS = \
include/dogecoin/transaction.h \
include/dogecoin/tx.h \
include/dogecoin/utils.h \
include/dogecoin/validation.h \
include/dogecoin/vector.h \
include/dogecoin/wow.h

Expand All @@ -67,13 +72,16 @@ pkgconfig_DATA = libdogecoin.pc
libdogecoin_la_SOURCES = \
src/address.c \
src/aes.c \
src/arith_uint256.c \
src/auxpow.c \
src/base58.c \
src/bip32.c \
src/bip39.c \
src/bip44.c \
src/block.c \
src/buffer.c \
src/chainparams.c \
src/consensus.c \
src/cstr.c \
src/ctaes.c \
src/ecc.c \
Expand All @@ -83,6 +91,7 @@ libdogecoin_la_SOURCES = \
src/map.c \
src/mem.c \
src/moon.c \
src/pow.c \
src/png.c \
src/jpeg.c \
src/qrengine.c \
Expand All @@ -98,6 +107,7 @@ libdogecoin_la_SOURCES = \
src/transaction.c \
src/tx.c \
src/utils.c \
src/validation.c \
src/vector.c

if USE_SSE2
Expand Down
60 changes: 60 additions & 0 deletions include/dogecoin/arith_uint256.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
The MIT License (MIT)
Copyright (c) 2023 bluezr
Copyright (c) 2023 The Dogecoin Foundation
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef __LIBDOGECOIN_ARITH_UINT256_H__
#define __LIBDOGECOIN_ARITH_UINT256_H__

#include <assert.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>

#include <dogecoin/dogecoin.h>

LIBDOGECOIN_BEGIN_DECL

struct uint_err {
const char* str;
};

static unsigned int BITS;

typedef struct base_uint_ {
int WIDTH; // BITS / 32
uint32_t pn[]; // pn[WIDTH]
} base_uint_;

typedef base_uint_ arith_uint256;

arith_uint256 set_compact(arith_uint256 hash, uint32_t compact, dogecoin_bool *pf_negative, dogecoin_bool *pf_overflow);
uint256* arith_to_uint256(const arith_uint256 a);
arith_uint256 uint_to_arith(const uint256* a);
uint64_t get_low64(arith_uint256 pn);

LIBDOGECOIN_END_DECL

#endif // __LIBDOGECOIN_ARITH_UINT256_H__
49 changes: 49 additions & 0 deletions include/dogecoin/auxpow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
The MIT License (MIT)
Copyright (c) 2023 bluezr
Copyright (c) 2023 The Dogecoin Foundation
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef __LIBDOGECOIN_AUXPOW__
#define __LIBDOGECOIN_AUXPOW__

#include <dogecoin/block.h>
#include <dogecoin/dogecoin.h>
#include <dogecoin/tx.h>
#include <dogecoin/vector.h>

LIBDOGECOIN_BEGIN_DECL

#define BLOCK_VERSION_AUXPOW_BIT 0x100

/** Header for merge-mining data in the coinbase. */
static const unsigned char pchMergedMiningHeader[] = { 0xfa, 0xbe, 'm', 'm' };

int get_expected_index(uint32_t nNonce, int nChainId, unsigned h);
uint256* check_merkle_branch(uint256 hash, const vector* parent_coinbase_merkle, int n_index);
void init_aux_pow(dogecoin_block_header* block);

LIBDOGECOIN_END_DECL

#endif // __LIBDOGECOIN_AUXPOW__
15 changes: 14 additions & 1 deletion include/dogecoin/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,39 @@ LIBDOGECOIN_BEGIN_DECL
#include <dogecoin/map.h>
#include <dogecoin/tx.h>

typedef struct _auxpow {
dogecoin_bool is;
dogecoin_bool (*check)(void* ctx, uint256* hash, uint32_t chainid, dogecoin_chainparams* params);
void *ctx;
} auxpow;

typedef struct dogecoin_block_header_ {
int32_t version;
uint32_t version;
uint256 prev_block;
uint256 merkle_root;
uint32_t timestamp;
uint32_t bits;
uint32_t nonce;
auxpow auxpow[1];
} dogecoin_block_header;

typedef struct dogecoin_auxpow_block_ {
dogecoin_block_header* header;
dogecoin_tx* parent_coinbase;
uint256 parent_hash;
uint8_t parent_merkle_count;
uint256* parent_coinbase_merkle;
uint32_t parent_merkle_index;
uint8_t aux_merkle_count;
uint32_t aux_merkle_index;
dogecoin_block_header* parent_header;
} dogecoin_auxpow_block;

typedef struct dogecoin_block_ {
dogecoin_auxpow_block* block;
vector* vtx; // vector of transactions
} dogecoin_block;

LIBDOGECOIN_API dogecoin_block_header* dogecoin_block_header_new();
LIBDOGECOIN_API void dogecoin_block_header_free(dogecoin_block_header* header);
LIBDOGECOIN_API dogecoin_auxpow_block* dogecoin_auxpow_block_new();
Expand Down
3 changes: 3 additions & 0 deletions include/dogecoin/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ typedef struct dogecoin_chainparams_ {
uint256 genesisblockhash;
int default_port;
dogecoin_dns_seed dnsseeds[8];
dogecoin_bool strict_id;
dogecoin_bool auxpow_id;
uint256 pow_limit;
} dogecoin_chainparams;

typedef struct dogecoin_checkpoint_ {
Expand Down
1 change: 1 addition & 0 deletions include/dogecoin/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LIBDOGECOIN_BEGIN_DECL
#include <stdint.h>
#include <string.h>

#include <dogecoin/mem.h>
#include <dogecoin/portable_endian.h>
#include <dogecoin/utils.h>

Expand Down
Loading

0 comments on commit fc20793

Please sign in to comment.