-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: cgt #17412
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
Closed
Closed
feat: cgt #17412
Changes from 55 commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
0b5940a
feat(cgt): custom gas token
hexshire 5d807c7
feat: add gasPayingTokenName and gasPayingTokenSymbol on json config …
0xniha 2c9c7b9
fix: contracts semver
0xniha 4ddd49f
fix: remove system config bool
ashitakah 1a9acec
test: add OptimismPortal2CGT tests
0xniha 170cede
chore(cgt): set cgt flag l1block & fixes
0xniha ef98d54
fix(linter): resolve goimports formatting issue
hexshire 1f223a4
feat: add separate l2 contracts for cgt (#530)
0xniha 53a7501
test(cgt): fix failing tests (#529)
hexshire 52d4840
fix(cgt): revert weth
hexshire c64cbe5
cgt: feature flag integration
tynes 01b018c
config: make backwards compatible
tynes 2b5fdf2
fix: build issue
tynes c1e9f38
fix: better backwards compatibility
tynes 736e33d
build: fix
tynes e759aae
lint: fix
tynes 38404d5
snapshots: update
tynes 2175502
op-deployer: apply test with CGT
tynes 5fc88e1
contracts-bedrock: fix versioning
tynes 4db9ecc
lint: fix
tynes 47b0d81
deployer: remove standard values
tynes 75798b4
contracts: semver lock
tynes 787e880
contracts-bedrock: fix semver + abis
tynes 47bd311
cgt: solidity test cleanup
tynes 70f90c4
solidity: fmt
tynes fe0f5ab
tests: remove dead imports
tynes 0461d07
tests: fixup
tynes 8d2240f
cgt: configurable liquidity amount
tynes fd8b11d
feat: configurable native asset liquidity balance
tynes 11e3e4c
cleanup: merge L1Block logic so that we inherit
tynes bccbdb8
snapshots: update
tynes 2652a3f
cgt: inherit logic for L2ToL1MessagePasser
tynes c865863
semver-lock: update
tynes 8209fb1
lint: fix
tynes 3aedcdc
lint: fixup
tynes 82305b5
interfaces: fix
tynes da28e87
fixes: smol
tynes 152afcc
deploy-config: sane default
tynes d159627
lint: fix
tynes 3a876e1
linting: fix
tynes fbbbba2
lint: fix
tynes 330bb60
semgrep: fix
tynes b423844
lint: fix
tynes ca929cb
tests: fix
tynes 8de8477
tests: fix fuzz
tynes dfe5282
fix: custom gas token rebase (#17484)
agusduha b54c6b5
Merge branch 'develop' into sc-feat/custom-gas-token-rebase
agusduha cbdda0f
fix: semver lock
agusduha 9bb50bd
fix: CGT review fixes (#17534)
agusduha 872d409
Merge branch 'develop' into sc-feat/custom-gas-token-rebase
agusduha ed4c79b
fix: semver
agusduha 01020a3
fix: opcm version
agusduha 244a734
Merge branch 'develop' into sc-feat/custom-gas-token-rebase
agusduha c8060eb
fix: tests
agusduha ee87ecd
feat(op-acceptance-tests): add acceptance tests for native CGT across…
scharissis 4ad8a30
fix: custom gas token rebase review comments (#17577)
agusduha 4f01447
fix: cgt review (#17612)
agusduha c83d058
test: custom gas token invariants (#17489)
simon-something 882ca7a
refactor: use skipIfDevFeatureDisabled for cgt predeploys test (#614)…
agusduha 2da84c8
Merge branch 'develop' into sc-feat/custom-gas-token-rebase
agusduha bf72a8c
fix: tests
agusduha f033db8
fix: auth minter helper & bound _mint in depositTransaction tests (#1…
0xniha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
op-acceptance-tests/tests/custom_gas_token/cgt_introspection_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package custom_gas_token | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| ) | ||
|
|
||
| // TestCGT_IntrospectionViaL1Block verifies that the L2 L1Block predeploy reports | ||
| // that CGT mode is enabled and exposes non-empty token metadata (name, symbol). | ||
| func TestCGT_IntrospectionViaL1Block(gt *testing.T) { | ||
| t := devtest.SerialT(gt) | ||
| sys := presets.NewMinimal(t) | ||
|
|
||
| name, symbol := ensureCGTOrSkip(t, sys) | ||
|
|
||
| // Metadata should be non-empty. | ||
| if name == "" { | ||
| t.Require().Fail("gasPayingTokenName() returned empty string") | ||
| } | ||
| if symbol == "" { | ||
| t.Require().Fail("gasPayingTokenSymbol() returned empty string") | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
op-acceptance-tests/tests/custom_gas_token/cgt_l1_portal_introspection_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package custom_gas_token | ||
|
|
||
| import ( | ||
| "context" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
|
|
||
| "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/accounts/abi" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/rpc" | ||
| ) | ||
|
|
||
| // TestCGT_L1PortalIntrospection checks that the L1 OptimismPortal exposes | ||
| // a valid SystemConfig address via its systemConfig() view. | ||
| func TestCGT_L1PortalIntrospection(gt *testing.T) { | ||
| t := devtest.SerialT(gt) | ||
| sys := presets.NewMinimal(t) | ||
|
|
||
| // Skip if this devnet is not CGT-enabled (uses your existing gate). | ||
| ensureCGTOrSkip(t, sys) | ||
|
|
||
| l1c := sys.L1EL.EthClient() | ||
| portal := sys.L2Chain.DepositContractAddr() | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Ctx(), 20*time.Second) | ||
| defer cancel() | ||
|
|
||
| // Portal exposes systemConfig() -> address | ||
| const portalABI = `[ | ||
| {"inputs":[],"name":"systemConfig","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"} | ||
| ]` | ||
| pa, err := abi.JSON(strings.NewReader(portalABI)) | ||
| if err != nil { | ||
| t.Require().Fail("parse portal ABI: %v", err) | ||
| } | ||
|
|
||
| data, _ := pa.Pack("systemConfig") | ||
| out, err := l1c.Call(ctx, ethereum.CallMsg{To: &portal, Data: data}, rpc.LatestBlockNumber) | ||
| if err != nil { | ||
| t.Require().Fail("portal.systemConfig() call failed: %v", err) | ||
| } | ||
| vals, err := pa.Unpack("systemConfig", out) | ||
| if err != nil { | ||
| t.Require().Fail("unpack portal.systemConfig() failed: %v", err) | ||
| } | ||
| sysCfg := vals[0].(common.Address) | ||
| if sysCfg == (common.Address{}) { | ||
| t.Require().Fail("portal.systemConfig() returned zero address") | ||
| } | ||
| } | ||
48 changes: 48 additions & 0 deletions
48
op-acceptance-tests/tests/custom_gas_token/cgt_native_payment_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package custom_gas_token | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| "github.com/ethereum-optimism/optimism/op-service/eth" | ||
| ) | ||
|
|
||
| // TestCGT_ValueTransferPaysGasInToken verifies that on CGT chains a simple L2 | ||
| // value transfer charges gas in the native ERC-20, and balances reflect | ||
| // recipient +amount and sender > amount decrease (amount + gas). | ||
| func TestCGT_ValueTransferPaysGasInToken(gt *testing.T) { | ||
| t := devtest.SerialT(gt) | ||
| sys := presets.NewMinimal(t) | ||
|
|
||
| ensureCGTOrSkip(t, sys) | ||
|
|
||
| sender := sys.FunderL2.NewFundedEOA(eth.OneTenthEther) | ||
| recipient := sys.Wallet.NewEOA(sys.L2EL) | ||
|
|
||
| amount := eth.OneHundredthEther | ||
| beforeS := sender.GetBalance() | ||
| beforeR := recipient.GetBalance() | ||
|
|
||
| // This sends L2 native (CGT) value. | ||
| sender.Transfer(recipient.Address(), amount) | ||
|
|
||
| // Wait until recipient reflects the transfer. | ||
| // We don't wait on sender balance; it includes gas and is non-deterministic. | ||
| recipient.WaitForBalance(beforeR.Add(amount)) | ||
|
|
||
| afterS := sender.GetBalance() | ||
| afterR := recipient.GetBalance() | ||
|
|
||
| // Recipient increased by amount | ||
| wantR := beforeR.Add(amount) | ||
| if afterR != wantR { | ||
| t.Require().Fail("recipient balance mismatch: got %s, want %s", afterR, wantR) | ||
| } | ||
|
|
||
| // Sender decreased by at least amount (amount + gas). Strict inequality: | ||
| if !(beforeS.Sub(afterS)).Gt(amount) { | ||
| t.Require().Fail("sender delta must exceed transferred amount (gas must be paid): before=%s after=%s amount=%s", | ||
| beforeS, afterS, amount) | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
op-acceptance-tests/tests/custom_gas_token/cgt_portal_reverts_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package custom_gas_token | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| ) | ||
|
|
||
| // TestCGT_PortalReceiveReverts asserts that sending ETH to the L1 OptimismPortal | ||
| // (receive() -> depositTransaction) reverts under CGT, preventing ETH from getting stuck. | ||
| func TestCGT_PortalReceiveReverts(gt *testing.T) { | ||
| t := devtest.SerialT(gt) | ||
| sys := presets.NewMinimal(t) | ||
| ensureCGTOrSkip(t, sys) | ||
|
|
||
| l1c := sys.L1EL.EthClient() | ||
| portal := sys.L2Chain.DepositContractAddr() | ||
|
|
||
| // Try to send 1 wei to the Portal (receive() -> depositTransaction); should revert in CGT mode. | ||
| ctx, cancel := context.WithTimeout(t.Ctx(), 20*time.Second) | ||
| defer cancel() | ||
| _, err := l1c.EstimateGas(ctx, ethereum.CallMsg{ | ||
| To: &portal, | ||
| Value: common.Big1, | ||
| }) | ||
| if err == nil { | ||
| t.Require().Fail("expected L1 Portal to revert on direct ETH send in CGT mode, but estimator returned no error") | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
op-acceptance-tests/tests/custom_gas_token/cgt_reverts_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package custom_gas_token | ||
|
|
||
| import ( | ||
| "context" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| "github.com/ethereum-optimism/optimism/op-service/eth" | ||
|
|
||
| "math/big" | ||
|
|
||
| "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/accounts/abi" | ||
| ) | ||
|
|
||
| // TestCGT_MessengerRejectsValue ensures that sending native value to the | ||
| // L2CrossDomainMessenger reverts under CGT (non-payable path). | ||
| func TestCGT_MessengerRejectsValue(gt *testing.T) { | ||
| t := devtest.SerialT(gt) | ||
| sys := presets.NewMinimal(t) | ||
| ensureCGTOrSkip(t, sys) | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Ctx(), 30*time.Second) | ||
| defer cancel() | ||
|
|
||
| from := sys.FunderL2.NewFundedEOA(eth.OneHundredthEther).Address() | ||
| _, err := sys.L2EL.Escape().L2EthClient().EstimateGas(ctx, ethereum.CallMsg{ | ||
| From: from, | ||
| To: &l2XDMAddr, | ||
| Value: big.NewInt(1), // 1 wei native | ||
| Data: nil, | ||
| }) | ||
| if err == nil { | ||
| t.Require().Fail("expected estimation error when sending value to L2CrossDomainMessenger in CGT mode") | ||
| } | ||
| } | ||
|
|
||
| // TestCGT_L2StandardBridge_LegacyWithdrawReverts verifies that the legacy | ||
| // ETH-specific withdraw path on L2StandardBridge reverts under CGT. | ||
| func TestCGT_L2StandardBridge_LegacyWithdrawReverts(gt *testing.T) { | ||
| t := devtest.SerialT(gt) | ||
| sys := presets.NewMinimal(t) | ||
| ensureCGTOrSkip(t, sys) | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Ctx(), 30*time.Second) | ||
| defer cancel() | ||
|
|
||
| bridgeABIJSON := `[ | ||
| {"inputs":[ | ||
| {"internalType":"address","name":"_l2Token","type":"address"}, | ||
| {"internalType":"uint256","name":"_amount","type":"uint256"}, | ||
| {"internalType":"uint32","name":"_minGasLimit","type":"uint32"}, | ||
| {"internalType":"bytes","name":"_extraData","type":"bytes"} | ||
| ], | ||
| "name":"withdraw","outputs":[],"stateMutability":"payable","type":"function"} | ||
| ]` | ||
| bridgeABI, err := abi.JSON(strings.NewReader(bridgeABIJSON)) | ||
| if err != nil { | ||
| t.Require().Fail("%v", err) | ||
| } | ||
| // Any address is fine; the ETH-specific legacy path should be disabled under CGT. | ||
| anyAddress := l2XDMAddr | ||
| data, err := bridgeABI.Pack("withdraw", anyAddress, big.NewInt(1), uint32(100_000), []byte{}) | ||
| if err != nil { | ||
| t.Require().Fail("%v", err) | ||
| } | ||
|
|
||
| from := sys.FunderL2.NewFundedEOA(eth.OneHundredthEther).Address() | ||
| _, err = sys.L2EL.Escape().L2EthClient().EstimateGas(ctx, ethereum.CallMsg{ | ||
| From: from, | ||
| To: &l2BridgeAddr, | ||
| Data: data, | ||
| }) | ||
| if err == nil { | ||
| t.Require().Fail("expected estimation error for L2StandardBridge.withdraw under CGT") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
w3 is useful here when creating callers
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.
Oh yeah, I forgot about this, thanks!
#17583