Skip to content

Commit

Permalink
Merge branch 'develop' into sc/liquidity-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
agusduha committed Aug 14, 2024
2 parents 809a71b + 42b8711 commit f4d0bb3
Show file tree
Hide file tree
Showing 64 changed files with 2,237 additions and 10,910 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- run:
name: Load devnet-allocs
name: Load devnet-allocs and artifacts
command: |
mkdir -p .devnet
cp /tmp/workspace/.devnet<<parameters.variant>>/allocs-l2-delta.json .devnet/allocs-l2-delta.json
Expand All @@ -866,6 +866,7 @@ jobs:
cp /tmp/workspace/.devnet<<parameters.variant>>/allocs-l2-granite.json .devnet/allocs-l2-granite.json
cp /tmp/workspace/.devnet<<parameters.variant>>/allocs-l1.json .devnet/allocs-l1.json
cp /tmp/workspace/.devnet<<parameters.variant>>/addresses.json .devnet/addresses.json
cp -r /tmp/workspace/packages/contracts-bedrock/forge-artifacts packages/contracts-bedrock/forge-artifacts
cp /tmp/workspace/packages/contracts-bedrock/deploy-config/devnetL1.json packages/contracts-bedrock/deploy-config/devnetL1.json
cp -r /tmp/workspace/packages/contracts-bedrock/deployments/devnetL1 packages/contracts-bedrock/deployments/devnetL1
- run:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Tags of the form `v<semver>`, such as `v1.1.4`, indicate releases of all Go code
This naming scheme is required by Golang.
In the above list, this means these `v<semver` releases contain all `op-*` components and exclude all `contracts-*` components.

`op-geth` embeds upstream geth’s version inside it’s own version as follows: `vMAJOR.GETH_MAJOR GETH_MINOR GETH_PATCH.PATCH`.
`op-geth` embeds upstream geth’s version inside its own version as follows: `vMAJOR.GETH_MAJOR GETH_MINOR GETH_PATCH.PATCH`.
Basically, geth’s version is our minor version.
For example if geth is at `v1.12.0`, the corresponding op-geth version would be `v1.101200.0`.
Note that we pad out to three characters for the geth minor version and two characters for the geth patch version.
Expand Down
3 changes: 2 additions & 1 deletion bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,10 @@ def devnet_deploy(paths):

if DEVNET_PLASMA:
docker_env['PLASMA_ENABLED'] = 'true'
docker_env['DA_TYPE'] = 'calldata'
else:
docker_env['PLASMA_ENABLED'] = 'false'
docker_env['DA_TYPE'] = 'blobs'

if GENERIC_PLASMA:
docker_env['PLASMA_GENERIC_DA'] = 'true'
Expand All @@ -279,7 +281,6 @@ def devnet_deploy(paths):
docker_env['PLASMA_GENERIC_DA'] = 'false'
docker_env['PLASMA_DA_SERVICE'] = 'false'


# Bring up the rest of the services.
log.info('Bringing up `op-node`, `op-proposer` and `op-batcher`.')
run_command(['docker', 'compose', 'up', '-d', 'op-node', 'op-proposer', 'op-batcher', 'artifact-server'], cwd=paths.ops_bedrock_dir, env=docker_env)
Expand Down
4 changes: 2 additions & 2 deletions cannon/mipsevm/testutil/evm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testutil

