mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-03 06:13:07 +00:00
Derive clone for txn RLP structs (#1264)
* Derive Clone for txn rlp structs * Put txn rlp related structs behind testing module * Move module to end of file
This commit is contained in:
parent
0f19cd0dbc
commit
cd36e96cb8
@ -33,92 +33,14 @@ impl Default for AccountRlp {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug)]
|
||||
pub struct AccessListItemRlp {
|
||||
pub address: Address,
|
||||
pub storage_keys: Vec<U256>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AddressOption(pub Option<Address>);
|
||||
|
||||
impl Encodable for AddressOption {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
match self.0 {
|
||||
None => {
|
||||
s.append_empty_data();
|
||||
}
|
||||
Some(value) => {
|
||||
s.encoder().encode_value(&value.to_fixed_bytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for AddressOption {
|
||||
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
|
||||
if rlp.is_int() && rlp.is_empty() {
|
||||
return Ok(AddressOption(None));
|
||||
}
|
||||
if rlp.is_data() && rlp.size() == 20 {
|
||||
return Ok(AddressOption(Some(Address::decode(rlp)?)));
|
||||
}
|
||||
Err(DecoderError::RlpExpectedToBeData)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug)]
|
||||
pub struct LegacyTransactionRlp {
|
||||
pub nonce: U256,
|
||||
pub gas_price: U256,
|
||||
pub gas: U256,
|
||||
pub to: AddressOption,
|
||||
pub value: U256,
|
||||
pub data: Bytes,
|
||||
pub v: U256,
|
||||
pub r: U256,
|
||||
pub s: U256,
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug)]
|
||||
pub struct AccessListTransactionRlp {
|
||||
pub chain_id: u64,
|
||||
pub nonce: U256,
|
||||
pub gas_price: U256,
|
||||
pub gas: U256,
|
||||
pub to: AddressOption,
|
||||
pub value: U256,
|
||||
pub data: Bytes,
|
||||
pub access_list: Vec<AccessListItemRlp>,
|
||||
pub y_parity: U256,
|
||||
pub r: U256,
|
||||
pub s: U256,
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug)]
|
||||
pub struct FeeMarketTransactionRlp {
|
||||
pub chain_id: u64,
|
||||
pub nonce: U256,
|
||||
pub max_priority_fee_per_gas: U256,
|
||||
pub max_fee_per_gas: U256,
|
||||
pub gas: U256,
|
||||
pub to: AddressOption,
|
||||
pub value: U256,
|
||||
pub data: Bytes,
|
||||
pub access_list: Vec<AccessListItemRlp>,
|
||||
pub y_parity: U256,
|
||||
pub r: U256,
|
||||
pub s: U256,
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug)]
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug, Clone)]
|
||||
pub struct LogRlp {
|
||||
pub address: Address,
|
||||
pub topics: Vec<H256>,
|
||||
pub data: Bytes,
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug)]
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug, Clone)]
|
||||
pub struct LegacyReceiptRlp {
|
||||
pub status: bool,
|
||||
pub cum_gas_used: U256,
|
||||
@ -356,3 +278,85 @@ fn empty_nibbles() -> Nibbles {
|
||||
packed: U512::zero(),
|
||||
}
|
||||
}
|
||||
|
||||
pub mod transaction_testing {
|
||||
use super::*;
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug, Clone)]
|
||||
pub struct AccessListItemRlp {
|
||||
pub address: Address,
|
||||
pub storage_keys: Vec<U256>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AddressOption(pub Option<Address>);
|
||||
|
||||
impl Encodable for AddressOption {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
match self.0 {
|
||||
None => {
|
||||
s.append_empty_data();
|
||||
}
|
||||
Some(value) => {
|
||||
s.encoder().encode_value(&value.to_fixed_bytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for AddressOption {
|
||||
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
|
||||
if rlp.is_int() && rlp.is_empty() {
|
||||
return Ok(AddressOption(None));
|
||||
}
|
||||
if rlp.is_data() && rlp.size() == 20 {
|
||||
return Ok(AddressOption(Some(Address::decode(rlp)?)));
|
||||
}
|
||||
Err(DecoderError::RlpExpectedToBeData)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug, Clone)]
|
||||
pub struct LegacyTransactionRlp {
|
||||
pub nonce: U256,
|
||||
pub gas_price: U256,
|
||||
pub gas: U256,
|
||||
pub to: AddressOption,
|
||||
pub value: U256,
|
||||
pub data: Bytes,
|
||||
pub v: U256,
|
||||
pub r: U256,
|
||||
pub s: U256,
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug, Clone)]
|
||||
pub struct AccessListTransactionRlp {
|
||||
pub chain_id: u64,
|
||||
pub nonce: U256,
|
||||
pub gas_price: U256,
|
||||
pub gas: U256,
|
||||
pub to: AddressOption,
|
||||
pub value: U256,
|
||||
pub data: Bytes,
|
||||
pub access_list: Vec<AccessListItemRlp>,
|
||||
pub y_parity: U256,
|
||||
pub r: U256,
|
||||
pub s: U256,
|
||||
}
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug, Clone)]
|
||||
pub struct FeeMarketTransactionRlp {
|
||||
pub chain_id: u64,
|
||||
pub nonce: U256,
|
||||
pub max_priority_fee_per_gas: U256,
|
||||
pub max_fee_per_gas: U256,
|
||||
pub gas: U256,
|
||||
pub to: AddressOption,
|
||||
pub value: U256,
|
||||
pub data: Bytes,
|
||||
pub access_list: Vec<AccessListItemRlp>,
|
||||
pub y_parity: U256,
|
||||
pub r: U256,
|
||||
pub s: U256,
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,9 +17,8 @@ use plonky2::util::timing::TimingTree;
|
||||
use plonky2_evm::all_stark::AllStark;
|
||||
use plonky2_evm::config::StarkConfig;
|
||||
use plonky2_evm::fixed_recursive_verifier::AllRecursiveCircuits;
|
||||
use plonky2_evm::generation::mpt::{
|
||||
AccountRlp, AddressOption, LegacyReceiptRlp, LegacyTransactionRlp, LogRlp,
|
||||
};
|
||||
use plonky2_evm::generation::mpt::transaction_testing::{AddressOption, LegacyTransactionRlp};
|
||||
use plonky2_evm::generation::mpt::{AccountRlp, LegacyReceiptRlp, LogRlp};
|
||||
use plonky2_evm::generation::{GenerationInputs, TrieInputs};
|
||||
use plonky2_evm::proof::{BlockHashes, BlockMetadata, ExtraBlockData, PublicValues, TrieRoots};
|
||||
use plonky2_evm::prover::prove;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user