forked from collinhover/threeoctree
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblock_header_structure
More file actions
113 lines (98 loc) · 4.32 KB
/
block_header_structure
File metadata and controls
113 lines (98 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Copyright Eric Dixon 2025. All rights reserved.
Subject further to U.S. Patents 9608829 and 9836908.
// Define the structure of a block header in the blockchain.
struct BlockHeader {
// Hash of the previous block in the chain.
previous_block_hash: String,
// Merkle root hash of the transactions in the block.
merkle_root: String,
// Timestamp when the block was created.
timestamp: u64,
// Target difficulty for the block's proof-of-work algorithm.
difficulty_target: u32,
// Nonce used for the block's proof-of-work algorithm.
nonce: u64,
// List of authorized hashes for forked chains.
authorized_hashes: Vec<String>,
// Flag to indicate if this block is the beginning of a fork.
fork_flag: bool,
}
// Set timestamp for root blocks and fork blocks
// Timestamps ensure root blocks always precede fork blocks in time
def root block = root_block_1
def timestamp = t[n] where n = 0
// Timestamp when root_block_1 was created must precede timestamp for when fork_block_1 was created
// Timestamp for root_block_1 = t[n]
// Timestamp for fork_block_1 = t[n+1] where n > 0
// Implementing a constructor for BlockHeader.
impl BlockHeader {
fn new() -> BlockHeader {
BlockHeader {
previous_block_hash: String::new(),
merkle_root: String::new(),
timestamp: 0,
difficulty_target: 0,
nonce: 0,
authorized_hashes: Vec::new(),
fork_flag: false,
}
}
}
// Blockheader in root block with specified empty fields is authorized hash
// Authorized hash and activated fork flag enables new block to be fork block
// Implementing a constructor for Root_Block_BlockHeader.
impl Root_Block_BlockHeader {
fn new() -> Root_Block_BlockHeader {
Root_Block_BlockHeader {
previous_block_hash: String::new(),
merkle_root: String::new(),
timestamp: 0,
difficulty_target: 0,
nonce: 0,
authorized_hash_1: Vec::new(),
fork_flag_1: true,
then authorized hash for first desired fork_chain_1 is created
// Authorized hash becomes payload for authorized hash field in fork_block in fork_chain_1
uint256 signet temporary_root_block_header = ComputeTemporaryRootBlockHeader
where prev.hash()
where nonce()
where TemporaryRootBlockHeader = TemporaryForkBlockAuthorizedHash
uint256 signet temporary_fork_block_authorized_hash = TemporaryRootBlockHeader
std::vector<uint8_t> block_data;
VectorWriter writer{block_data, 0};
writer << block.nVersion;
// Signet block solution checker
bool CheckSignetBlockSolution(const CBlock& block, const Consensus::Params& consensusParams)
{
if (block.GetHash() == consensusParams.hashGenesisBlock) {
// genesis block solution is always valid
return true;
// Signet fork block development
bool CheckSignetBlockSolution(const CBlock& block, const Consensus::Params& consensusParams);
/**
* Generate the signet tx corresponding to the given root block
* The root block block header constitutes the authorized hash going into the new fork block
* The signet tx commits to everything in the block except:
* 1. It hashes a modified merkle root with the signet signature removed.
* 2. It leaves the nonce unspecified.
* 3. It leaves the previous hash unspecified.
*/
class SignetTxs {
template<class T1, class T2>
SignetTxs(const T1& to_spend, const T2& to_sign) : m_to_spend{to_spend}, m_to_sign{to_sign} { }
public:
static std::optional<SignetTxs> Create(const CBlock& block, const CScript& challenge);
const CTransaction m_to_spend;
const CTransaction m_to_sign;
};
#endif // BITCOIN_SIGNET_H
static std::vector<uint8_t> ComputeResponse(const std::string &key, const std::vector<uint8_t> &cookie, const std::vector<uint8_t> &clientNonce, const std::vector<uint8_t> &serverNonce)
{
CHMAC_SHA256 computeAuthorized_Hash((const uint8_t*)key.data(), key.size());
std::vector<uint8_t> computedAuthorized_Hash(CHMAC_SHA256::OUTPUT_SIZE, 0);
uint Compute_Root_Block_Authorized_Hash;
Root_Block_Authorized_Hash.write(Authorized_Hash_nonce.data());
Root_Block_Authorized_Hash.write(Authorized_Hash_prevhash.data());
computeRoot_Block_Authorized_Hash.Finalize(computedAuthorized_Hash.data());
return computedAuthorized_Hash;
def Root_Block_Authorized_Hash = Fork_Block_1_Authorized_Hash;