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

Feature/#555 smc etrog #556

Merged
merged 9 commits into from
Jan 11, 2024
Merged
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
4 changes: 2 additions & 2 deletions config/config.debug.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ BridgeVersion = "v1"

[NetworkConfig]
GenBlockNumber = 1
PolygonBridgeAddress = "0xaAE872C70944D40001755C3EAaE53bC4E1A78bD0"
PolygonBridgeAddress = "0xCca6ECD73932e49633B9307e1aa0fC174525F424"
PolygonZkEVMGlobalExitRootAddress = "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"
PolygonRollupManagerAddress = "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e"
PolygonZkEvmAddress = "0x8dAF17A20c9DBA35f005b6324F493785D239719d"
L2PolygonBridgeAddresses = ["0xaAE872C70944D40001755C3EAaE53bC4E1A78bD0"]
L2PolygonBridgeAddresses = ["0xCca6ECD73932e49633B9307e1aa0fC174525F424"]
4 changes: 2 additions & 2 deletions config/config.local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ BridgeVersion = "v1"

[NetworkConfig]
GenBlockNumber = 1
PolygonBridgeAddress = "0xaAE872C70944D40001755C3EAaE53bC4E1A78bD0"
PolygonBridgeAddress = "0xCca6ECD73932e49633B9307e1aa0fC174525F424"
PolygonZkEVMGlobalExitRootAddress = "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"
PolygonRollupManagerAddress = "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e"
PolygonZkEvmAddress = "0x8dAF17A20c9DBA35f005b6324F493785D239719d"
L2PolygonBridgeAddresses = ["0xaAE872C70944D40001755C3EAaE53bC4E1A78bD0"]
L2PolygonBridgeAddresses = ["0xCca6ECD73932e49633B9307e1aa0fC174525F424"]
4 changes: 2 additions & 2 deletions config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ var (
},
"local": {
GenBlockNumber: 1,
PolygonBridgeAddress: common.HexToAddress("0xaAE872C70944D40001755C3EAaE53bC4E1A78bD0"),
PolygonBridgeAddress: common.HexToAddress("0xCca6ECD73932e49633B9307e1aa0fC174525F424"),
PolygonZkEVMGlobalExitRootAddress: common.HexToAddress("0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"),
PolygonRollupManagerAddress: common.HexToAddress("0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e"),
PolygonZkEvmAddress: common.HexToAddress("0x8dAF17A20c9DBA35f005b6324F493785D239719d"),
L2PolygonBridgeAddresses: []common.Address{common.HexToAddress("0xaAE872C70944D40001755C3EAaE53bC4E1A78bD0")},
L2PolygonBridgeAddresses: []common.Address{common.HexToAddress("0xCca6ECD73932e49633B9307e1aa0fC174525F424")},
},
}
)
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ services:

zkevm-node:
container_name: zkevm-node
image: hermeznetwork/zkevm-node:LxLy-v2-fork-6
image: hermeznetwork/zkevm-node:v0.5.0-RC8
ports:
- 8123:8123
- 61090:61090
Expand All @@ -79,13 +79,13 @@ services:

zkevm-mock-l1-network:
container_name: zkevm-local-l1-network
image: hermeznetwork/geth-zkevm-contracts:v2.1.1-fork.6-geth1.12.0
image: hermeznetwork/geth-zkevm-contracts:v2.1.1-fork.7-geth1.12.0
ports:
- 8545:8545

zkevm-prover:
container_name: zkevm-prover
image: hermeznetwork/zkevm-prover:v3.0.1
image: hermeznetwork/zkevm-prover:v4.0.0-RC21
ports:
- 50051:50051 # Prover
- 50052:50052 # MockProver
Expand Down
4 changes: 2 additions & 2 deletions docs/running_local.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ make test-edge

| Address | Description |
|---|---|
| 0xaAE872C70944D40001755C3EAaE53bC4E1A78bD0 | L1 Bridge |
| 0xaAE872C70944D40001755C3EAaE53bC4E1A78bD0 | L2 Bridge |
| 0xCca6ECD73932e49633B9307e1aa0fC174525F424 | L1 Bridge |
| 0xCca6ECD73932e49633B9307e1aa0fC174525F424 | L2 Bridge |
| 0x5FbDB2315678afecb367f032d93F642f64180aa3 | Pol token |
| 0x8A791620dd6260079BF849Dc5567aDC3F2FdC318 | GlobalExitRootManager |
| 0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e | RollupManager |
Expand Down
84 changes: 74 additions & 10 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const (
TokensOrder EventOrder = "TokenWrapped"
// VerifyBatchOrder identifies a VerifyBatch event
VerifyBatchOrder EventOrder = "VerifyBatch"
// ActivateEtrogOrder identifies the event to activate etrog
ActivateEtrogOrder EventOrder = "etrog"
)

