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

validium/rollup switch #26

Merged
merged 16 commits into from
Oct 23, 2023
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ LastBatchVirtualizationTimeMaxWaitPeriod = "5s"
MaxTxSizeForL1 = 1000
L2Coinbase = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKey = {Path = "/pk/sequencer.keystore", Password = "testonly"}
UseValidium = true

[Aggregator]
Host = "0.0.0.0"
Expand Down
39 changes: 31 additions & 8 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package etherman
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -554,18 +555,39 @@ func (etherMan *Client) BuildSequenceBatchesTxData(sender common.Address, sequen

func (etherMan *Client) sequenceBatches(opts bind.TransactOpts, sequences []ethmanTypes.Sequence, l2Coinbase common.Address, committeeSignaturesAndAddrs []byte) (*types.Transaction, error) {
var batches []polygonzkevm.PolygonZkEVMBatchData
for _, seq := range sequences {
batch := polygonzkevm.PolygonZkEVMBatchData{
TransactionsHash: crypto.Keccak256Hash(seq.BatchL2Data),
GlobalExitRoot: seq.GlobalExitRoot,
Timestamp: uint64(seq.Timestamp),
MinForcedTimestamp: uint64(seq.ForcedBatchTimestamp),

var tx *types.Transaction
var err error
if len(committeeSignaturesAndAddrs) > 0 {
for _, seq := range sequences {
batch := polygonzkevm.PolygonZkEVMBatchData{
TransactionsHash: crypto.Keccak256Hash(seq.BatchL2Data),
GlobalExitRoot: seq.GlobalExitRoot,
Timestamp: uint64(seq.Timestamp),
MinForcedTimestamp: uint64(seq.ForcedBatchTimestamp),
}

batches = append(batches, batch)
}

log.Infof("Sequence batches with validium.")
tx, err = etherMan.ZkEVM.SequenceBatches(&opts, batches, l2Coinbase, committeeSignaturesAndAddrs)
} else {
for _, seq := range sequences {
batch := polygonzkevm.PolygonZkEVMBatchData{
Transactions: seq.BatchL2Data,
GlobalExitRoot: seq.GlobalExitRoot,
Timestamp: uint64(seq.Timestamp),
MinForcedTimestamp: uint64(seq.ForcedBatchTimestamp),
}

batches = append(batches, batch)
}

batches = append(batches, batch)
log.Infof("Sequence batches with rollup.")
tx, err = etherMan.ZkEVM.SequenceBatches(&opts, batches, l2Coinbase, nil)
}

tx, err := etherMan.ZkEVM.SequenceBatches(&opts, batches, l2Coinbase, committeeSignaturesAndAddrs)
if err != nil {
if parsedErr, ok := tryParseError(err); ok {
err = parsedErr
Expand Down Expand Up @@ -813,6 +835,7 @@ func decodeSequences(txData []byte, lastBatchNumber uint64, sequencer common.Add
Coinbase: coinbase,
PolygonZkEVMBatchData: seq,
}
log.Infof("decodeSequences txs len:%d, tx hash:%s", len(seq.Transactions), hex.EncodeToString(seq.TransactionsHash[:]))
}

return sequencedBatches, nil
Expand Down
8 changes: 4 additions & 4 deletions etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ func TestSequencedBatchesEvent(t *testing.T) {
GlobalExitRoot: ger,
Timestamp: currentBlock.Time(),
MinForcedTimestamp: uint64(blocks[2].ForcedBatches[0].ForcedAt.Unix()),
Transactions: crypto.Keccak256Hash(common.Hex2Bytes(rawTxs)),
TransactionsHash: crypto.Keccak256Hash(common.Hex2Bytes(rawTxs)),
})
sequences = append(sequences, polygonzkevm.PolygonZkEVMBatchData{
GlobalExitRoot: ger,
Timestamp: currentBlock.Time() + 1,
MinForcedTimestamp: 0,
Transactions: crypto.Keccak256Hash(common.Hex2Bytes(rawTxs)),
TransactionsHash: crypto.Keccak256Hash(common.Hex2Bytes(rawTxs)),
})
_, err = etherman.ZkEVM.SequenceBatches(auth, sequences, auth.From, []byte{})
require.NoError(t, err)
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestVerifyBatchEvent(t *testing.T) {
GlobalExitRoot: common.Hash{},
Timestamp: initBlock.Time(),
MinForcedTimestamp: 0,
Transactions: crypto.Keccak256Hash(common.Hex2Bytes(rawTxs)),
TransactionsHash: crypto.Keccak256Hash(common.Hex2Bytes(rawTxs)),
}
_, err = etherman.ZkEVM.SequenceBatches(auth, []polygonzkevm.PolygonZkEVMBatchData{tx}, auth.From, []byte{})
require.NoError(t, err)
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestSendSequences(t *testing.T) {
Timestamp: int64(currentBlock.Time() - 1),
BatchL2Data: batchL2Data,
}
tx, err := etherman.sequenceBatches(*auth, []ethmanTypes.Sequence{sequence}, auth.From)
tx, err := etherman.sequenceBatches(*auth, []ethmanTypes.Sequence{sequence}, auth.From, nil)
require.NoError(t, err)
log.Debug("TX: ", tx.Hash())
ethBackend.Commit()
Expand Down
18 changes: 18 additions & 0 deletions etherman/smartcontracts/abi/polygonzkevm.abi
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,11 @@
"inputs": [
{
"components": [
{
"internalType": "bytes",
"name": "transactions",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "transactionsHash",
Expand Down Expand Up @@ -1458,6 +1463,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "newBatchFee",
"type": "uint16"
}
],
"name": "setBatchFee",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
2 changes: 1 addition & 1 deletion etherman/smartcontracts/bin/datacommittee.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion etherman/smartcontracts/bin/polygonzkevm.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion etherman/smartcontracts/datacommittee/datacommittee.go

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions etherman/smartcontracts/matic/matic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions etherman/smartcontracts/mockverifier/mockverifier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 30 additions & 8 deletions etherman/smartcontracts/polygonzkevm/polygonzkevm.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.19
require (
github.com/0xPolygon/cdk-data-availability v0.0.0-20230830141533-4064ada790a6
github.com/didip/tollbooth/v6 v6.1.2
github.com/dop251/goja v0.0.0-20230122112309-96b1610dd4f7
github.com/ethereum/go-ethereum v1.12.0
github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3
github.com/ethereum/go-ethereum v1.12.1
github.com/go-git/go-billy/v5 v5.4.1
github.com/go-git/go-git/v5 v5.8.1
github.com/gobuffalo/packr/v2 v2.8.3
Expand Down Expand Up @@ -45,19 +45,24 @@ require (
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.10.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/ethereum/c-kzg-4844 v0.3.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
Expand All @@ -75,6 +80,7 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/huin/goupnp v1.0.3 // indirect
Expand All @@ -101,6 +107,7 @@ require (
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miguelmota/go-solidity-sha3 v0.1.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
Expand All @@ -120,6 +127,7 @@ require (
github.com/status-im/keycard-go v0.2.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/supranational/blst v0.3.11-0.20230406105308-e9dfc5ee724b // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
Expand All @@ -129,17 +137,18 @@ require (
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

require (
Expand All @@ -153,6 +162,6 @@ require (
github.com/segmentio/kafka-go v0.4.43
)

replace github.com/0xPolygon/cdk-data-availability => github.com/okx/cdk-data-availability v0.0.1-dac.0.20230913020111-2ec48291d6db
replace github.com/0xPolygon/cdk-data-availability => github.com/okx/Xgon-data-availability v0.0.0-20231017042200-1e5db80e4477

replace github.com/0xPolygonHermez/zkevm-node => ./
Loading