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

M1 Support for Fraud Proofs #12

Merged
merged 38 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2c0d205
start fresh
afkbyte Jun 8, 2024
670432b
try to parse with abi
afkbyte Jun 8, 2024
cd78e91
parsing correctly with the abi decoder now! Bringing other changes ba…
afkbyte Jun 8, 2024
3671179
remove commented out code
afkbyte Jun 8, 2024
ddb75c4
update typo in hash
afkbyte Jun 9, 2024
11b2f7f
brought in historical changes
afkbyte Jun 9, 2024
7c7dcf5
brought in replay script changes
afkbyte Jun 9, 2024
0b37bb8
bring in eigenDA ref to the replay script
afkbyte Jun 9, 2024
48faf73
added all changes
afkbyte Jun 9, 2024
f2a8af7
update inbox multiplexer
afkbyte Jun 9, 2024
6e8489a
modify eigenda file path
afkbyte Jun 10, 2024
fc12d81
add more informative logs
afkbyte Jun 10, 2024
c1f70c2
change no EigenDA configured to a log level error, follow same patter…
afkbyte Jun 10, 2024
616d94a
change to string
afkbyte Jun 10, 2024
77922bf
differentiate between derivation pipeline and fraud proof preimages
afkbyte Jun 10, 2024
acbfdec
bump nitro testnode commit
afkbyte Jun 10, 2024
98231af
modified put and get to be synchronus and blocking
afkbyte Jun 10, 2024
db2f388
fix(batch_poster): Fix cert decoding
ethenotethan Jun 26, 2024
e7adb68
fix(batch_poster): Fix cert decoding - update contracts and sequencer…
ethenotethan Jun 28, 2024
2d3f067
fix(batch_poster): Fix cert decoding - fix sequencer inbox posting an…
ethenotethan Jul 1, 2024
42db7ac
fix(batch_poster): Fix cert decoding - remove debug files
ethenotethan Jul 1, 2024
96e0f74
fix: Updated contracts to better align with nitro deploy tooling and …
ethenotethan Jul 2, 2024
6d2a016
refactors and minor tweaks
ethenotethan Jul 3, 2024
ebac5bc
update go.mod and submodules
ethenotethan Jul 3, 2024
3ab6f9b
update go.mod and submodules
ethenotethan Jul 3, 2024
363ec7e
fix batch header hash calculation bug
ethenotethan Jul 3, 2024
2c02a8a
remove dbug stmts && update system tests
ethenotethan Jul 3, 2024
35b2cae
fix challenge test construction
ethenotethan Jul 3, 2024
104aea9
fix challenge test construction
ethenotethan Jul 3, 2024
fce0728
remove rollup manager dep
ethenotethan Jul 3, 2024
c6ec1ef
patch CI bug
ethenotethan Jul 3, 2024
a1cc5d6
update contracts submodule
ethenotethan Jul 3, 2024
385781b
update contracts submodule
ethenotethan Jul 3, 2024
a5ef13c
update gen.go to dump files being read for yul binding generation
ethenotethan Jul 3, 2024
81b1755
update gen.go to dump files being read for yul binding generation
ethenotethan Jul 3, 2024
d609a90
only generate yul artifacts for 4844 reader
ethenotethan Jul 3, 2024
a818fc9
update contracts submodule
ethenotethan Jul 4, 2024
21651dc
update contracts submodule
ethenotethan Jul 4, 2024
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "go-ethereum"]
path = go-ethereum
url = https://github.com/OffchainLabs/go-ethereum.git
url = git@github.com:Layr-Labs/nitro-go-ethereum-private.git
[submodule "fastcache"]
path = fastcache
url = https://github.com/OffchainLabs/fastcache.git
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ COPY ./blsSignatures ./blsSignatures
COPY ./cmd/chaininfo ./cmd/chaininfo
COPY ./cmd/replay ./cmd/replay
COPY ./das/dastree ./das/dastree
COPY ./das/eigenda ./das/eigenda
COPY ./eigenda ./eigenda
COPY ./precompiles ./precompiles
COPY ./statetransfer ./statetransfer
COPY ./util ./util
Expand Down
1 change: 1 addition & 0 deletions arbitrator/jit/src/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum DynamicObject {
#[derive(Clone, Debug)]
pub struct PendingEvent {
pub id: JsValue,
#[allow(dead_code)]
pub this: JsValue,
pub args: Vec<GoValue>,
}
Expand Down
156 changes: 136 additions & 20 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
"github.com/offchainlabs/nitro/cmd/chaininfo"
"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/das"
"github.com/offchainlabs/nitro/das/eigenda"
"github.com/offchainlabs/nitro/eigenda"
"github.com/offchainlabs/nitro/execution"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/util"
Expand All @@ -64,8 +64,9 @@ var (
const (
batchPosterSimpleRedisLockKey = "node.batch-poster.redis-lock.simple-lock-key"

sequencerBatchPostMethodName = "addSequencerL2BatchFromOrigin0"
sequencerBatchPostWithBlobsMethodName = "addSequencerL2BatchFromBlobs"
sequencerBatchPostMethodName = "addSequencerL2BatchFromOrigin0"
sequencerBatchPostWithBlobsMethodName = "addSequencerL2BatchFromBlobs"
sequencerBatchPostWithEigendaMethodName = "addSequencerL2BatchFromEigenDA"
)

type batchPosterPosition struct {
Expand Down Expand Up @@ -143,6 +144,7 @@ type BatchPosterConfig struct {
RedisLock redislock.SimpleCfg `koanf:"redis-lock" reload:"hot"`
ExtraBatchGas uint64 `koanf:"extra-batch-gas" reload:"hot"`
Post4844Blobs bool `koanf:"post-4844-blobs" reload:"hot"`
PostEigenDA bool `koanf:"post-eigen-da" reload:"hot"`
IgnoreBlobPrice bool `koanf:"ignore-blob-price" reload:"hot"`
ParentChainWallet genericconf.WalletConfig `koanf:"parent-chain-wallet"`
L1BlockBound string `koanf:"l1-block-bound" reload:"hot"`
Expand Down Expand Up @@ -194,6 +196,7 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".gas-refunder-address", DefaultBatchPosterConfig.GasRefunderAddress, "The gas refunder contract address (optional)")
f.Uint64(prefix+".extra-batch-gas", DefaultBatchPosterConfig.ExtraBatchGas, "use this much more gas than estimation says is necessary to post batches")
f.Bool(prefix+".post-4844-blobs", DefaultBatchPosterConfig.Post4844Blobs, "if the parent chain supports 4844 blobs and they're well priced, post EIP-4844 blobs")
f.Bool(prefix+".post-eigen-da", DefaultBatchPosterConfig.PostEigenDA, "Post data to EigenDA")
f.Bool(prefix+".ignore-blob-price", DefaultBatchPosterConfig.IgnoreBlobPrice, "if the parent chain supports 4844 blobs and ignore-blob-price is true, post 4844 blobs even if it's not price efficient")
f.String(prefix+".redis-url", DefaultBatchPosterConfig.RedisUrl, "if non-empty, the Redis URL to store queued transactions in")
f.String(prefix+".l1-block-bound", DefaultBatchPosterConfig.L1BlockBound, "only post messages to batches when they're within the max future block/timestamp as of this L1 block tag (\"safe\", \"finalized\", \"latest\", or \"ignore\" to ignore this check)")
Expand Down Expand Up @@ -221,6 +224,7 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
GasRefunderAddress: "",
ExtraBatchGas: 50_000,
Post4844Blobs: false,
PostEigenDA: false,
IgnoreBlobPrice: false,
DataPoster: dataposter.DefaultDataPosterConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
Expand Down Expand Up @@ -252,6 +256,30 @@ var TestBatchPosterConfig = BatchPosterConfig{
GasRefunderAddress: "",
ExtraBatchGas: 10_000,
Post4844Blobs: true,
PostEigenDA: false,
IgnoreBlobPrice: false,
DataPoster: dataposter.TestDataPosterConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
L1BlockBound: "",
L1BlockBoundBypass: time.Hour,
UseAccessLists: true,
GasEstimateBaseFeeMultipleBips: arbmath.OneInBips * 3 / 2,
}

var EigenDABatchPosterConfig = BatchPosterConfig{
Enable: true,
MaxSize: 100000,
Max4844BatchSize: DefaultBatchPosterConfig.Max4844BatchSize,
PollInterval: time.Millisecond * 10,
ErrorDelay: time.Millisecond * 10,
MaxDelay: 0,
WaitForMaxDelay: false,
CompressionLevel: 2,
DASRetentionPeriod: time.Hour * 24 * 15,
GasRefunderAddress: "",
ExtraBatchGas: 10_000,
Post4844Blobs: false,
PostEigenDA: true,
IgnoreBlobPrice: false,
DataPoster: dataposter.TestDataPosterConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
Expand Down Expand Up @@ -611,6 +639,7 @@ type buildingBatch struct {
msgCount arbutil.MessageIndex
haveUsefulMessage bool
use4844 bool
useEigenDA bool
}

func newBatchSegments(firstDelayed uint64, config *BatchPosterConfig, backlog uint64, use4844 bool) *batchSegments {
Expand Down Expand Up @@ -847,11 +876,16 @@ func (b *BatchPoster) encodeAddBatch(
l2MessageData []byte,
delayedMsg uint64,
use4844 bool,
useEigenDA bool,
eigenDaBlobInfo *eigenda.EigenDABlobInfo,
) ([]byte, []kzg4844.Blob, error) {
methodName := sequencerBatchPostMethodName
if use4844 {
methodName = sequencerBatchPostWithBlobsMethodName
}
if useEigenDA {
methodName = sequencerBatchPostWithEigendaMethodName
}
method, ok := b.seqInboxABI.Methods[methodName]
if !ok {
return nil, nil, errors.New("failed to find add batch method")
Expand All @@ -872,6 +906,88 @@ func (b *BatchPoster) encodeAddBatch(
new(big.Int).SetUint64(uint64(prevMsgNum)),
new(big.Int).SetUint64(uint64(newMsgNum)),
)
} else if useEigenDA {

blobVerificationProofType, err := abi.NewType("tuple", "", []abi.ArgumentMarshaling{
{Name: "batchID", Type: "uint32"},
{Name: "blobIndex", Type: "uint32"},
{Name: "batchMetadata", Type: "tuple",
Components: []abi.ArgumentMarshaling{
{Name: "batchHeader", Type: "tuple",
Components: []abi.ArgumentMarshaling{
{Name: "blobHeadersRoot", Type: "bytes32"},
{Name: "quorumNumbers", Type: "bytes"},
{Name: "signedStakeForQuorums", Type: "bytes"},
{Name: "referenceBlockNumber", Type: "uint32"},
},
},
{Name: "signatoryRecordHash", Type: "bytes32"},
{Name: "confirmationBlockNumber", Type: "uint32"},
},
},
{
Name: "inclusionProof",
Type: "bytes",
},
{
Name: "quorumIndices",
Type: "bytes",
},
})

if err != nil {
return nil, nil, err
}

blobHeaderType, err := abi.NewType("tuple", "", []abi.ArgumentMarshaling{
{Name: "commitment", Type: "tuple", Components: []abi.ArgumentMarshaling{
{Name: "X", Type: "uint256"},
{Name: "Y", Type: "uint256"},
}},
{Name: "dataLength", Type: "uint32"},
{Name: "quorumBlobParams", Type: "tuple[]", Components: []abi.ArgumentMarshaling{
{Name: "quorumNumber", Type: "uint8"},
{Name: "adversaryThresholdPercentage", Type: "uint8"},
{Name: "confirmationThresholdPercentage", Type: "uint8"},
{Name: "chunkLength", Type: "uint32"},
}},
})
if err != nil {
return nil, nil, err
}

u256Type, err := abi.NewType("uint256", "", nil)
if err != nil {
return nil, nil, err
}

// Create ABI arguments
arguments := abi.Arguments{
{Type: u256Type},
{Type: blobVerificationProofType},
{Type: blobHeaderType},
{Type: u256Type},
{Type: u256Type},
{Type: u256Type},
}

// define values array
values := make([]interface{}, 6)
values[0] = seqNum
values[1] = eigenDaBlobInfo.BlobVerificationProof
values[2] = eigenDaBlobInfo.BlobHeader
values[3] = new(big.Int).SetUint64(delayedMsg)
values[4] = new(big.Int).SetUint64(uint64(prevMsgNum))
values[5] = new(big.Int).SetUint64(uint64(newMsgNum))

// pack arguments
// Pack the BlobHeader
calldata, err = arguments.PackValues(values)

if err != nil {
return nil, nil, err
}

} else {
calldata, err = method.Inputs.Pack(
seqNum,
Expand All @@ -887,6 +1003,7 @@ func (b *BatchPoster) encodeAddBatch(
}
fullCalldata := append([]byte{}, method.ID...)
fullCalldata = append(fullCalldata, calldata...)
println("Full calldata: %s", hexutil.Encode(fullCalldata))
return fullCalldata, kzgBlobs, nil
}

Expand All @@ -907,7 +1024,7 @@ func estimateGas(client rpc.ClientInterface, ctx context.Context, params estimat
return uint64(gas), err
}

func (b *BatchPoster) estimateGas(ctx context.Context, sequencerMessage []byte, delayedMessages uint64, realData []byte, realBlobs []kzg4844.Blob, realNonce uint64, realAccessList types.AccessList) (uint64, error) {
func (b *BatchPoster) estimateGas(ctx context.Context, sequencerMessage []byte, delayedMessages uint64, realData []byte, realBlobs []kzg4844.Blob, realNonce uint64, realAccessList types.AccessList, eigenDaBlobInfo *eigenda.EigenDABlobInfo) (uint64, error) {
config := b.config()
rpcClient := b.l1Reader.Client()
rawRpcClient := rpcClient.Client()
Expand Down Expand Up @@ -949,7 +1066,7 @@ func (b *BatchPoster) estimateGas(ctx context.Context, sequencerMessage []byte,
// However, we set nextMsgNum to 1 because it is necessary for a correct estimation for the final to be non-zero.
// Because we're likely estimating against older state, this might not be the actual next message,
// but the gas used should be the same.
data, kzgBlobs, err := b.encodeAddBatch(abi.MaxUint256, 0, 1, sequencerMessage, delayedMessages, len(realBlobs) > 0)
data, kzgBlobs, err := b.encodeAddBatch(abi.MaxUint256, 0, 1, sequencerMessage, delayedMessages, len(realBlobs) > 0, eigenDaBlobInfo != nil, eigenDaBlobInfo)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -1044,11 +1161,19 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
}
}

var useEigenDA bool
if b.eigenDAWriter != nil {
useEigenDA = true
}

println("use4844", use4844, "useEigenDA", useEigenDA)

b.building = &buildingBatch{
segments: newBatchSegments(batchPosition.DelayedMessageCount, b.config(), b.GetBacklogEstimate(), use4844),
msgCount: batchPosition.MessageCount,
startMsgCount: batchPosition.MessageCount,
use4844: use4844,
useEigenDA: useEigenDA,
}
}
msgCount, err := b.streamer.GetMessageCount()
Expand Down Expand Up @@ -1224,26 +1349,16 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
}
}

var blobInfo *eigenda.EigenDABlobInfo
if b.daWriter == nil && b.eigenDAWriter != nil {
log.Info("Start to write data to eigenda: ", "data", hex.EncodeToString(sequencerMsg))
daRef, err := b.eigenDAWriter.Store(ctx, sequencerMsg)
if err != nil {
if config.DisableEigenDAFallbackStoreDataOnChain {
log.Warn("Falling back to storing data on chain", "err", err)
return false, errors.New("unable to post batch to EigenDA and fallback storing data on chain is disabled")
}
}

pointer, err := b.eigenDAWriter.Serialize(daRef)
blobInfo, err = b.eigenDAWriter.Store(ctx, sequencerMsg)
if err != nil {
log.Warn("DaRef serialization failed", "err", err)
return false, errors.New("DaRef serialization failed")
return false, err
}
log.Info("EigenDA transaction receipt(data pointer): ", "hash", hex.EncodeToString(daRef.BatchHeaderHash), "index", daRef.BlobIndex)
sequencerMsg = pointer
}

data, kzgBlobs, err := b.encodeAddBatch(new(big.Int).SetUint64(batchPosition.NextSeqNum), batchPosition.MessageCount, b.building.msgCount, sequencerMsg, b.building.segments.delayedMsg, b.building.use4844)
data, kzgBlobs, err := b.encodeAddBatch(new(big.Int).SetUint64(batchPosition.NextSeqNum), batchPosition.MessageCount, b.building.msgCount, sequencerMsg, b.building.segments.delayedMsg, b.building.use4844, b.building.useEigenDA, blobInfo)
if err != nil {
return false, err
}
Expand All @@ -1258,7 +1373,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
// In theory, this might reduce gas usage, but only by a factor that's already
// accounted for in `config.ExtraBatchGas`, as that same factor can appear if a user
// posts a new delayed message that we didn't see while gas estimating.
gasLimit, err := b.estimateGas(ctx, sequencerMsg, lastPotentialMsg.DelayedMessagesRead, data, kzgBlobs, nonce, accessList)
gasLimit, err := b.estimateGas(ctx, sequencerMsg, lastPotentialMsg.DelayedMessagesRead, data, kzgBlobs, nonce, accessList, blobInfo)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -1286,6 +1401,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
}
log.Info(
"BatchPoster: batch sent",
"eigenDA", b.building.useEigenDA,
"sequenceNumber", batchPosition.NextSeqNum,
"from", batchPosition.MessageCount,
"to", b.building.msgCount,
Expand Down
1 change: 1 addition & 0 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ const minWait = time.Second * 10
func (p *DataPoster) Start(ctxIn context.Context) {
p.StopWaiter.Start(ctxIn, p)
p.CallIteratively(func(ctx context.Context) time.Duration {
println("Data poster CallIteratively")
p.mutex.Lock()
defer p.mutex.Unlock()
err := p.updateBalance(ctx)
Expand Down
8 changes: 6 additions & 2 deletions arbnode/inbox_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/broadcaster"
m "github.com/offchainlabs/nitro/broadcaster/message"
"github.com/offchainlabs/nitro/das/eigenda"
"github.com/offchainlabs/nitro/eigenda"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/containers"
)
Expand Down Expand Up @@ -616,8 +616,12 @@ func (t *InboxTracker) AddSequencerBatches(ctx context.Context, client arbutil.L
if t.blobReader != nil {
daProviders = append(daProviders, arbstate.NewDAProviderBlobReader(t.blobReader))
}
multiplexer := arbstate.NewInboxMultiplexer(backend, prevbatchmeta.DelayedMessageCount, daProviders, t.eigenDA, arbstate.KeysetValidate)
if t.eigenDA != nil {
daProviders = append(daProviders, arbstate.NewDAProviderEigenDA(t.eigenDA))
}
multiplexer := arbstate.NewInboxMultiplexer(backend, prevbatchmeta.DelayedMessageCount, daProviders, arbstate.KeysetValidate)
batchMessageCounts := make(map[uint64]arbutil.MessageIndex)

currentpos := prevbatchmeta.MessageCount + 1
for {
if len(backend.batches) == 0 {
Expand Down
4 changes: 3 additions & 1 deletion arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/offchainlabs/nitro/broadcaster"
"github.com/offchainlabs/nitro/cmd/chaininfo"
"github.com/offchainlabs/nitro/das"
"github.com/offchainlabs/nitro/das/eigenda"
"github.com/offchainlabs/nitro/eigenda"
"github.com/offchainlabs/nitro/execution"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
Expand Down Expand Up @@ -546,6 +546,8 @@ func createNodeImpl(
eigenDAWriter = eigenDAService
}

log.Info("EigenDA reader", "reader", eigenDAReader)

inboxTracker, err := NewInboxTracker(arbDb, txStreamer, daReader, blobReader, eigenDAReader)
if err != nil {
return nil, err
Expand Down
Loading
Loading