Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(op): use RollupCostData instead of full encoding #1491

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Rjected
Copy link
Collaborator

@Rjected Rjected commented Jun 5, 2024

This is a WIP to ultimately replace the tx_envelope part of the OptimismFields with a new struct.

Currently it just introduces the struct, which basically mirrors the RollupCostData from op-geth, and uses it in a few places. The plan is to first integrate this internally, without breaking OptimismFields, and once it is properly tested, break OptimismFields to use this instead.

@Rjected Rjected added feature New feature or lib ability refactor Refactor of the code labels Jun 5, 2024
/// The number of zeroes in the transaction.
pub(crate) zeroes: u64,
/// The number of ones in the transaction.
pub(crate) ones: u64,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-zero

pub fn from_bytes(bytes: &[u8]) -> Self {
let mut data = RollupCostData::default();
let mut i = 0;
while i < bytes.len() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same functionality exists in gas costs, this should reuse that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym / where? the counting for op data gas costs at least we want to remove, and put here instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Initial gas that is deducted for transaction to be included.
/// Initial gas contains initial stipend gas, gas for access list and input data.
pub fn validate_initial_tx_gas(
spec_id: SpecId,
input: &[u8],
is_create: bool,
access_list: &[(Address, Vec<U256>)],
) -> u64 {
let mut initial_gas = 0;
let zero_data_len = input.iter().filter(|v| **v == 0).count() as u64;
let non_zero_data_len = input.len() as u64 - zero_data_len;
// initdate stipend
initial_gas += zero_data_len * TRANSACTION_ZERO_DATA;
// EIP-2028: Transaction data gas cost reduction
initial_gas += non_zero_data_len
* if spec_id.is_enabled_in(SpecId::ISTANBUL) {
16
} else {
68
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see, thx

let mut rollup_data_gas_cost = U256::from(cost_data.ones.get())
.saturating_mul(U256::from(NON_ZERO_BYTE_COST))
.saturating_add(
U256::from(cost_data.zeroes.get()).saturating_mul(U256::from(ZERO_BYTE_COST)),
Copy link
Collaborator

@DaniPopes DaniPopes Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure all the arithmetic in this function and *fjord can be scaled down to use u64

Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rjected this looks nice, did you check why tests are failing?

@Rjected
Copy link
Collaborator Author

Rjected commented Jun 24, 2024

@Rjected this looks nice, did you check why tests are failing?

nope, was busy with other things, can pick this back up this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or lib ability refactor Refactor of the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants