mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 08:43:06 +00:00
Update BlockBaseFee to fit in 2 limbs
This commit is contained in:
parent
c138f2d64f
commit
9a4500683b
@ -570,7 +570,7 @@ where
|
|||||||
let mut prod = builder.constant(F::ONE);
|
let mut prod = builder.constant(F::ONE);
|
||||||
|
|
||||||
// Add metadata writes.
|
// Add metadata writes.
|
||||||
let block_fields_without_beneficiary = [
|
let block_fields_without_beneficiary_and_basefee = [
|
||||||
(
|
(
|
||||||
GlobalMetadata::BlockTimestamp,
|
GlobalMetadata::BlockTimestamp,
|
||||||
public_values.block_metadata.block_timestamp,
|
public_values.block_metadata.block_timestamp,
|
||||||
@ -591,16 +591,13 @@ where
|
|||||||
GlobalMetadata::BlockChainId,
|
GlobalMetadata::BlockChainId,
|
||||||
public_values.block_metadata.block_chain_id,
|
public_values.block_metadata.block_chain_id,
|
||||||
),
|
),
|
||||||
(
|
|
||||||
GlobalMetadata::BlockBaseFee,
|
|
||||||
public_values.block_metadata.block_base_fee,
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let zero = builder.constant(F::ZERO);
|
let zero = builder.constant(F::ZERO);
|
||||||
let one = builder.constant(F::ONE);
|
let one = builder.constant(F::ONE);
|
||||||
let segment = builder.constant(F::from_canonical_u32(Segment::GlobalMetadata as u32));
|
let segment = builder.constant(F::from_canonical_u32(Segment::GlobalMetadata as u32));
|
||||||
|
|
||||||
|
// Include the block beneficiary.
|
||||||
let row = builder.add_virtual_targets(13);
|
let row = builder.add_virtual_targets(13);
|
||||||
// is_read
|
// is_read
|
||||||
builder.connect(row[0], zero);
|
builder.connect(row[0], zero);
|
||||||
@ -629,7 +626,7 @@ where
|
|||||||
let combined = challenge.combine_base_circuit(builder, &row);
|
let combined = challenge.combine_base_circuit(builder, &row);
|
||||||
prod = builder.mul(prod, combined);
|
prod = builder.mul(prod, combined);
|
||||||
|
|
||||||
block_fields_without_beneficiary.map(|(field, target)| {
|
block_fields_without_beneficiary_and_basefee.map(|(field, target)| {
|
||||||
let row = builder.add_virtual_targets(13);
|
let row = builder.add_virtual_targets(13);
|
||||||
// is_read
|
// is_read
|
||||||
builder.connect(row[0], zero);
|
builder.connect(row[0], zero);
|
||||||
@ -651,6 +648,32 @@ where
|
|||||||
prod = builder.mul(prod, combined);
|
prod = builder.mul(prod, combined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Include the block base fee.
|
||||||
|
let row = builder.add_virtual_targets(13);
|
||||||
|
// is_read
|
||||||
|
builder.connect(row[0], zero);
|
||||||
|
// context
|
||||||
|
builder.connect(row[1], zero);
|
||||||
|
// segment
|
||||||
|
builder.connect(row[2], segment);
|
||||||
|
// virtual
|
||||||
|
let field_target = builder.constant(F::from_canonical_usize(
|
||||||
|
GlobalMetadata::BlockBaseFee as usize,
|
||||||
|
));
|
||||||
|
builder.connect(row[3], field_target);
|
||||||
|
// values
|
||||||
|
for j in 0..2 {
|
||||||
|
builder.connect(row[4 + j], public_values.block_metadata.block_base_fee[j]);
|
||||||
|
}
|
||||||
|
for j in 2..VALUE_LIMBS {
|
||||||
|
builder.connect(row[4 + j], zero);
|
||||||
|
}
|
||||||
|
// timestamp
|
||||||
|
builder.connect(row[12], one);
|
||||||
|
|
||||||
|
let combined = challenge.combine_base_circuit(builder, &row);
|
||||||
|
prod = builder.mul(prod, combined);
|
||||||
|
|
||||||
// Add trie roots writes.
|
// Add trie roots writes.
|
||||||
let trie_fields = [
|
let trie_fields = [
|
||||||
(
|
(
|
||||||
|
|||||||
@ -74,7 +74,10 @@ fn observe_block_metadata<
|
|||||||
block_metadata.block_chain_id.as_u32(),
|
block_metadata.block_chain_id.as_u32(),
|
||||||
));
|
));
|
||||||
challenger.observe_element(F::from_canonical_u32(
|
challenger.observe_element(F::from_canonical_u32(
|
||||||
block_metadata.block_base_fee.as_u32(),
|
block_metadata.block_base_fee.as_u64() as u32,
|
||||||
|
));
|
||||||
|
challenger.observe_element(F::from_canonical_u32(
|
||||||
|
(block_metadata.block_base_fee.as_u64() >> 32) as u32,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +97,7 @@ fn observe_block_metadata_target<
|
|||||||
challenger.observe_element(block_metadata.block_difficulty);
|
challenger.observe_element(block_metadata.block_difficulty);
|
||||||
challenger.observe_element(block_metadata.block_gaslimit);
|
challenger.observe_element(block_metadata.block_gaslimit);
|
||||||
challenger.observe_element(block_metadata.block_chain_id);
|
challenger.observe_element(block_metadata.block_chain_id);
|
||||||
challenger.observe_element(block_metadata.block_base_fee);
|
challenger.observe_elements(&block_metadata.block_base_fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn observe_public_values<
|
pub(crate) fn observe_public_values<
|
||||||
|
|||||||
@ -120,7 +120,7 @@ impl PublicValuesTarget {
|
|||||||
buffer.write_target(block_difficulty)?;
|
buffer.write_target(block_difficulty)?;
|
||||||
buffer.write_target(block_gaslimit)?;
|
buffer.write_target(block_gaslimit)?;
|
||||||
buffer.write_target(block_chain_id)?;
|
buffer.write_target(block_chain_id)?;
|
||||||
buffer.write_target(block_base_fee)?;
|
buffer.write_target_vec(&block_base_fee)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ impl PublicValuesTarget {
|
|||||||
block_difficulty: buffer.read_target()?,
|
block_difficulty: buffer.read_target()?,
|
||||||
block_gaslimit: buffer.read_target()?,
|
block_gaslimit: buffer.read_target()?,
|
||||||
block_chain_id: buffer.read_target()?,
|
block_chain_id: buffer.read_target()?,
|
||||||
block_base_fee: buffer.read_target()?,
|
block_base_fee: buffer.read_target_vec()?.try_into().unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@ -264,11 +264,11 @@ pub struct BlockMetadataTarget {
|
|||||||
pub block_difficulty: Target,
|
pub block_difficulty: Target,
|
||||||
pub block_gaslimit: Target,
|
pub block_gaslimit: Target,
|
||||||
pub block_chain_id: Target,
|
pub block_chain_id: Target,
|
||||||
pub block_base_fee: Target,
|
pub block_base_fee: [Target; 2],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockMetadataTarget {
|
impl BlockMetadataTarget {
|
||||||
const SIZE: usize = 11;
|
const SIZE: usize = 12;
|
||||||
|
|
||||||
pub fn from_public_inputs(pis: &[Target]) -> Self {
|
pub fn from_public_inputs(pis: &[Target]) -> Self {
|
||||||
let block_beneficiary = pis[0..5].try_into().unwrap();
|
let block_beneficiary = pis[0..5].try_into().unwrap();
|
||||||
@ -277,7 +277,7 @@ impl BlockMetadataTarget {
|
|||||||
let block_difficulty = pis[7];
|
let block_difficulty = pis[7];
|
||||||
let block_gaslimit = pis[8];
|
let block_gaslimit = pis[8];
|
||||||
let block_chain_id = pis[9];
|
let block_chain_id = pis[9];
|
||||||
let block_base_fee = pis[10];
|
let block_base_fee = pis[10..12].try_into().unwrap();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
block_beneficiary,
|
block_beneficiary,
|
||||||
@ -309,7 +309,9 @@ impl BlockMetadataTarget {
|
|||||||
block_difficulty: builder.select(condition, bm0.block_difficulty, bm1.block_difficulty),
|
block_difficulty: builder.select(condition, bm0.block_difficulty, bm1.block_difficulty),
|
||||||
block_gaslimit: builder.select(condition, bm0.block_gaslimit, bm1.block_gaslimit),
|
block_gaslimit: builder.select(condition, bm0.block_gaslimit, bm1.block_gaslimit),
|
||||||
block_chain_id: builder.select(condition, bm0.block_chain_id, bm1.block_chain_id),
|
block_chain_id: builder.select(condition, bm0.block_chain_id, bm1.block_chain_id),
|
||||||
block_base_fee: builder.select(condition, bm0.block_base_fee, bm1.block_base_fee),
|
block_base_fee: core::array::from_fn(|i| {
|
||||||
|
builder.select(condition, bm0.block_base_fee[i], bm1.block_base_fee[i])
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +328,9 @@ impl BlockMetadataTarget {
|
|||||||
builder.connect(bm0.block_difficulty, bm1.block_difficulty);
|
builder.connect(bm0.block_difficulty, bm1.block_difficulty);
|
||||||
builder.connect(bm0.block_gaslimit, bm1.block_gaslimit);
|
builder.connect(bm0.block_gaslimit, bm1.block_gaslimit);
|
||||||
builder.connect(bm0.block_chain_id, bm1.block_chain_id);
|
builder.connect(bm0.block_chain_id, bm1.block_chain_id);
|
||||||
builder.connect(bm0.block_base_fee, bm1.block_base_fee);
|
for i in 0..2 {
|
||||||
|
builder.connect(bm0.block_base_fee[i], bm1.block_base_fee[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -548,7 +548,7 @@ pub(crate) fn add_virtual_block_metadata<F: RichField + Extendable<D>, const D:
|
|||||||
let block_difficulty = builder.add_virtual_public_input();
|
let block_difficulty = builder.add_virtual_public_input();
|
||||||
let block_gaslimit = builder.add_virtual_public_input();
|
let block_gaslimit = builder.add_virtual_public_input();
|
||||||
let block_chain_id = builder.add_virtual_public_input();
|
let block_chain_id = builder.add_virtual_public_input();
|
||||||
let block_base_fee = builder.add_virtual_public_input();
|
let block_base_fee = builder.add_virtual_public_input_arr();
|
||||||
BlockMetadataTarget {
|
BlockMetadataTarget {
|
||||||
block_beneficiary,
|
block_beneficiary,
|
||||||
block_timestamp,
|
block_timestamp,
|
||||||
@ -749,8 +749,13 @@ pub(crate) fn set_block_metadata_target<F, W, const D: usize>(
|
|||||||
block_metadata_target.block_chain_id,
|
block_metadata_target.block_chain_id,
|
||||||
F::from_canonical_u32(block_metadata.block_chain_id.as_u32()),
|
F::from_canonical_u32(block_metadata.block_chain_id.as_u32()),
|
||||||
);
|
);
|
||||||
|
// Basefee fits in 2 limbs
|
||||||
witness.set_target(
|
witness.set_target(
|
||||||
block_metadata_target.block_base_fee,
|
block_metadata_target.block_base_fee[0],
|
||||||
F::from_canonical_u32(block_metadata.block_base_fee.as_u32()),
|
F::from_canonical_u32(block_metadata.block_base_fee.as_u64() as u32),
|
||||||
|
);
|
||||||
|
witness.set_target(
|
||||||
|
block_metadata_target.block_base_fee[1],
|
||||||
|
F::from_canonical_u32((block_metadata.block_base_fee.as_u64() >> 32) as u32),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user