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

OptimismPortal2 set initial _balance through StorageSetter pattern #254

Merged
merged 5 commits into from
Oct 14, 2024

Conversation

ezdac
Copy link

@ezdac ezdac commented Oct 8, 2024

Fixes #239

The custom gas-token feature adaptation for the fault-proof system using the OptimismPortal2 contract has been merged recently upstream.

We are using the custom-gas-token feature and additionally require a modification of the OptimismPortal's _balance value to be set to the entire allocation of Celo on the L2 - meaning that all L1 token is initially locked in the bridge and only usable on the L2.

Those changes are now adapted also to the OptimismPortal2, which was a requirement to make our custom-gas-token pre-locked balance feature work in conjunction with fault-proofs.

@@ -1,8 +1,8 @@
import { chainConfig } from 'viem/op-stack'
import { defineChain } from 'viem'
import { chainConfig } from "viem/op-stack";
Copy link

Choose a reason for hiding this comment

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

Why the switch from single to double quotes here? The other js files in this dir seem to all be using single quotes

Copy link
Author

Choose a reason for hiding this comment

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

You're right - this was mainly due to my editor doing automatic formats on save.
I now added a .prettierrc.toml config and formatted all files consistently.

Copy link

Choose a reason for hiding this comment

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

Looks like the tab width of 4 is not working out here, there are now about 7k lines of changed code, I think 2 is probably the right value, or whatever doesn't reformat any of the codebase.

Choose a reason for hiding this comment

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

Also, let's move out the re-formatting to a separate PR if needed.

uint256 initialBalance = 0;
customGasTokenAddress = cfg.customGasTokenAddress();
IERC20 token = IERC20(customGasTokenAddress);
initialBalance = token.balanceOf(optimismPortalProxy);
Copy link

Choose a reason for hiding this comment

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

Where is the balance of the optimismPortalProxy set?

Copy link
Author

@ezdac ezdac Oct 10, 2024

Choose a reason for hiding this comment

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

This is set within the Deploy.s.sol script:

Our Celo L1 Token contract takes the Portal address as an initializer argument:

_upgradeAndCallViaSafe({
_proxy: payable(customGasTokenProxyAddress),
_implementation: customGasTokenAddress,
_innerCallData: abi.encodeCall(CeloTokenL1.initialize, (portalProxyAddress))
});

And then mints the whole market cap to the provided addresses balance:

uint256 constant TOTAL_MARKET_CAP = 1000000000e18; // 1 billion CELO
contract CeloTokenL1 is ERC20Upgradeable {
function initialize(address portalProxyAddress) public initializer {
__ERC20_init(NAME, SYMBOL);
_mint(portalProxyAddress, TOTAL_MARKET_CAP);
}


const l2GasPayment =
receipt.gasUsed * receipt.effectiveGasPrice + receipt.l1Fee
const l2GasPayment = receipt.gasUsed * receipt.effectiveGasPrice;

Choose a reason for hiding this comment

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

I thought we want to keep the l1Fee, just have it 0 everywhere, maybe doesn't make sense to remove it here.

Copy link
Author

@ezdac ezdac Oct 10, 2024

Choose a reason for hiding this comment

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

True, but it seems this is not yet reflected in the code. This means that receipt values do not align with deducted values.
This should only happen when the blobbasefeeScalar and basefeeScalar are not set to 0.

I opened an issue for it, I don't know if we were aware of this behavior already.

A hot-fix to make the test pass would be to set the blobbasefeeScalar and basefeeScalar values to 0 in the devnet deploy-config - currently the default values are used.

Choose a reason for hiding this comment

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

@karlb reverted the change (and merged only today), so we shouldn't be shortcutting anymore.

Copy link

Choose a reason for hiding this comment

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

The change is in op-geth and we didn't update the dependency yet. I'll probably do it as part of the optimism repo rebase.

@ezdac ezdac force-pushed the ezdac/optimismPortal2BalanceUpdate branch 2 times, most recently from 981f87f to e68c0e3 Compare October 10, 2024 20:45
Copy link

socket-security bot commented Oct 10, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] environment, filesystem, unsafe 0 7.7 MB prettier-bot
npm/[email protected] network Transitive: environment +10 18.1 MB awkweb, jmoxey

