From 8c44c904efc7ce6fc8b35c61f54b17dcdbf46498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kami=C5=84ski?= Date: Fri, 2 Aug 2024 11:38:52 +0200 Subject: [PATCH 1/2] draft of validate_merkle_root --- src/state.cairo | 18 ++++++++++++++++++ src/validation.cairo | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/state.cairo b/src/state.cairo index b1a75261..6bbb5b4e 100644 --- a/src/state.cairo +++ b/src/state.cairo @@ -3,16 +3,22 @@ pub struct ChainState { /// Height of the current block. pub block_height: u32, // not u256? + /// Total work done. pub total_work: u256, + /// Best block. pub best_block_hash: u256, + /// Current block. pub current_target: u32, + /// Start of the current epoch. pub epoch_start_time: u32, + /// Previous timestamps. pub prev_timestamps: Span, + // TODO: utreexo_roots? } @@ -34,14 +40,19 @@ pub struct Block { struct Header { /// The version of the block. pub version: u32, + /// The hash of the previous block in the blockchain. pub prev_block_hash: u256, + /// The Merkle root hash of the transactions in the block. pub merkle_root_hash: u256, + /// The timestamp of the block. pub time: u32, + /// The difficulty target for mining the block. pub bits: u32, + /// The nonce used in mining the block. pub nonce: u32, } @@ -52,10 +63,13 @@ struct Header { pub struct Transaction { /// The version of the transaction. pub version: i32, + /// The inputs of the transaction. pub inputs: Span, + /// The outputs of the transaction. pub outputs: Span, + /// The lock time of the transaction. pub lock_time: u32, } @@ -66,6 +80,7 @@ pub struct Transaction { pub struct TxOut { /// The value of the output. value: i64, + /// The public key script of the output. pk_script: @ByteArray, } @@ -76,10 +91,13 @@ pub struct TxOut { pub struct TxIn { /// The transaction ID of the input. txid: u256, + /// The index of the input. index: u32, + /// The script of the input. script: @ByteArray, + /// The sequence of the input. sequence: u32, } diff --git a/src/validation.cairo b/src/validation.cairo index f0e13c76..18d9f856 100644 --- a/src/validation.cairo +++ b/src/validation.cairo @@ -8,7 +8,7 @@ impl BlockValidatorImpl of BlockValidator { validate_target(@self, @block)?; validate_timestamp(@self, @block)?; - // validate_merkle_root + validate_merkle_root(@self, @block)?; // validate_and_apply_transactions let prev_timestamps = next_prev_timestamps(@self, @block); @@ -58,3 +58,8 @@ fn adjust_difficulty(self: @ChainState, block: @Block) -> (u32, u32) { // TODO: implement (*self.current_target, *self.epoch_start_time) } + +fn validate_merkle_root(self: @ChainState, block: @Block) -> Result<(), ByteArray> { + // TODO: implement + Result::Ok(()) +} \ No newline at end of file From b33b6ab2977c8c2d93002df99c195766d9baf1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kami=C5=84ski?= Date: Fri, 2 Aug 2024 11:41:14 +0200 Subject: [PATCH 2/2] fmt --- src/state.cairo | 18 ------------------ src/validation.cairo | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/state.cairo b/src/state.cairo index 6bbb5b4e..b1a75261 100644 --- a/src/state.cairo +++ b/src/state.cairo @@ -3,22 +3,16 @@ pub struct ChainState { /// Height of the current block. pub block_height: u32, // not u256? - /// Total work done. pub total_work: u256, - /// Best block. pub best_block_hash: u256, - /// Current block. pub current_target: u32, - /// Start of the current epoch. pub epoch_start_time: u32, - /// Previous timestamps. pub prev_timestamps: Span, - // TODO: utreexo_roots? } @@ -40,19 +34,14 @@ pub struct Block { struct Header { /// The version of the block. pub version: u32, - /// The hash of the previous block in the blockchain. pub prev_block_hash: u256, - /// The Merkle root hash of the transactions in the block. pub merkle_root_hash: u256, - /// The timestamp of the block. pub time: u32, - /// The difficulty target for mining the block. pub bits: u32, - /// The nonce used in mining the block. pub nonce: u32, } @@ -63,13 +52,10 @@ struct Header { pub struct Transaction { /// The version of the transaction. pub version: i32, - /// The inputs of the transaction. pub inputs: Span, - /// The outputs of the transaction. pub outputs: Span, - /// The lock time of the transaction. pub lock_time: u32, } @@ -80,7 +66,6 @@ pub struct Transaction { pub struct TxOut { /// The value of the output. value: i64, - /// The public key script of the output. pk_script: @ByteArray, } @@ -91,13 +76,10 @@ pub struct TxOut { pub struct TxIn { /// The transaction ID of the input. txid: u256, - /// The index of the input. index: u32, - /// The script of the input. script: @ByteArray, - /// The sequence of the input. sequence: u32, } diff --git a/src/validation.cairo b/src/validation.cairo index 18d9f856..1071898f 100644 --- a/src/validation.cairo +++ b/src/validation.cairo @@ -62,4 +62,4 @@ fn adjust_difficulty(self: @ChainState, block: @Block) -> (u32, u32) { fn validate_merkle_root(self: @ChainState, block: @Block) -> Result<(), ByteArray> { // TODO: implement Result::Ok(()) -} \ No newline at end of file +}