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

EIP4844 smart contract updated #8712

Closed

Conversation

anikaraghu
Copy link
Contributor

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

  • Fixes #[Link to Issue]

/// @custom:semver 1.2.0
string public constant version = "1.2.0";

/// @notice Flag that indicates whether the network is in ecotone mode.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// @notice Flag that indicates whether the network is in ecotone mode.
/// @notice indicates whether the network has gone through the Ecotone upgrade

Copy link

codecov bot commented Dec 20, 2023

Codecov Report

Attention: 66 lines in your changes are missing coverage. Please review.

Comparison is base (79e62bf) 34.57% compared to head (fc71f2b) 34.25%.
Report is 15 commits behind head on develop.

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     
Flag Coverage Δ
cannon-go-tests 63.48% <ø> (ø)
chain-mon-tests 27.14% <ø> (ø)
common-ts-tests 26.74% <ø> (ø)
contracts-bedrock-tests 19.55% <0.00%> (-0.69%) ⬇️
contracts-ts-tests 12.25% <ø> (ø)
core-utils-tests 44.03% <ø> (ø)
sdk-next-tests 42.18% <ø> (ø)
sdk-tests 42.18% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...ckages/contracts-bedrock/src/L2/GasPriceOracle.sol 0.00% <0.00%> (ø)
packages/contracts-bedrock/src/L2/L1Block.sol 17.39% <0.00%> (-71.50%) ⬇️

... and 3 files with indirect coverage changes

/// @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) {
Copy link
Collaborator

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() ?

Copy link
Collaborator

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
Copy link
Contributor

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
Copy link
Contributor

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";
Copy link
Contributor

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;
Copy link
Collaborator

@roberto-bayardo roberto-bayardo Dec 20, 2023

Choose a reason for hiding this comment

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

Suggested change
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();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor Author

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?

Comment on lines 143 to 148
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;
Copy link
Collaborator

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:

Suggested change
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to return

@@ -93,7 +159,10 @@ contract GasPriceOracle is ISemver {
total += 16;
}
}
uint256 unsigned = total + overhead();
uint256 unsigned = total;
if (!isEcotone) {
Copy link
Contributor Author

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)

@roberto-bayardo
Copy link
Collaborator

Taking over this PR by reopening here: #8726
(Anika is out for the holidays)

@tynes
Copy link
Contributor

tynes commented Dec 22, 2023

Closing in favor of the other PR

@tynes tynes closed this Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants