|
| 1 | +use alloy::consensus::{Header, Sealed}; |
| 2 | +use alloy::primitives::Log; |
| 3 | +use basic_bootloader::bootloader::block_header::BlockHeader; |
| 4 | +use ruint::aliases::B160; |
| 5 | +use zk_ee::common_structs::GenericEventContent; |
| 6 | +use zk_ee::system::metadata::{BlockHashes, BlockMetadataFromOracle}; |
| 7 | +use zk_ee::types_config::EthereumIOTypesConfig; |
| 8 | +use zksync_os_interface::error::{AAMethod, InvalidTransaction}; |
| 9 | +use zksync_os_interface::types::{BlockContext, L2ToL1Log}; |
| 10 | + |
| 11 | +pub trait FromInterface<T> { |
| 12 | + fn from_interface(value: T) -> Self; |
| 13 | +} |
| 14 | + |
| 15 | +pub trait IntoInterface<T> { |
| 16 | + fn into_interface(self) -> T; |
| 17 | +} |
| 18 | + |
| 19 | +impl FromInterface<BlockContext> for BlockMetadataFromOracle { |
| 20 | + fn from_interface(value: BlockContext) -> Self { |
| 21 | + BlockMetadataFromOracle { |
| 22 | + chain_id: value.chain_id, |
| 23 | + block_number: value.block_number, |
| 24 | + block_hashes: BlockHashes(value.block_hashes.0), |
| 25 | + timestamp: value.timestamp, |
| 26 | + eip1559_basefee: value.eip1559_basefee, |
| 27 | + gas_per_pubdata: value.gas_per_pubdata, |
| 28 | + native_price: value.native_price, |
| 29 | + coinbase: B160::from_be_bytes(value.coinbase.0 .0), |
| 30 | + gas_limit: value.gas_limit, |
| 31 | + pubdata_limit: value.pubdata_limit, |
| 32 | + mix_hash: value.mix_hash, |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +impl IntoInterface<InvalidTransaction> |
| 38 | + for basic_bootloader::bootloader::errors::InvalidTransaction |
| 39 | +{ |
| 40 | + fn into_interface(self) -> InvalidTransaction { |
| 41 | + match self { |
| 42 | + basic_bootloader::bootloader::errors::InvalidTransaction::InvalidEncoding => { InvalidTransaction::InvalidEncoding } |
| 43 | + basic_bootloader::bootloader::errors::InvalidTransaction::InvalidStructure => { InvalidTransaction::InvalidStructure } |
| 44 | + basic_bootloader::bootloader::errors::InvalidTransaction::PriorityFeeGreaterThanMaxFee => { InvalidTransaction::PriorityFeeGreaterThanMaxFee } |
| 45 | + basic_bootloader::bootloader::errors::InvalidTransaction::BaseFeeGreaterThanMaxFee => { InvalidTransaction::BaseFeeGreaterThanMaxFee } |
| 46 | + basic_bootloader::bootloader::errors::InvalidTransaction::GasPriceLessThanBasefee => { InvalidTransaction::GasPriceLessThanBasefee } |
| 47 | + basic_bootloader::bootloader::errors::InvalidTransaction::CallerGasLimitMoreThanBlock => { InvalidTransaction::CallerGasLimitMoreThanBlock } |
| 48 | + basic_bootloader::bootloader::errors::InvalidTransaction::CallGasCostMoreThanGasLimit => { InvalidTransaction::CallGasCostMoreThanGasLimit } |
| 49 | + basic_bootloader::bootloader::errors::InvalidTransaction::RejectCallerWithCode => { InvalidTransaction::RejectCallerWithCode } |
| 50 | + basic_bootloader::bootloader::errors::InvalidTransaction::LackOfFundForMaxFee { fee, balance } => { InvalidTransaction::LackOfFundForMaxFee { fee, balance } } |
| 51 | + basic_bootloader::bootloader::errors::InvalidTransaction::OverflowPaymentInTransaction => { InvalidTransaction::OverflowPaymentInTransaction } |
| 52 | + basic_bootloader::bootloader::errors::InvalidTransaction::NonceOverflowInTransaction => { InvalidTransaction::NonceOverflowInTransaction } |
| 53 | + basic_bootloader::bootloader::errors::InvalidTransaction::NonceTooHigh { tx, state } => { InvalidTransaction::NonceTooHigh { tx, state } } |
| 54 | + basic_bootloader::bootloader::errors::InvalidTransaction::NonceTooLow { tx, state } => { InvalidTransaction::NonceTooLow { tx, state } } |
| 55 | + basic_bootloader::bootloader::errors::InvalidTransaction::MalleableSignature => { InvalidTransaction::MalleableSignature } |
| 56 | + basic_bootloader::bootloader::errors::InvalidTransaction::IncorrectFrom { tx, recovered } => { InvalidTransaction::IncorrectFrom { tx: tx.to_be_bytes().into(), recovered: recovered.to_be_bytes().into() } } |
| 57 | + basic_bootloader::bootloader::errors::InvalidTransaction::CreateInitCodeSizeLimit => { InvalidTransaction::CreateInitCodeSizeLimit } |
| 58 | + basic_bootloader::bootloader::errors::InvalidTransaction::InvalidChainId => { InvalidTransaction::InvalidChainId } |
| 59 | + basic_bootloader::bootloader::errors::InvalidTransaction::AccessListNotSupported => { InvalidTransaction::AccessListNotSupported } |
| 60 | + basic_bootloader::bootloader::errors::InvalidTransaction::GasPerPubdataTooHigh => { InvalidTransaction::GasPerPubdataTooHigh } |
| 61 | + basic_bootloader::bootloader::errors::InvalidTransaction::BlockGasLimitTooHigh => { InvalidTransaction::BlockGasLimitTooHigh } |
| 62 | + basic_bootloader::bootloader::errors::InvalidTransaction::UpgradeTxNotFirst => { InvalidTransaction::UpgradeTxNotFirst } |
| 63 | + basic_bootloader::bootloader::errors::InvalidTransaction::Revert { method, output } => { InvalidTransaction::Revert { method: match method { |
| 64 | + basic_bootloader::bootloader::errors::AAMethod::AccountValidate => { AAMethod::AccountValidate} |
| 65 | + basic_bootloader::bootloader::errors::AAMethod::AccountPayForTransaction => { AAMethod::AccountPayForTransaction} |
| 66 | + basic_bootloader::bootloader::errors::AAMethod::AccountPrePaymaster => {AAMethod::AccountPrePaymaster} |
| 67 | + basic_bootloader::bootloader::errors::AAMethod::PaymasterValidateAndPay => {AAMethod::PaymasterValidateAndPay} |
| 68 | + }, output } } |
| 69 | + basic_bootloader::bootloader::errors::InvalidTransaction::ReceivedInsufficientFees { received, required } => { InvalidTransaction::ReceivedInsufficientFees { received, required } } |
| 70 | + basic_bootloader::bootloader::errors::InvalidTransaction::InvalidMagic => { InvalidTransaction::InvalidMagic } |
| 71 | + basic_bootloader::bootloader::errors::InvalidTransaction::InvalidReturndataLength => { InvalidTransaction::InvalidReturndataLength } |
| 72 | + basic_bootloader::bootloader::errors::InvalidTransaction::OutOfGasDuringValidation => { InvalidTransaction::OutOfGasDuringValidation } |
| 73 | + basic_bootloader::bootloader::errors::InvalidTransaction::OutOfNativeResourcesDuringValidation => { InvalidTransaction::OutOfNativeResourcesDuringValidation } |
| 74 | + basic_bootloader::bootloader::errors::InvalidTransaction::NonceUsedAlready => { InvalidTransaction::NonceUsedAlready } |
| 75 | + basic_bootloader::bootloader::errors::InvalidTransaction::NonceNotIncreased => { InvalidTransaction::NonceNotIncreased } |
| 76 | + basic_bootloader::bootloader::errors::InvalidTransaction::PaymasterReturnDataTooShort => { InvalidTransaction::PaymasterReturnDataTooShort } |
| 77 | + basic_bootloader::bootloader::errors::InvalidTransaction::PaymasterInvalidMagic => { InvalidTransaction::PaymasterInvalidMagic } |
| 78 | + basic_bootloader::bootloader::errors::InvalidTransaction::PaymasterContextInvalid => { InvalidTransaction::PaymasterContextInvalid } |
| 79 | + basic_bootloader::bootloader::errors::InvalidTransaction::PaymasterContextOffsetTooLong => { InvalidTransaction::PaymasterContextOffsetTooLong } |
| 80 | + basic_bootloader::bootloader::errors::InvalidTransaction::BlockGasLimitReached => { InvalidTransaction::BlockGasLimitReached } |
| 81 | + basic_bootloader::bootloader::errors::InvalidTransaction::BlockNativeLimitReached => { InvalidTransaction::BlockNativeLimitReached } |
| 82 | + basic_bootloader::bootloader::errors::InvalidTransaction::BlockPubdataLimitReached => { InvalidTransaction::BlockPubdataLimitReached } |
| 83 | + basic_bootloader::bootloader::errors::InvalidTransaction::BlockL2ToL1LogsLimitReached => { InvalidTransaction::BlockL2ToL1LogsLimitReached } |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +impl IntoInterface<Log> for &GenericEventContent<4, EthereumIOTypesConfig> { |
| 89 | + fn into_interface(self) -> Log { |
| 90 | + Log::new( |
| 91 | + self.address.to_be_bytes().into(), |
| 92 | + self.topics.iter().map(|t| t.as_u8_array().into()).collect(), |
| 93 | + self.data.as_slice().to_vec().into(), |
| 94 | + ) |
| 95 | + .unwrap() |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +impl IntoInterface<L2ToL1Log> for zk_ee::common_structs::L2ToL1Log { |
| 100 | + fn into_interface(self) -> L2ToL1Log { |
| 101 | + L2ToL1Log { |
| 102 | + l2_shard_id: self.l2_shard_id, |
| 103 | + is_service: self.is_service, |
| 104 | + tx_number_in_block: self.tx_number_in_block, |
| 105 | + sender: self.sender.to_be_bytes().into(), |
| 106 | + key: self.key.as_u8_array().into(), |
| 107 | + value: self.value.as_u8_array().into(), |
| 108 | + } |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +impl IntoInterface<Sealed<Header>> for BlockHeader { |
| 113 | + fn into_interface(self) -> Sealed<Header> { |
| 114 | + let hash = self.hash(); |
| 115 | + let header = Header { |
| 116 | + parent_hash: self.parent_hash.as_u8_array().into(), |
| 117 | + ommers_hash: self.ommers_hash.as_u8_array().into(), |
| 118 | + beneficiary: self.beneficiary.to_be_bytes().into(), |
| 119 | + state_root: self.state_root.as_u8_array().into(), |
| 120 | + transactions_root: self.transactions_root.as_u8_array().into(), |
| 121 | + receipts_root: self.receipts_root.as_u8_array().into(), |
| 122 | + logs_bloom: self.logs_bloom.into(), |
| 123 | + difficulty: self.difficulty, |
| 124 | + number: self.number, |
| 125 | + gas_limit: self.gas_limit, |
| 126 | + gas_used: self.gas_used, |
| 127 | + timestamp: self.timestamp, |
| 128 | + extra_data: self.extra_data.to_vec().into(), |
| 129 | + mix_hash: self.mix_hash.as_u8_array().into(), |
| 130 | + nonce: self.nonce.into(), |
| 131 | + base_fee_per_gas: Some(self.base_fee_per_gas), |
| 132 | + withdrawals_root: None, |
| 133 | + blob_gas_used: None, |
| 134 | + excess_blob_gas: None, |
| 135 | + parent_beacon_block_root: None, |
| 136 | + requests_hash: None, |
| 137 | + }; |
| 138 | + Sealed::new_unchecked(header, hash.into()) |
| 139 | + } |
| 140 | +} |
0 commit comments