-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
EIP4844 smart contract updated #8712
EIP4844 smart contract updated #8712
Conversation
/// @custom:semver 1.2.0 | ||
string public constant version = "1.2.0"; | ||
|
||
/// @notice Flag that indicates whether the network is in ecotone mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// @notice Flag that indicates whether the network is in ecotone mode. | |
/// @notice indicates whether the network has gone through the Ecotone upgrade |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #8712 +/- ##
===========================================
- Coverage 34.57% 34.25% -0.33%
===========================================
Files 167 167
Lines 7170 7229 +59
Branches 1213 1219 +6
===========================================
- Hits 2479 2476 -3
- Misses 4539 4603 +64
+ Partials 152 150 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/// @notice Post-ecotone L1 gas estimation calculation. | ||
/// @param _data Unsigned fully RLP-encoded transaction to get the L1 gas for. | ||
/// @return Amount of L1 gas used to publish the transaction. | ||
function _getL1GasUsedEcotone(bytes memory _data) internal pure returns (uint256) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't computing a "gas" value, but the approximation of "compressed bytes", so I'd rename it something more accurate to make it better match the spec.
_getCompressedTxSize() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from Slack discussion: just delete this function after applying the suggested edit above to the "main" function.
bytes32 _batcherHash; | ||
|
||
assembly { | ||
let offset := 0x4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having an offset for first pass to get passing tests is fine but ideally we don't need to have the intermediate adds and we just hardcode in the values. We should also be able to sstore
directly in the yul but I am fine with that as a nice to have
|
||
assembly { | ||
let offset := 0x4 | ||
_basefeeScalar := shr(224, calldataload(offset)) // uint32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the basefeescalar and the blobbasefeescalar we technically do not need to even parse them into their own values on the stack, since they are next to each other in the calldata and in storage we can sstore(slot, shr(160, calldataload(4))
or something like that
@@ -3,32 +3,53 @@ pragma solidity 0.8.15; | |||
|
|||
// Testing utilities | |||
import { CommonTest } from "test/setup/CommonTest.sol"; | |||
import "forge-std/console.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dead code
total += 16; | ||
} | ||
} | ||
return (total + (68 * 16 * 16)) / 16; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (total + (68 * 16 * 16)) / 16; | |
return (total / 16) + 68 |
@@ -93,7 +162,23 @@ contract GasPriceOracle is ISemver { | |||
total += 16; | |||
} | |||
} | |||
uint256 unsigned = total + overhead(); | |||
uint256 unsigned = total + L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).l1FeeOverhead(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint256 unsigned = total + L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).l1FeeOverhead(); | |
uint256 unsigned = total + isEcotone ? 0 : L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).l1FeeOverhead(); |
...From Slack discussion where the proposal is to just make this return "calldataGas".
then you can drop the _getL1GasUsedEcotone() function entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth noting that with this approach the _getL1FeeBedrock / _getL1FeeEcotone methods are checking the isEcotone
flag twice. are we ok with that additional gas usage?
uint256 l1GasUsed = _getL1GasUsedEcotone(_data); | ||
uint256 scaledBasefee = basefeeScalar() * 16 * l1BaseFee(); | ||
uint256 scaledBlobBasefee = blobBasefeeScalar() * blobBasefee(); | ||
uint256 unscaled = l1GasUsed * (scaledBasefee + scaledBlobBasefee); | ||
uint256 divisor = 10 ** DECIMALS; | ||
uint256 scaled = unscaled / divisor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to move the division by 16 to the end to preserve precision.
If we change l1GasUsed as suggested above:
uint256 l1GasUsed = _getL1GasUsedEcotone(_data); | |
uint256 scaledBasefee = basefeeScalar() * 16 * l1BaseFee(); | |
uint256 scaledBlobBasefee = blobBasefeeScalar() * blobBasefee(); | |
uint256 unscaled = l1GasUsed * (scaledBasefee + scaledBlobBasefee); | |
uint256 divisor = 10 ** DECIMALS; | |
uint256 scaled = unscaled / divisor; | |
uint256 l1GasUsed = _getL1GasUsed(_data); | |
uint256 scaledBasefee = basefeeScalar() * 16 * l1BaseFee(); | |
uint256 scaledBlobBasefee = blobBasefeeScalar() * blobBasefee(); | |
uint256 unscaled = l1GasUsed * (scaledBasefee + scaledBlobBasefee); | |
uint256 divisor = 16 * 10 ** DECIMALS; | |
uint256 scaled = unscaled / divisor; |
uint256 scaled = unscaled / divisor; | ||
return scaled; | ||
if (isEcotone) { | ||
_getL1FeeEcotone(_data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to return
4b523e2
to
865ee19
Compare
@@ -93,7 +159,10 @@ contract GasPriceOracle is ISemver { | |||
total += 16; | |||
} | |||
} | |||
uint256 unsigned = total + overhead(); | |||
uint256 unsigned = total; | |||
if (!isEcotone) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that with this approach we check the isEcotone flag twice when we call this from _getL1FeeBedrock/Ecotone
. Thoughts on this tradeoff(alternative being have a separate internal function)
865ee19
to
fc71f2b
Compare
Taking over this PR by reopening here: #8726 |
Closing in favor of the other PR |
Description
Fully backwards compatible smart contract changes to support the updated EIP4844 pricing function and new parameters
Tests
foundry tests added
Additional context
Add any other context about the problem you're solving.
Metadata