🚮 Removed packages: npm/[email protected]

View full report↗︎

@ezdac
Copy link
Author

ezdac commented Oct 10, 2024

So I added the l1Fee to the gas calculation in the test again. And I set the blobbasefeeScalar and basefeeScalar parameters to zero in the deploy config. (see #254 (comment) for context)

However the basefeeScalar zero value does not end up in the L1InfoTransaction that op-geth receives, and the receipts still have a non-zero value set for the L1BasefeeScalar.

I checked the SystemConfig contract, here both values are set to zero. However, e.g. one L1InfoTransaction on L2 I checked showed the following data, and the slice of data where the basefeeScalar value should be encoded is set to 1000000:

https://go.dev/play/p/8PN2lhQ-QGE

This is the same value that I could observe in the transaction receipts.

For now I don't know what's wrong here, but this is likely something that happens in the payload building in the L2 node.
Probably the SystemConfig update events are not read properly while building the payload attributes or the data is not encoded properly for the Ecotone encoding scheme.

I suggest we postpone fixing the tests for now and review this PR mainly for the changes to the OptimismPortal and the deploy script.

@pahor167 , could you have a look at this part of the PR?

@ezdac ezdac requested a review from pahor167 October 10, 2024 22:24
Copy link

@karlb karlb Oct 14, 2024

Choose a reason for hiding this comment

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

Does your editor change the indentation or did npm change in this respect? If it's your editor, please avoid the additional diff (for this and the other json files).

Copy link

Choose a reason for hiding this comment

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

Ah, it is probably prettier. We should avoid having npm and prettier fight over the formatting.

Copy link
Author

Choose a reason for hiding this comment

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

I think npm doesn't have auto-formatting included. Before, the code probably has been formatted by an editor's global settings of prettier or the LanguageServer.
The problem with the diff was the tab-width setting in prettier - I changed it to 2, which seem to have been the setting the code has been formatted with previously. This got rid of most of the diff.

I added the npm run format script that calls prettier in write mode with the checked in prettier config file.
Like that we can have an opinionated formatter for the e2e tests from now on and avoid larger formatting diffs in the future. Maybe we can include this in a pre-commit config or CI run as well.

Copy link

Choose a reason for hiding this comment

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

Just for comparison the formatting instructions in our op-geth e2e tests: https://github.com/celo-org/op-geth/blob/celo8/e2e_test/js-tests/Makefile

We could adjust them to be the same (same formatter, same config and called int the same way), but we can do that later.

@ezdac ezdac force-pushed the ezdac/optimismPortal2BalanceUpdate branch from 8762b47 to 72e56e4 Compare October 14, 2024 14:02
ezdac and others added 5 commits October 14, 2024 10:20
Fixes #239

The custom gas-token feature adaptation for the fault-proof system using
the `OptimismPortal2` contract has been merged recently upstream.

We are using the custom-gas-token feature and additionally require a
modification of the OptimismPortal's `_balance` value to be set
to the entire allocation of Celo on the L2 - meaning that all L1 token is
initially locked in the bridge and only usable on the L2.

Those changes are now adapted also to the `OptimismPortal2`, which
was a requirement to make our custom-gas-token pre-locked balance
feature work in conjunction with fault-proofs.
Co-authored-by: Valentin Rodygin <[email protected]>
@ezdac ezdac force-pushed the ezdac/optimismPortal2BalanceUpdate branch from 72e56e4 to 7009efb Compare October 14, 2024 14:20
@ezdac ezdac requested a review from pahor167 October 14, 2024 16:11
@ezdac ezdac merged commit 3ea562b into celo9 Oct 14, 2024
52 of 53 checks passed
@ezdac ezdac deleted the ezdac/optimismPortal2BalanceUpdate branch October 14, 2024 20:05
Comment on lines -1440 to +1451
commands[2] = string.concat("[[ -f ", filePath, " ]] && echo \"present\"");
commands[2] = string.concat("[[ -f ", filePath, ' ]] && echo "present"');
Copy link

Choose a reason for hiding this comment

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

This looks like an unnecessary change. Did you do it intentionally or did an autoformatter do this?

karlb pushed a commit that referenced this pull request Oct 15, 2024
…254)

