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: Add single minimal e2e test. #8115

Merged
merged 9 commits into from
Dec 4, 2023
4 changes: 2 additions & 2 deletions op-e2e/e2eutils/geth/fakepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (f *fakePoS) Start() error {
tim.Stop()
return nil
}
envelope, err := f.engineAPI.GetPayloadV2(*res.PayloadID)
envelope, err := f.engineAPI.GetPayloadV3(*res.PayloadID)
if err != nil {
f.log.Error("failed to finish building L1 block", "err", err)
continue
Expand Down Expand Up @@ -178,7 +178,7 @@ func (f *fakePoS) Start() error {
continue
}
}
if _, err := f.engineAPI.ForkchoiceUpdatedV2(engine.ForkchoiceStateV1{
if _, err := f.engineAPI.ForkchoiceUpdatedV3(engine.ForkchoiceStateV1{
HeadBlockHash: envelope.ExecutionPayload.BlockHash,
SafeBlockHash: safe.Hash(),
FinalizedBlockHash: finalized.Hash(),
Expand Down
55 changes: 55 additions & 0 deletions op-e2e/e2eutils/transactions/blobs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package transactions

import (
"crypto/ecdsa"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/holiman/uint256"
)

var (
emptyBlob kzg4844.Blob
emptyBlobCommit kzg4844.Commitment
emptyBlobProof kzg4844.Proof
)

func init() {
var err error
emptyBlob = kzg4844.Blob{}
emptyBlobCommit, err = kzg4844.BlobToCommitment(emptyBlob)
if err != nil {
panic("failed to create empty blob commitment: " + err.Error())
}
emptyBlobProof, err = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
if err != nil {
panic("failed to create empty blob proof: " + err.Error())
}
EvanJRichard marked this conversation as resolved.
Show resolved Hide resolved
}

// with thanks to fjl
// https://github.com/ethereum/go-ethereum/commit/2a6beb6a39d7cb3c5906dd4465d65da6efcc73cd
func CreateEmptyBlobTx(key *ecdsa.PrivateKey, withSidecar bool, chainID uint64) *types.BlobTx {
sidecar := &types.BlobTxSidecar{
Blobs: []kzg4844.Blob{emptyBlob},
Commitments: []kzg4844.Commitment{emptyBlobCommit},
Proofs: []kzg4844.Proof{emptyBlobProof},
}
blobTx := &types.BlobTx{
ChainID: uint256.NewInt(chainID),
Nonce: 0,
GasTipCap: uint256.NewInt(2200000000000),
GasFeeCap: uint256.NewInt(5000000000000),
Gas: 25000,
To: common.Address{0x03, 0x04, 0x05},
Value: uint256.NewInt(99),
Data: make([]byte, 50),
BlobFeeCap: uint256.NewInt(150000000000),
BlobHashes: sidecar.BlobHashes(),
EvanJRichard marked this conversation as resolved.
Show resolved Hide resolved
}
EvanJRichard marked this conversation as resolved.
Show resolved Hide resolved
if withSidecar {
blobTx.Sidecar = sidecar
EvanJRichard marked this conversation as resolved.
Show resolved Hide resolved
}
return blobTx
}
38 changes: 38 additions & 0 deletions op-e2e/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-e2e/config"
gethutils "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/transactions"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-node/metrics"
rollupNode "github.com/ethereum-optimism/optimism/op-node/node"
Expand Down Expand Up @@ -171,6 +173,42 @@ func TestSystemE2EDencunAtGenesis(t *testing.T) {
require.NotNil(t, head.ExcessBlobGas(), "L1 is building dencun blocks since genesis")
}

// TestSystemE2EDencunAtGenesis tests if L2 finalizes when blobs are present on L1
func TestSystemE2EDencunAtGenesisWithBlobs(t *testing.T) {
InitParallel(t)

cfg := DefaultSystemConfig(t)
//cancun is on from genesis:
genesisActivation := uint64(0)
cfg.DeployConfig.L1CancunTimeOffset = &genesisActivation // i.e. turn cancun on at genesis time + 0

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
defer sys.Close()

// send a blob-containing txn on l1
ethPrivKey := sys.Cfg.Secrets.Alice
txData := transactions.CreateEmptyBlobTx(ethPrivKey, true, sys.Cfg.L1ChainIDBig().Uint64())
tx := types.MustSignNewTx(ethPrivKey, types.LatestSignerForChainID(cfg.L1ChainIDBig()), txData)
// send blob-containing txn
sendCtx, sendCancel := context.WithTimeout(context.Background(), 15*time.Second)
defer sendCancel()

l1Client := sys.Clients["l1"]
err = l1Client.SendTransaction(sendCtx, tx)
require.NoError(t, err, "Sending L1 empty blob tx")
// Wait for transaction on L1
blockContainsBlob, err := geth.WaitForTransaction(tx.Hash(), l1Client, 30*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second)
require.Nil(t, err, "Waiting for blob tx on L1")
// end sending blob-containing txns on l1
l2Client := sys.Clients["sequencer"]
finalizedBlock, err := gethutils.WaitForL1OriginOnL2(blockContainsBlob.BlockNumber.Uint64(), l2Client, 30*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second)
require.Nil(t, err, "Waiting for L1 origin of blob tx on L2")
finalizationTimeout := 30 * time.Duration(cfg.DeployConfig.L1BlockTime) * time.Second
_, err = gethutils.WaitForBlockToBeSafe(finalizedBlock.Header().Number, l2Client, finalizationTimeout)
require.Nil(t, err, "Waiting for safety of L2 block")
}

// TestSystemE2E sets up a L1 Geth node, a rollup node, and a L2 geth node and then confirms that L1 deposits are reflected on L2.
// All nodes are run in process (but are the full nodes, not mocked or stubbed).
func TestSystemE2E(t *testing.T) {
Expand Down