import (
"bytes"
"encoding/binary"
"fmt"
"math/big"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
Expand Down Expand Up @@ -78,7 +78,7 @@ func NewEVMEnv(artifacts *Artifacts, addrs *Addresses) (*vm.EVM, *state.StateDB)

var mipsCtorArgs [32]byte
copy(mipsCtorArgs[12:], addrs.Oracle[:])
mipsDeploy := append(hexutil.MustDecode(artifacts.MIPS.Bytecode.Object.String()), mipsCtorArgs[:]...)
mipsDeploy := append(bytes.Clone(artifacts.MIPS.Bytecode.Object), mipsCtorArgs[:]...)
startingGas := uint64(30_000_000)
_, deployedMipsAddr, leftOverGas, err := env.Create(vm.AccountRef(addrs.Sender), mipsDeploy, startingGas, common.U2560)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/crate-crypto/go-kzg-4844 v1.0.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240812010938-34a43d577f74
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240813170044-d5be5587e58f
github.com/ethereum/go-ethereum v1.14.7
github.com/fsnotify/fsnotify v1.7.0
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 h1:RWHKLhCrQThMfch+QJ1Z
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3/go.mod h1:QziizLAiF0KqyLdNJYD7O5cpDlaFMNZzlxYNcWsJUxs=
github.com/ethereum-optimism/op-geth v1.101407.0-rc.1.0.20240812224053-8d99ca68bb1a h1:OK3wB7HbdhCneSowC1XZusHaLIVdXoRLuCWgXp5Tjuc=
github.com/ethereum-optimism/op-geth v1.101407.0-rc.1.0.20240812224053-8d99ca68bb1a/go.mod h1:9pT+bF20XwCBE7WkjfRSsCg6RN6Njdbr924DtQ3+geY=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240812010938-34a43d577f74 h1:HQZQalpPUXs9qnJgDmEDzpPO70Z1p8Le2l0bZ9eJjCk=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240812010938-34a43d577f74/go.mod h1:zy9f3TNPS7pwW4msMitF83fp0Wf452tZ6+Fg6d4JyXM=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240813170044-d5be5587e58f h1:JTnVOiaYVQcXc+zgsSjnTQ18k3uOLOpch8SiPjO1eTo=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240813170044-d5be5587e58f/go.mod h1:zy9f3TNPS7pwW4msMitF83fp0Wf452tZ6+Fg6d4JyXM=
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4=
Expand Down
5 changes: 4 additions & 1 deletion op-batcher/batcher/channel_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func NewChannelBuilder(cfg ChannelConfig, rollupCfg rollup.Config, latestL1Origi
chainSpec := rollup.NewChainSpec(&rollupCfg)
var co derive.ChannelOut
if cfg.BatchType == derive.SpanBatchType {
co, err = derive.NewSpanChannelOut(rollupCfg.Genesis.L2Time, rollupCfg.L2ChainID, cfg.CompressorConfig.TargetOutputSize, cfg.CompressorConfig.CompressionAlgo, chainSpec)
co, err = derive.NewSpanChannelOut(
rollupCfg.Genesis.L2Time, rollupCfg.L2ChainID,
cfg.CompressorConfig.TargetOutputSize, cfg.CompressorConfig.CompressionAlgo,
chainSpec, derive.WithMaxBlocksPerSpanBatch(cfg.MaxBlocksPerSpanBatch))
} else {
co, err = derive.NewSingularChannelOut(c, chainSpec)
}
Expand Down
3 changes: 3 additions & 0 deletions op-batcher/batcher/channel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type ChannelConfig struct {
SubSafetyMargin uint64
// The maximum byte-size a frame can have.
MaxFrameSize uint64
// MaxBlocksPerSpanBatch is the maximum number of blocks to add to a span batch.
// A value of 0 disables a maximum.
MaxBlocksPerSpanBatch int

// Target number of frames to create per channel.
// For blob transactions, this controls the number of blobs to target adding
Expand Down
4 changes: 4 additions & 0 deletions op-batcher/batcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type CLIConfig struct {
// If using blobs, this setting is ignored and the max blob size is used.
MaxL1TxSize uint64

// Maximum number of blocks to add to a span batch. Default is 0 - no maximum.
MaxBlocksPerSpanBatch int

// The target number of frames to create per channel. Controls number of blobs
// per blob tx, if using Blob DA.
TargetNumFrames int
Expand Down Expand Up @@ -173,6 +176,7 @@ func NewConfig(ctx *cli.Context) *CLIConfig {
MaxPendingTransactions: ctx.Uint64(flags.MaxPendingTransactionsFlag.Name),
MaxChannelDuration: ctx.Uint64(flags.MaxChannelDurationFlag.Name),
MaxL1TxSize: ctx.Uint64(flags.MaxL1TxSizeBytesFlag.Name),
MaxBlocksPerSpanBatch: ctx.Int(flags.MaxBlocksPerSpanBatch.Name),
TargetNumFrames: ctx.Int(flags.TargetNumFramesFlag.Name),
ApproxComprRatio: ctx.Float64(flags.ApproxComprRatioFlag.Name),
Compressor: ctx.String(flags.CompressorFlag.Name),
Expand Down
15 changes: 8 additions & 7 deletions op-batcher/batcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,14 @@ func (bs *BatcherService) initChannelConfig(cfg *CLIConfig) error {
channelTimeout = bs.RollupConfig.ChannelTimeoutGranite
}
cc := ChannelConfig{
SeqWindowSize: bs.RollupConfig.SeqWindowSize,
ChannelTimeout: channelTimeout,
MaxChannelDuration: cfg.MaxChannelDuration,
MaxFrameSize: cfg.MaxL1TxSize - 1, // account for version byte prefix; reset for blobs
TargetNumFrames: cfg.TargetNumFrames,
SubSafetyMargin: cfg.SubSafetyMargin,
BatchType: cfg.BatchType,
SeqWindowSize: bs.RollupConfig.SeqWindowSize,
ChannelTimeout: channelTimeout,
MaxChannelDuration: cfg.MaxChannelDuration,
MaxFrameSize: cfg.MaxL1TxSize - 1, // account for version byte prefix; reset for blobs
MaxBlocksPerSpanBatch: cfg.MaxBlocksPerSpanBatch,
TargetNumFrames: cfg.TargetNumFrames,
SubSafetyMargin: cfg.SubSafetyMargin,
BatchType: cfg.BatchType,
}

switch cfg.DataAvailabilityType {
Expand Down
6 changes: 6 additions & 0 deletions op-batcher/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ var (
Value: 120_000, // will be overwritten to max for blob da-type
EnvVars: prefixEnvVars("MAX_L1_TX_SIZE_BYTES"),
}
MaxBlocksPerSpanBatch = &cli.IntFlag{
Name: "max-blocks-per-span-batch",
Usage: "Maximum number of blocks to add to a span batch. Default is 0 - no maximum.",
EnvVars: prefixEnvVars("MAX_BLOCKS_PER_SPAN_BATCH"),
}
TargetNumFramesFlag = &cli.IntFlag{
Name: "target-num-frames",
Usage: "The target number of frames to create per channel. Controls number of blobs per blob tx, if using Blob DA.",
Expand Down Expand Up @@ -169,6 +174,7 @@ var optionalFlags = []cli.Flag{
MaxPendingTransactionsFlag,
MaxChannelDurationFlag,
MaxL1TxSizeBytesFlag,
MaxBlocksPerSpanBatch,
TargetNumFramesFlag,
ApproxComprRatioFlag,
CompressorFlag,
Expand Down
90 changes: 77 additions & 13 deletions op-chain-ops/foundry/artifact.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package foundry

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/holiman/uint256"
Expand All @@ -26,6 +27,7 @@ type Artifact struct {
StorageLayout solc.StorageLayout
DeployedBytecode DeployedBytecode
Bytecode Bytecode
Metadata Metadata
}

func (a *Artifact) UnmarshalJSON(data []byte) error {
Expand All @@ -42,6 +44,7 @@ func (a *Artifact) UnmarshalJSON(data []byte) error {
a.StorageLayout = artifact.StorageLayout
a.DeployedBytecode = artifact.DeployedBytecode
a.Bytecode = artifact.Bytecode
a.Metadata = artifact.Metadata
return nil
}

Expand All @@ -51,6 +54,7 @@ func (a Artifact) MarshalJSON() ([]byte, error) {
StorageLayout: a.StorageLayout,
DeployedBytecode: a.DeployedBytecode,
Bytecode: a.Bytecode,
Metadata: a.Metadata,
}
return json.Marshal(artifact)
}
Expand All @@ -62,22 +66,83 @@ type artifactMarshaling struct {
StorageLayout solc.StorageLayout `json:"storageLayout"`
DeployedBytecode DeployedBytecode `json:"deployedBytecode"`
Bytecode Bytecode `json:"bytecode"`
Metadata Metadata `json:"metadata"`
}

// Metadata is the subset of metadata in a foundry contract artifact that we use in OP-Stack tooling.
type Metadata struct {
Compiler struct {
Version string `json:"version"`
} `json:"compiler"`

Language string `json:"language"`

Output json.RawMessage `json:"output"`

Settings struct {
// Remappings of the contract imports
Remappings json.RawMessage `json:"remappings"`
// Optimizer settings affect the compiler output, but can be arbitrary.
// We load them opaquely, to include it in the hash of what we run.
Optimizer json.RawMessage `json:"optimizer"`
// Metadata is loaded opaquely, similar to the Optimizer, to include in hashing.
// E.g. the bytecode-hash contract suffix as setting is enabled/disabled in here.
Metadata json.RawMessage `json:"metadata"`
// Map of full contract path to compiled contract name.
CompilationTarget map[string]string `json:"compilationTarget"`
// EVM version affects output, and hence included.
EVMVersion string `json:"evmVersion"`
// Libraries data
Libraries json.RawMessage `json:"libraries"`
} `json:"settings"`

Sources map[string]ContractSource `json:"sources"`

Version int `json:"version"`
}

// ContractSource represents a JSON value in the "sources" map of a contract metadata dump.
// This uniquely identifies the source code of the contract.
type ContractSource struct {
Keccak256 common.Hash `json:"keccak256"`
URLs []string `json:"urls"`
License string `json:"license"`
}

var ErrLinkingUnsupported = errors.New("cannot load bytecode with linking placeholders")

// LinkableBytecode is not purely hex, it returns an ErrLinkingUnsupported error when
// input contains __$aaaaaaa$__ style linking placeholders.
// See https://docs.soliditylang.org/en/latest/using-the-compiler.html#library-linking
// In practice this is only used by test contracts to link in large test libraries.
type LinkableBytecode []byte

func (lb *LinkableBytecode) UnmarshalJSON(data []byte) error {
if bytes.Contains(data, []byte("__$")) {
return ErrLinkingUnsupported
}
return (*hexutil.Bytes)(lb).UnmarshalJSON(data)
}

func (lb LinkableBytecode) MarshalText() ([]byte, error) {
return (hexutil.Bytes)(lb).MarshalText()
}

// DeployedBytecode represents the deployed bytecode section of the solc compiler output.
type DeployedBytecode struct {
SourceMap string `json:"sourceMap"`
Object hexutil.Bytes `json:"object"`
LinkReferences json.RawMessage `json:"linkReferences"`
ImmutableReferences json.RawMessage `json:"immutableReferences,omitempty"`
SourceMap string `json:"sourceMap"`
Object LinkableBytecode `json:"object"`
LinkReferences json.RawMessage `json:"linkReferences"`
ImmutableReferences json.RawMessage `json:"immutableReferences,omitempty"`
}

// Bytecode represents the bytecode section of the solc compiler output.
type Bytecode struct {
SourceMap string `json:"sourceMap"`
Object hexutil.Bytes `json:"object"`
LinkReferences json.RawMessage `json:"linkReferences"`
ImmutableReferences json.RawMessage `json:"immutableReferences,omitempty"`
SourceMap string `json:"sourceMap"`
// not purely hex, can contain __$aaaaaaa$__ style linking placeholders
Object LinkableBytecode `json:"object"`
LinkReferences json.RawMessage `json:"linkReferences"`
ImmutableReferences json.RawMessage `json:"immutableReferences,omitempty"`
}

// ReadArtifact will read an artifact from disk given a path.
Expand Down Expand Up @@ -130,15 +195,14 @@ func (d *ForgeAllocs) UnmarshalJSON(b []byte) error {
}

func LoadForgeAllocs(allocsPath string) (*ForgeAllocs, error) {
path := filepath.Join(allocsPath)
f, err := os.OpenFile(path, os.O_RDONLY, 0644)
f, err := os.OpenFile(allocsPath, os.O_RDONLY, 0644)
if err != nil {
return nil, fmt.Errorf("failed to open forge allocs %q: %w", path, err)
return nil, fmt.Errorf("failed to open forge allocs %q: %w", allocsPath, err)
}
defer f.Close()
var out ForgeAllocs
if err := json.NewDecoder(f).Decode(&out); err != nil {
return nil, fmt.Errorf("failed to json-decode forge allocs %q: %w", path, err)
return nil, fmt.Errorf("failed to json-decode forge allocs %q: %w", allocsPath, err)
}
return &out, nil
}
5 changes: 3 additions & 2 deletions op-chain-ops/foundry/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

// TestArtifactJSON tests roundtrip serialization of a foundry artifact for commonly used fields.
func TestArtifactJSON(t *testing.T) {
artifact, err := ReadArtifact("testdata/OptimismPortal.json")
artifact, err := ReadArtifact("testdata/forge-artifacts/Owned.sol/Owned.json")
require.NoError(t, err)

data, err := json.Marshal(artifact)
require.NoError(t, err)

file, err := os.ReadFile("testdata/OptimismPortal.json")
file, err := os.ReadFile("testdata/forge-artifacts/Owned.sol/Owned.json")
require.NoError(t, err)

got := unmarshalIntoMap(t, data)
Expand All @@ -26,6 +26,7 @@ func TestArtifactJSON(t *testing.T) {
require.JSONEq(t, marshal(t, got["deployedBytecode"]), marshal(t, expected["deployedBytecode"]))
require.JSONEq(t, marshal(t, got["abi"]), marshal(t, expected["abi"]))
require.JSONEq(t, marshal(t, got["storageLayout"]), marshal(t, expected["storageLayout"]))
require.JSONEq(t, marshal(t, got["metadata"]), marshal(t, expected["metadata"]))
}

func unmarshalIntoMap(t *testing.T, file []byte) map[string]any {
Expand Down
Loading

0 comments on commit f4d0bb3

Please sign in to comment.