* OptimismPortal2 set initial `_balance` through StorageSetter pattern

Fixes #239

The custom gas-token feature adaptation for the fault-proof system using
the `OptimismPortal2` contract has been merged recently upstream.

We are using the custom-gas-token feature and additionally require a
modification of the OptimismPortal's `_balance` value to be set
to the entire allocation of Celo on the L2 - meaning that all L1 token is
initially locked in the bridge and only usable on the L2.

Those changes are now adapted also to the `OptimismPortal2`, which
was a requirement to make our custom-gas-token pre-locked balance
feature work in conjunction with fault-proofs.

* Adapt withdraw e2e-tests to work with fault-proofs

* Use prettier for formatting e2e tests

* Fix typo

Co-authored-by: Valentin Rodygin <[email protected]>

* Set L1-fee scalars to zero in devnet

---------

Co-authored-by: Valentin Rodygin <[email protected]>
alecps pushed a commit that referenced this pull request Oct 15, 2024
…254)

* OptimismPortal2 set initial `_balance` through StorageSetter pattern

Fixes #239

The custom gas-token feature adaptation for the fault-proof system using
the `OptimismPortal2` contract has been merged recently upstream.

We are using the custom-gas-token feature and additionally require a
modification of the OptimismPortal's `_balance` value to be set
to the entire allocation of Celo on the L2 - meaning that all L1 token is
initially locked in the bridge and only usable on the L2.

Those changes are now adapted also to the `OptimismPortal2`, which
was a requirement to make our custom-gas-token pre-locked balance
feature work in conjunction with fault-proofs.

* Adapt withdraw e2e-tests to work with fault-proofs

* Use prettier for formatting e2e tests

* Fix typo

Co-authored-by: Valentin Rodygin <[email protected]>

* Set L1-fee scalars to zero in devnet

---------

Co-authored-by: Valentin Rodygin <[email protected]>
alecps pushed a commit that referenced this pull request Oct 16, 2024
…254)

* OptimismPortal2 set initial `_balance` through StorageSetter pattern

Fixes #239

The custom gas-token feature adaptation for the fault-proof system using
the `OptimismPortal2` contract has been merged recently upstream.

We are using the custom-gas-token feature and additionally require a
modification of the OptimismPortal's `_balance` value to be set
to the entire allocation of Celo on the L2 - meaning that all L1 token is
initially locked in the bridge and only usable on the L2.

Those changes are now adapted also to the `OptimismPortal2`, which
was a requirement to make our custom-gas-token pre-locked balance
feature work in conjunction with fault-proofs.

* Adapt withdraw e2e-tests to work with fault-proofs

* Use prettier for formatting e2e tests

* Fix typo

Co-authored-by: Valentin Rodygin <[email protected]>

* Set L1-fee scalars to zero in devnet

---------

Co-authored-by: Valentin Rodygin <[email protected]>
karlb pushed a commit that referenced this pull request Oct 16, 2024
…254)

* OptimismPortal2 set initial `_balance` through StorageSetter pattern

Fixes #239

The custom gas-token feature adaptation for the fault-proof system using
the `OptimismPortal2` contract has been merged recently upstream.

We are using the custom-gas-token feature and additionally require a
modification of the OptimismPortal's `_balance` value to be set
to the entire allocation of Celo on the L2 - meaning that all L1 token is
initially locked in the bridge and only usable on the L2.

Those changes are now adapted also to the `OptimismPortal2`, which
was a requirement to make our custom-gas-token pre-locked balance
feature work in conjunction with fault-proofs.

* Adapt withdraw e2e-tests to work with fault-proofs

* Use prettier for formatting e2e tests

* Fix typo

Co-authored-by: Valentin Rodygin <[email protected]>

* Set L1-fee scalars to zero in devnet

---------

Co-authored-by: Valentin Rodygin <[email protected]>
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.

Port CustomGasToken changes to OptimismPortal2
5 participants