Skip to content
This repository was archived by the owner on Aug 20, 2022. It is now read-only.

core: handle base fee, l1 availability fee, tx fee#26

Closed
tuxcanfly wants to merge 1 commit intooptimism-prototypefrom
tux/l2-fees
Closed

core: handle base fee, l1 availability fee, tx fee#26
tuxcanfly wants to merge 1 commit intooptimism-prototypefrom
tux/l2-fees

Conversation

@tuxcanfly
Copy link
Copy Markdown
Contributor

@tuxcanfly tuxcanfly commented Jun 3, 2022

Description:

This PR implements handling of transaction fees for paying the cost of posting the RLP encoded transaction as part of calldata on L1 and the regular transaction fees on L2. The L1 cost is computed using variables from the GasPriceOracle and L1Block contracts on L2. Both the fees from L1 and L2 are transferred to a configurable fee recipient account.

Note: The PR aims to keep the client compatible for L1 and minimizes the diff required so as to be easily reviewable / auditable.

@tuxcanfly tuxcanfly marked this pull request as ready for review June 8, 2022 17:15
@trianglesphere
Copy link
Copy Markdown
Contributor

Ok, I took a look at the math. My suggestion is as follows:

l1GasUsed := ...
ctx.divisor = new(big.Int).Exp(big10, decimals, nil)
l1Cost := new(big.Int).Mul(l1GasUsed, ctx.BaseFee)
l1Cost = l1Cost.Mul(l1Cost, ctx.Scalar)
l1Cost = l1Cost.Div(l1Cost, ctx.Divisor)

Basically the scalar & decimals in the contract must be set relative to each other & we should only use integer math, not floating point math.

To get a scalar that is like 1.3, the scalar should be 1.3 * 10^decimals & the decimals should be appropriately set.

@tuxcanfly
Copy link
Copy Markdown
Contributor Author

Ok, I took a look at the math. My suggestion is as follows:

l1GasUsed := ...
ctx.divisor = new(big.Int).Exp(big10, decimals, nil)
l1Cost := new(big.Int).Mul(l1GasUsed, ctx.BaseFee)
l1Cost = l1Cost.Mul(l1Cost, ctx.Scalar)
l1Cost = l1Cost.Div(l1Cost, ctx.Divisor)

Basically the scalar & decimals in the contract must be set relative to each other & we should only use integer math, not floating point math.

To get a scalar that is like 1.3, the scalar should be 1.3 * 10^decimals & the decimals should be appropriately set.

Thanks this works, updated.

@trianglesphere
Copy link
Copy Markdown
Contributor

This is looking pretty good. I only have these couple comments + a proper PR description is what this needs from my side to get it merged.

@trianglesphere
Copy link
Copy Markdown
Contributor

Ok, rerunning tests. It looks like the new auth tests are flaky. Once tests go green, I'll approve.

Copy link
Copy Markdown
Contributor

@trianglesphere trianglesphere left a comment

Choose a reason for hiding this comment

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

LGTM. Please squash this for the merge. Feel free to wait to merge this until testing is all integrated.

tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 13, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 13, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 13, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 15, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
@tuxcanfly tuxcanfly changed the title core (tx): init l1 fee context core: handle base fee, l1 availability fee, tx fee Jun 15, 2022
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 15, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 15, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
Copy link
Copy Markdown
Contributor

@trianglesphere trianglesphere left a comment

Choose a reason for hiding this comment

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

just the switch to MarshallBinary

tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 16, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
@tuxcanfly tuxcanfly requested a review from trianglesphere June 16, 2022 11:13
base fee and l1 availability fee are redirected to configurable
accounts; where as tx fee is redirected as coinbase reward
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 16, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
@tuxcanfly tuxcanfly closed this Jun 16, 2022
@tuxcanfly tuxcanfly deleted the tux/l2-fees branch June 16, 2022 11:44
@tuxcanfly tuxcanfly restored the tux/l2-fees branch June 16, 2022 11:46
@tuxcanfly tuxcanfly deleted the tux/l2-fees branch June 16, 2022 11:47
@tuxcanfly
Copy link
Copy Markdown
Contributor Author

Followed up in #27 , same commit as the squashed one here (accidentally closed this PR).

tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 16, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 16, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 16, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 16, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 16, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
tuxcanfly added a commit to tuxcanfly/optimism that referenced this pull request Jun 16, 2022
This PR depends on ethereum-optimism#26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After ethereum-optimism#26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
mergify bot pushed a commit to ethereum-optimism/optimism that referenced this pull request Jun 16, 2022
This PR depends on #26 on reference-optimistic-geth:

ethereum-optimism/reference-optimistic-geth#26

A new test TestFees is added, which runs a simple transaction and tests
that the L2 fee is redirected to the configured fee recipient and that
the L1 availability fee is calculated based the RLP encoded transaction
size and also redirected to the configured fee recipient.

TestFees is skipped, but can be enabled the above PR is merged into
reference-optimistic-geth.

NOTE: After #26 reference-optimistic-geth is merged, L2 genesis
configuration needs to be updated for OptimismConfig to enable special
fee handling and to find L1Block, GasPriceOracle contract addresses.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants