Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions op-enclave/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
FROM ghcr.io/mdehoog/aws-nitro-enclaves-sdk-bootstrap@sha256:6e5e53bd47370dbc1920208e93d222533a36f9f5dc85615591cbfe56a03312b0 AS bootstrap


# golang:1.22.6
FROM golang@sha256:367bb5295d3103981a86a572651d8297d6973f2ec8b62f716b007860e22cbc25 AS builder
# golang:1.24
FROM golang:1.24 AS builder

RUN go install github.com/linuxkit/linuxkit/src/cmd/linuxkit@270fd1c5aa1986977b31af6c743c6a2681f67a29

Expand All @@ -23,8 +23,8 @@ RUN linuxkit build --format kernel+initrd --no-sbom --name init-ramdisk ./eif/in
RUN linuxkit build --format kernel+initrd --no-sbom --name user-ramdisk ./eif/user-ramdisk.yaml


# rust:1.80.1
FROM rust@sha256:29fe4376919e25b7587a1063d7b521d9db735fc137d3cf30ae41eb326d209471 AS eif
# rust:1.83
FROM rust:1.83 AS eif

RUN mkdir /build
WORKDIR /build
Expand Down
20 changes: 20 additions & 0 deletions op-enclave/cmd/enclave/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"net/http"
"os"
"strconv"

enclave2 "github.com/base/op-enclave/op-enclave/enclave"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
Expand All @@ -10,10 +12,28 @@ import (
"github.com/mdlayher/vsock"
)

const (
// defaultHTTPBodyLimit is set to 50MB (increased from go-ethereum's default of 5MB)
// because witness data for some blocks can exceed 5MB, causing 413 errors.
defaultHTTPBodyLimit = 50 * 1024 * 1024
)

func main() {
oplog.SetupDefaults()

s := rpc.NewServer()
// Set HTTP body limit (configurable via OP_ENCLAVE_HTTP_BODY_LIMIT env var, in bytes)
httpBodyLimit := defaultHTTPBodyLimit
if envLimit := os.Getenv("OP_ENCLAVE_HTTP_BODY_LIMIT"); envLimit != "" {
if parsed, err := strconv.Atoi(envLimit); err == nil && parsed > 0 {
httpBodyLimit = parsed
log.Info("Using custom HTTP body limit", "bytes", httpBodyLimit)
} else {
log.Warn("Invalid OP_ENCLAVE_HTTP_BODY_LIMIT, using default", "value", envLimit, "default", defaultHTTPBodyLimit)
}
}
s.SetHTTPBodyLimit(httpBodyLimit)

serv, err := enclave2.NewServer()
if err != nil {
log.Crit("Error creating API server", "error", err)
Expand Down
4 changes: 3 additions & 1 deletion op-enclave/enclave/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ func DefaultDeployConfig() genesis.DeployConfig {
L2GenesisEcotoneTimeOffset: u64UtilPtr(0),
L2GenesisFjordTimeOffset: u64UtilPtr(0),
L2GenesisGraniteTimeOffset: u64UtilPtr(0),
UseInterop: false,
L2GenesisHoloceneTimeOffset: u64UtilPtr(0),
L2GenesisIsthmusTimeOffset: u64UtilPtr(0),
L2GenesisJovianTimeOffset: u64UtilPtr(0),
},
L2CoreDeployConfig: genesis.L2CoreDeployConfig{
L2ChainID: 1,
Expand Down
14 changes: 7 additions & 7 deletions op-enclave/enclave/l1_receipts_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ type l1ReceiptsFetcher struct {
hash common.Hash
header *types.Header
receipts types.Receipts
cfg *params.ChainConfig
}

func NewL1ReceiptsFetcher(hash common.Hash, header *types.Header, receipts types.Receipts, cfg *params.ChainConfig) derive.L1ReceiptsFetcher {
func NewL1ReceiptsFetcher(hash common.Hash, header *types.Header, receipts types.Receipts) derive.L1ReceiptsFetcher {
return &l1ReceiptsFetcher{
hash: hash,
header: header,
receipts: receipts,
cfg: cfg,
}
}

Expand All @@ -37,7 +35,6 @@ func (l *l1ReceiptsFetcher) InfoByHash(ctx context.Context, hash common.Hash) (e
return headerInfo{
hash: l.hash,
Header: l.header,
cfg: l.cfg,
}, nil
}

Expand All @@ -52,7 +49,6 @@ func (l *l1ReceiptsFetcher) FetchReceipts(ctx context.Context, blockHash common.
type headerInfo struct {
hash common.Hash
*types.Header
cfg *params.ChainConfig
}

var _ eth.BlockInfo = (*headerInfo)(nil)
Expand Down Expand Up @@ -89,14 +85,18 @@ func (h headerInfo) BaseFee() *big.Int {
return h.Header.BaseFee
}

func (h headerInfo) BlobBaseFee() *big.Int {
return eip4844.CalcBlobFee(h.cfg, h.Header)
func (h headerInfo) BlobBaseFee(cfg *params.ChainConfig) *big.Int {
return eip4844.CalcBlobFee(cfg, h.Header)
}

func (h headerInfo) ExcessBlobGas() *uint64 {
return h.Header.ExcessBlobGas
}

func (h headerInfo) BlobGasUsed() *uint64 {
return h.Header.BlobGasUsed
}

func (h headerInfo) WithdrawalsRoot() *common.Hash {
return h.Header.WithdrawalsHash
}
Expand Down
29 changes: 27 additions & 2 deletions op-enclave/enclave/l2_system_config_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,40 @@ func blockToSystemConfig(rollupCfg *rollup.Config, header *types.Header, txs []*
binary.BigEndian.PutUint32(info.L1FeeScalar[24:28], info.BlobBaseFeeScalar)
binary.BigEndian.PutUint32(info.L1FeeScalar[28:32], info.BaseFeeScalar)
}
return eth.SystemConfig{
sysCfg := eth.SystemConfig{
BatcherAddr: info.BatcherAddr,
Overhead: info.L1FeeOverhead,
Scalar: info.L1FeeScalar,
GasLimit: header.GasLimit,
}, err
}
// Add Isthmus operator fee params
if isIsthmusButNotFirstBlock(rollupCfg, header.Time) {
sysCfg.OperatorFeeParams = encodeOperatorFeeParams(info.OperatorFeeScalar, info.OperatorFeeConstant)
}
// Add Jovian DA footprint gas scalar
if isJovianButNotFirstBlock(rollupCfg, header.Time) {
sysCfg.DAFootprintGasScalar = info.DAFootprintGasScalar
}
return sysCfg, err
}
}

func isEcotoneButNotFirstBlock(rollupCfg *rollup.Config, l2BlockTime uint64) bool {
return rollupCfg.IsEcotone(l2BlockTime) && !rollupCfg.IsEcotoneActivationBlock(l2BlockTime)
}

func isIsthmusButNotFirstBlock(rollupCfg *rollup.Config, l2BlockTime uint64) bool {
return rollupCfg.IsIsthmus(l2BlockTime) && !rollupCfg.IsIsthmusActivationBlock(l2BlockTime)
}

func isJovianButNotFirstBlock(rollupCfg *rollup.Config, l2BlockTime uint64) bool {
return rollupCfg.IsJovian(l2BlockTime) && !rollupCfg.IsJovianActivationBlock(l2BlockTime)
}

// encodeOperatorFeeParams encodes the operator fee scalar and constant into a Bytes32
func encodeOperatorFeeParams(scalar uint32, constant uint64) eth.Bytes32 {
var encoded eth.Bytes32
binary.BigEndian.PutUint32(encoded[20:24], scalar)
binary.BigEndian.PutUint64(encoded[24:32], constant)
return encoded
}
30 changes: 18 additions & 12 deletions op-enclave/enclave/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,12 @@ func (s *Server) SetSignerKey(ctx context.Context, encrypted hexutil.Bytes) erro
}

type Proposal struct {
OutputRoot common.Hash
Signature hexutil.Bytes
L1OriginHash common.Hash
L2BlockNumber *hexutil.Big
OutputRoot common.Hash
Signature hexutil.Bytes
L1OriginHash common.Hash
L2BlockNumber *hexutil.Big
PrevOutputRoot common.Hash
ConfigHash common.Hash
}

func (s *Server) ExecuteStateless(
Expand Down Expand Up @@ -290,10 +292,12 @@ func (s *Server) ExecuteStateless(
return nil, err
}
return &Proposal{
OutputRoot: outputRoot,
Signature: sig,
L1OriginHash: l1OriginHash,
L2BlockNumber: (*hexutil.Big)(blockHeader.Number),
OutputRoot: outputRoot,
Signature: sig,
L1OriginHash: l1OriginHash,
L2BlockNumber: (*hexutil.Big)(blockHeader.Number),
PrevOutputRoot: prevOutputRoot,
ConfigHash: configHash,
}, nil
}

Expand Down Expand Up @@ -331,10 +335,12 @@ func (s *Server) Aggregate(ctx context.Context, configHash common.Hash, prevOutp
}

return &Proposal{
OutputRoot: outputRoot,
Signature: sig,
L1OriginHash: l1OriginHash,
L2BlockNumber: (*hexutil.Big)(new(big.Int).SetBytes(l2BlockNumber[:])),
OutputRoot: outputRoot,
Signature: sig,
L1OriginHash: l1OriginHash,
L2BlockNumber: (*hexutil.Big)(new(big.Int).SetBytes(l2BlockNumber[:])),
PrevOutputRoot: prevOutputRoot,
ConfigHash: configHash,
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions op-enclave/enclave/stateless.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ func ExecuteStateless(
return errors.New("invalid L1 origin")
}

l1Fetcher := NewL1ReceiptsFetcher(l1OriginHash, l1Origin, l1Receipts, config)
l1Fetcher := NewL1ReceiptsFetcher(l1OriginHash, l1Origin, l1Receipts)
l2Fetcher := NewL2SystemConfigFetcher(rollupConfig, previousBlockHash, previousBlockHeader, previousTxs)
attributeBuilder := derive.NewFetchingAttributesBuilder(rollupConfig, l1Fetcher, l2Fetcher)
// Pass nil for DependencySet as we don't use interop
attributeBuilder := derive.NewFetchingAttributesBuilder(rollupConfig, params.SepoliaChainConfig, nil, l1Fetcher, l2Fetcher)
payload, err := attributeBuilder.PreparePayloadAttributes(ctx, l2Parent, eth.BlockID{
Hash: l1OriginHash,
Number: l1Origin.Number.Uint64(),
Expand Down
Loading
Loading