type ethClienter interface {
Expand Down Expand Up @@ -276,11 +278,9 @@ func (etherMan *Client) processEvent(ctx context.Context, vLog types.Log, blocks
log.Debug("UpdateRollup event detected")
return nil
case addExistingRollupSignatureHash:
log.Debug("AddExistingRollup event detected")
return nil
return etherMan.AddExistingRollupEvent(ctx, vLog, blocks, blocksOrder)
case createNewRollupSignatureHash:
log.Debug("CreateNewRollup event detected")
return nil
return etherMan.createNewRollupEvent(ctx, vLog, blocks, blocksOrder)
case obsoleteRollupTypeSignatureHash:
log.Debug("ObsoleteRollupType event detected")
return nil
Expand Down Expand Up @@ -312,16 +312,16 @@ func (etherMan *Client) processEvent(ctx context.Context, vLog types.Log, blocks

func (etherMan *Client) updateGlobalExitRootEvent(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error {
log.Debug("UpdateGlobalExitRoot event detected. Processing...")
globalExitRoot, err := etherMan.PolygonZkEVMGlobalExitRoot.ParseUpdateGlobalExitRoot(vLog)
if err != nil {
return err
}
return etherMan.processUpdateGlobalExitRootEvent(ctx, globalExitRoot.MainnetExitRoot, globalExitRoot.RollupExitRoot, vLog, blocks, blocksOrder)
return etherMan.processUpdateGlobalExitRootEvent(ctx, vLog.Topics[1], vLog.Topics[2], vLog, blocks, blocksOrder)
}

func (etherMan *Client) updateL1InfoTreeEvent(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error {
log.Debug("UpdateL1InfoTree event detected")
return etherMan.processUpdateGlobalExitRootEvent(ctx, vLog.Topics[1], vLog.Topics[2], vLog, blocks, blocksOrder)
globalExitRoot, err := etherMan.PolygonZkEVMGlobalExitRoot.ParseUpdateL1InfoTree(vLog)
if err != nil {
return err
}
return etherMan.processUpdateGlobalExitRootEvent(ctx, globalExitRoot.MainnetExitRoot, globalExitRoot.RollupExitRoot, vLog, blocks, blocksOrder)
}

func (etherMan *Client) processUpdateGlobalExitRootEvent(ctx context.Context, mainnetExitRoot, rollupExitRoot common.Hash, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error {
Expand Down Expand Up @@ -617,3 +617,67 @@ func GenerateGlobalIndex(mainnetFlag bool, rollupIndex uint, localExitRootIndex
globalIndexBytes = append(globalIndexBytes, leri...)
return big.NewInt(0).SetBytes(globalIndexBytes)
}

func (etherMan *Client) createNewRollupEvent(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error {
log.Debug("CreateNewRollup event detected. Processing...")
rollup, err := etherMan.PolygonRollupManager.ParseCreateNewRollup(vLog)
if err != nil {
return err
}
if rollup.RollupID != etherMan.RollupID {
return nil
}

if len(*blocks) == 0 || ((*blocks)[len(*blocks)-1].BlockHash != vLog.BlockHash || (*blocks)[len(*blocks)-1].BlockNumber != vLog.BlockNumber) {
fullBlock, err := etherMan.EtherClient.BlockByHash(ctx, vLog.BlockHash)
if err != nil {
return fmt.Errorf("error getting hashParent. BlockNumber: %d. Error: %v", vLog.BlockNumber, err)
}
block := prepareBlock(vLog, time.Unix(int64(fullBlock.Time()), 0), fullBlock)
block.ActivateEtrog = append(block.ActivateEtrog, true)
*blocks = append(*blocks, block)
} else if (*blocks)[len(*blocks)-1].BlockHash == vLog.BlockHash && (*blocks)[len(*blocks)-1].BlockNumber == vLog.BlockNumber {
(*blocks)[len(*blocks)-1].ActivateEtrog = append((*blocks)[len(*blocks)-1].ActivateEtrog, true)
} else {
log.Error("Error processing TokenWrapped event. BlockHash:", vLog.BlockHash, ". BlockNumber: ", vLog.BlockNumber)
return fmt.Errorf("error processing TokenWrapped event")
}
or := Order{
Name: ActivateEtrogOrder,
Pos: len((*blocks)[len(*blocks)-1].ActivateEtrog) - 1,
}
(*blocksOrder)[(*blocks)[len(*blocks)-1].BlockHash] = append((*blocksOrder)[(*blocks)[len(*blocks)-1].BlockHash], or)
return nil
}

func (etherMan *Client) AddExistingRollupEvent(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error {
log.Debug("AddExistingRollup event detected. Processing...")
rollup, err := etherMan.PolygonRollupManager.ParseAddExistingRollup(vLog)
if err != nil {
return err
}
if rollup.RollupID != etherMan.RollupID {
return nil
}

if len(*blocks) == 0 || ((*blocks)[len(*blocks)-1].BlockHash != vLog.BlockHash || (*blocks)[len(*blocks)-1].BlockNumber != vLog.BlockNumber) {
fullBlock, err := etherMan.EtherClient.BlockByHash(ctx, vLog.BlockHash)
if err != nil {
return fmt.Errorf("error getting hashParent. BlockNumber: %d. Error: %v", vLog.BlockNumber, err)
}
block := prepareBlock(vLog, time.Unix(int64(fullBlock.Time()), 0), fullBlock)
block.ActivateEtrog = append(block.ActivateEtrog, true)
*blocks = append(*blocks, block)
} else if (*blocks)[len(*blocks)-1].BlockHash == vLog.BlockHash && (*blocks)[len(*blocks)-1].BlockNumber == vLog.BlockNumber {
(*blocks)[len(*blocks)-1].ActivateEtrog = append((*blocks)[len(*blocks)-1].ActivateEtrog, true)
} else {
log.Error("Error processing TokenWrapped event. BlockHash:", vLog.BlockHash, ". BlockNumber: ", vLog.BlockNumber)
return fmt.Errorf("error processing TokenWrapped event")
}
or := Order{
Name: ActivateEtrogOrder,
Pos: len((*blocks)[len(*blocks)-1].ActivateEtrog) - 1,
}
(*blocksOrder)[(*blocks)[len(*blocks)-1].BlockHash] = append((*blocksOrder)[(*blocks)[len(*blocks)-1].BlockHash], or)
return nil
}
12 changes: 6 additions & 6 deletions etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ func TestVerifyBatchEvent(t *testing.T) {
require.NoError(t, err)

rawTxs := "f84901843b9aca00827b0c945fbdb2315678afecb367f032d93f642f64180aa380a46057361d00000000000000000000000000000000000000000000000000000000000000048203e9808073efe1fa2d3e27f26f32208550ea9b0274d49050b816cadab05a771f4275d0242fd5d92b3fb89575c070e6c930587c520ee65a3aa8cfe382fcad20421bf51d621c"
tx := polygonzkevm.PolygonRollupBaseBatchData{
GlobalExitRoot: common.Hash{},
Timestamp: initBlock.Time(),
MinForcedTimestamp: 0,
Transactions: common.Hex2Bytes(rawTxs),
tx := polygonzkevm.PolygonRollupBaseEtrogBatchData{
ForcedGlobalExitRoot: common.Hash{},
ForcedBlockHashL1: common.Hash{},
ForcedTimestamp: 0,
Transactions: common.Hex2Bytes(rawTxs),
}
_, err = zkevm.SequenceBatches(auth, []polygonzkevm.PolygonRollupBaseBatchData{tx}, auth.From)
_, err = zkevm.SequenceBatches(auth, []polygonzkevm.PolygonRollupBaseEtrogBatchData{tx}, auth.From)
require.NoError(t, err)

// Mine the tx in a block
Expand Down
1 change: 1 addition & 0 deletions etherman/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Block struct {
Claims []Claim
Tokens []TokenWrapped
VerifiedBatches []VerifiedBatch
ActivateEtrog []bool
ReceivedAt time.Time
}

Expand Down
33 changes: 16 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/0xPolygonHermez/zkevm-bridge-service
go 1.21

require (
github.com/0xPolygonHermez/zkevm-node v0.3.21-0.20231122150335-286094140ed5
github.com/0xPolygonHermez/zkevm-node v0.5.0-RC8
github.com/ethereum/go-ethereum v1.13.2
github.com/gobuffalo/packr/v2 v2.8.3
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0
Expand All @@ -16,22 +16,21 @@ require (
github.com/rubenv/sql-migrate v1.5.2
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.7
golang.org/x/crypto v0.15.0
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb
google.golang.org/grpc v1.59.0
github.com/urfave/cli/v2 v2.26.0
golang.org/x/crypto v0.16.0
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17
google.golang.org/grpc v1.60.0
google.golang.org/protobuf v1.31.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/0xPolygonHermez/zkevm-data-streamer v0.1.11 // indirect
github.com/0xPolygonHermez/zkevm-data-streamer v0.1.18 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/allegro/bigcache v1.2.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down Expand Up @@ -62,7 +61,7 @@ require (
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.10.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
Expand All @@ -76,12 +75,12 @@ require (
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/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.1-0.20180906183839-65a6292f0157 // indirect
github.com/hermeznetwork/tracerr v0.3.2 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand Down Expand Up @@ -123,9 +122,9 @@ require (
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/status-im/keycard-go v0.2.0 // indirect
Expand All @@ -146,14 +145,14 @@ require (
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading
Loading