mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 00:33:06 +00:00
Apply comments
This commit is contained in:
parent
42f7038031
commit
4e0fe74a74
@ -249,7 +249,7 @@ global blockhash:
|
||||
// stack: cur_block_number, block_number, retdest
|
||||
DUP1 DUP3 %increment GT %jumpi(zero_hash) // if block_number >= cur_block_number
|
||||
// stack: cur_block_number, block_number, retdest
|
||||
DUP2 PUSH 256 ADD
|
||||
DUP2 PUSH 256 %add_or_fault
|
||||
// stack: block_number+256, cur_block_number, block_number, retdest
|
||||
DUP2 GT %jumpi(zero_hash) // if cur_block_number > block_number + 256
|
||||
// If we are here, the provided block number is correct
|
||||
|
||||
@ -76,7 +76,7 @@ fn test_small_index_block_hash() -> Result<()> {
|
||||
let block_number = rng.gen::<u8>() as usize;
|
||||
let initial_stack = vec![retdest, block_number.into()];
|
||||
|
||||
let hashes: Vec<U256> = (20..277).map(|elt| elt.into()).collect();
|
||||
let hashes: Vec<U256> = vec![U256::from_big_endian(&thread_rng().gen::<H256>().0); 257];
|
||||
|
||||
let mut interpreter = Interpreter::new_with_kernel(blockhash_label, initial_stack);
|
||||
interpreter.set_memory_segment(Segment::BlockHashes, hashes[0..256].to_vec());
|
||||
@ -95,3 +95,21 @@ fn test_small_index_block_hash() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_block_hash_with_overflow() {
|
||||
let blockhash_label = KERNEL.global_labels["blockhash"];
|
||||
let retdest = 0xDEADBEEFu32.into();
|
||||
let cur_block_number = 1;
|
||||
let block_number = U256::MAX;
|
||||
let initial_stack = vec![retdest, block_number];
|
||||
|
||||
let hashes: Vec<U256> = vec![U256::from_big_endian(&thread_rng().gen::<H256>().0); 257];
|
||||
|
||||
let mut interpreter = Interpreter::new_with_kernel(blockhash_label, initial_stack);
|
||||
interpreter.set_memory_segment(Segment::BlockHashes, hashes[0..256].to_vec());
|
||||
interpreter.set_global_metadata_field(GlobalMetadata::BlockCurrentHash, hashes[256]);
|
||||
interpreter.set_global_metadata_field(GlobalMetadata::BlockNumber, cur_block_number.into());
|
||||
let _ = interpreter.run();
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ fn apply_metadata_and_tries_memops<F: RichField + Extendable<D>, const D: usize>
|
||||
(GlobalMetadata::BlockBaseFee, metadata.block_base_fee),
|
||||
(
|
||||
GlobalMetadata::BlockCurrentHash,
|
||||
U256::from_big_endian(&inputs.block_hashes.cur_hash.0),
|
||||
h2u(inputs.block_hashes.cur_hash),
|
||||
),
|
||||
(GlobalMetadata::BlockGasUsed, metadata.block_gas_used),
|
||||
(GlobalMetadata::BlockGasUsedBefore, inputs.gas_used_before),
|
||||
|
||||
@ -13,7 +13,7 @@ use crate::permutation::{
|
||||
get_n_grand_product_challenge_sets_target,
|
||||
};
|
||||
use crate::proof::*;
|
||||
use crate::util::u256_limbs;
|
||||
use crate::util::{h256_limbs, u256_limbs};
|
||||
|
||||
fn observe_root<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>(
|
||||
challenger: &mut Challenger<F, C::Hasher>,
|
||||
@ -155,12 +155,9 @@ fn observe_block_hashes<
|
||||
block_hashes: &BlockHashes,
|
||||
) {
|
||||
for i in 0..256 {
|
||||
challenger.observe_elements(
|
||||
&u256_limbs::<F>(U256::from_big_endian(&block_hashes.prev_hashes[i].0))[0..8],
|
||||
);
|
||||
challenger.observe_elements(&h256_limbs::<F>(block_hashes.prev_hashes[i])[0..8]);
|
||||
}
|
||||
challenger
|
||||
.observe_elements(&u256_limbs::<F>(U256::from_big_endian(&block_hashes.cur_hash.0))[0..8])
|
||||
challenger.observe_elements(&h256_limbs::<F>(block_hashes.cur_hash)[0..8])
|
||||
}
|
||||
|
||||
fn observe_block_hashes_target<
|
||||
|
||||
@ -43,7 +43,7 @@ use crate::proof::{
|
||||
TrieRootsTarget,
|
||||
};
|
||||
use crate::stark::Stark;
|
||||
use crate::util::u256_limbs;
|
||||
use crate::util::{h256_limbs, u256_limbs};
|
||||
use crate::vanishing_poly::eval_vanishing_poly_circuit;
|
||||
use crate::vars::StarkEvaluationTargets;
|
||||
|
||||
@ -1057,8 +1057,7 @@ pub(crate) fn set_block_hashes_target<F, W, const D: usize>(
|
||||
W: Witness<F>,
|
||||
{
|
||||
for i in 0..256 {
|
||||
let block_hash_limbs: [F; 8] =
|
||||
u256_limbs::<F>(U256::from_big_endian(&block_hashes.prev_hashes[i].0))[..8]
|
||||
let block_hash_limbs: [F; 8] = h256_limbs::<F>(block_hashes.prev_hashes[i])[..8]
|
||||
.try_into()
|
||||
.unwrap();
|
||||
witness.set_target_arr(
|
||||
@ -1066,8 +1065,7 @@ pub(crate) fn set_block_hashes_target<F, W, const D: usize>(
|
||||
&block_hash_limbs,
|
||||
);
|
||||
}
|
||||
let cur_block_hash_limbs: [F; 8] =
|
||||
u256_limbs::<F>(U256::from_big_endian(&block_hashes.cur_hash.0))[..8]
|
||||
let cur_block_hash_limbs: [F; 8] = h256_limbs::<F>(block_hashes.cur_hash)[..8]
|
||||
.try_into()
|
||||
.unwrap();
|
||||
witness.set_target_arr(&block_hashes_target.cur_hash, &cur_block_hash_limbs);
|
||||
|
||||
@ -178,7 +178,7 @@ where
|
||||
),
|
||||
(
|
||||
GlobalMetadata::BlockCurrentHash,
|
||||
U256::from_big_endian(&public_values.block_hashes.cur_hash.0),
|
||||
h2u(public_values.block_hashes.cur_hash),
|
||||
),
|
||||
(
|
||||
GlobalMetadata::BlockGasUsed,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user