-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: nuking old
BlockHeader
(#4154)
Fixes #3937 Fixes #3564 Fixes #4134
- Loading branch information
1 parent
b97849b
commit d5bc0c2
Showing
10 changed files
with
85 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use dep::std::merkle::compute_merkle_root; | ||
use dep::protocol_types::{ | ||
constants::HEADER_LENGTH, | ||
header::Header, | ||
}; | ||
|
||
use crate::{ | ||
context::PrivateContext, | ||
oracle::get_membership_witness::get_archive_membership_witness, | ||
}; | ||
|
||
#[oracle(getHeader)] | ||
fn get_header_at_oracle(_block_number: u32) -> [Field; HEADER_LENGTH] {} | ||
|
||
unconstrained pub fn get_header_at_internal(block_number: u32) -> Header { | ||
let header = get_header_at_oracle(block_number); | ||
Header::deserialize(header) | ||
} | ||
|
||
pub fn get_header_at(block_number: u32, context: PrivateContext) -> Header { | ||
// 1) Get block number corresponding to the last_archive root in the header | ||
// Note: We subtract 1 because the last_archive root is the root of the archive after applying the previous block | ||
let last_archive_block_number = (context.historical_header.global_variables.block_number - 1) as u32; | ||
|
||
// 2) Check that the last archive block number is more than or equal to the block number we want to prove against | ||
// We could not perform the proof otherwise because the last archive root from the header would not "contain" | ||
// the header we want to prove against | ||
assert( | ||
last_archive_block_number >= block_number, "Last archive block number is smaller than the block number we want to prove against" | ||
); | ||
|
||
// 3) Get the header of a given block from oracle | ||
let header = get_header_at_internal(block_number); | ||
|
||
// 4) Compute the block hash from the block header | ||
let block_hash = header.block_hash(); | ||
|
||
// 5) Get the membership witness of the block in the archive | ||
let witness = get_archive_membership_witness(last_archive_block_number, block_hash); | ||
|
||
// 6) Check that the block is in the archive (i.e. the witness is valid) | ||
assert( | ||
context.historical_header.last_archive.root | ||
== compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in archive failed" | ||
); | ||
|
||
// 7) Return the block header | ||
header | ||
} |