Skip to content

Commit

Permalink
New feijoa smc (0xPolygonHermez#3534)
Browse files Browse the repository at this point in the history
* Clasify smc

* New feijoa smc

* fix test dependency + linter fixes
  • Loading branch information
ARR552 authored Apr 5, 2024
1 parent 399d62c commit 11ee6e2
Show file tree
Hide file tree
Showing 56 changed files with 30,344 additions and 9,976 deletions.
218 changes: 109 additions & 109 deletions etherman/etherman.go

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/0xPolygonHermez/zkevm-node/encoding"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevmbridge"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/etrogpolygonzkevm"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/etrogpolygonzkevmbridge"
ethmanTypes "github.com/0xPolygonHermez/zkevm-node/etherman/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
Expand All @@ -38,7 +38,7 @@ func init() {
}

// This function prepare the blockchain, the wallet with funds and deploy the smc
func newTestingEnv() (ethman *Client, ethBackend *simulated.Backend, auth *bind.TransactOpts, polAddr common.Address, br *polygonzkevmbridge.Polygonzkevmbridge) {
func newTestingEnv() (ethman *Client, ethBackend *simulated.Backend, auth *bind.TransactOpts, polAddr common.Address, br *etrogpolygonzkevmbridge.Etrogpolygonzkevmbridge) {
privateKey, err := crypto.GenerateKey()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -96,12 +96,12 @@ func TestForcedBatchEvent(t *testing.T) {
initBlock, err := etherman.EthClient.BlockByNumber(ctx, nil)
require.NoError(t, err)

amount, err := etherman.RollupManager.GetForcedBatchFee(&bind.CallOpts{Pending: false})
amount, err := etherman.EtrogRollupManager.GetForcedBatchFee(&bind.CallOpts{Pending: false})
require.NoError(t, err)
rawTxs := "f84901843b9aca00827b0c945fbdb2315678afecb367f032d93f642f64180aa380a46057361d00000000000000000000000000000000000000000000000000000000000000048203e9808073efe1fa2d3e27f26f32208550ea9b0274d49050b816cadab05a771f4275d0242fd5d92b3fb89575c070e6c930587c520ee65a3aa8cfe382fcad20421bf51d621c"
data, err := hex.DecodeString(rawTxs)
require.NoError(t, err)
_, err = etherman.ZkEVM.ForceBatch(auth, data, amount)
_, err = etherman.EtrogZkEVM.ForceBatch(auth, data, amount)
require.NoError(t, err)

// Mine the tx in a block
Expand Down Expand Up @@ -139,12 +139,12 @@ func TestSequencedBatchesEvent(t *testing.T) {
ethBackend.Commit()
auth.Value = big.NewInt(0)

amount, err := etherman.RollupManager.GetForcedBatchFee(&bind.CallOpts{Pending: false})
amount, err := etherman.EtrogRollupManager.GetForcedBatchFee(&bind.CallOpts{Pending: false})
require.NoError(t, err)
rawTxs := "f84901843b9aca00827b0c945fbdb2315678afecb367f032d93f642f64180aa380a46057361d00000000000000000000000000000000000000000000000000000000000000048203e9808073efe1fa2d3e27f26f32208550ea9b0274d49050b816cadab05a771f4275d0242fd5d92b3fb89575c070e6c930587c520ee65a3aa8cfe382fcad20421bf51d621c"
data, err := hex.DecodeString(rawTxs)
require.NoError(t, err)
_, err = etherman.ZkEVM.ForceBatch(auth, data, amount)
_, err = etherman.EtrogZkEVM.ForceBatch(auth, data, amount)
require.NoError(t, err)
require.NoError(t, err)
ethBackend.Commit()
Expand All @@ -156,13 +156,13 @@ func TestSequencedBatchesEvent(t *testing.T) {
blocks, _, err := etherman.GetRollupInfoByBlockRange(ctx, initBlock.NumberU64(), &currentBlockNumber)
require.NoError(t, err)
t.Log("Blocks: ", blocks)
var sequences []polygonzkevm.PolygonRollupBaseEtrogBatchData
sequences = append(sequences, polygonzkevm.PolygonRollupBaseEtrogBatchData{
var sequences []etrogpolygonzkevm.PolygonRollupBaseEtrogBatchData
sequences = append(sequences, etrogpolygonzkevm.PolygonRollupBaseEtrogBatchData{
Transactions: common.Hex2Bytes(rawTxs),
}, polygonzkevm.PolygonRollupBaseEtrogBatchData{
}, etrogpolygonzkevm.PolygonRollupBaseEtrogBatchData{
Transactions: common.Hex2Bytes(rawTxs),
})
_, err = etherman.ZkEVM.SequenceBatches(auth, sequences, uint64(time.Now().Unix()), uint64(1), auth.From)
_, err = etherman.EtrogZkEVM.SequenceBatches(auth, sequences, uint64(time.Now().Unix()), uint64(1), auth.From)
require.NoError(t, err)

// Mine the tx in a block
Expand Down Expand Up @@ -197,17 +197,17 @@ func TestVerifyBatchEvent(t *testing.T) {
require.NoError(t, err)

rawTxs := "f84901843b9aca00827b0c945fbdb2315678afecb367f032d93f642f64180aa380a46057361d00000000000000000000000000000000000000000000000000000000000000048203e9808073efe1fa2d3e27f26f32208550ea9b0274d49050b816cadab05a771f4275d0242fd5d92b3fb89575c070e6c930587c520ee65a3aa8cfe382fcad20421bf51d621c"
tx := polygonzkevm.PolygonRollupBaseEtrogBatchData{
tx := etrogpolygonzkevm.PolygonRollupBaseEtrogBatchData{
Transactions: common.Hex2Bytes(rawTxs),
}
//TODO: Fix params
_, err = etherman.ZkEVM.SequenceBatches(auth, []polygonzkevm.PolygonRollupBaseEtrogBatchData{tx}, uint64(time.Now().Unix()), uint64(1), auth.From)
_, err = etherman.EtrogZkEVM.SequenceBatches(auth, []etrogpolygonzkevm.PolygonRollupBaseEtrogBatchData{tx}, uint64(time.Now().Unix()), uint64(1), auth.From)
require.NoError(t, err)

// Mine the tx in a block
ethBackend.Commit()

_, err = etherman.RollupManager.VerifyBatchesTrustedAggregator(auth, 1, uint64(0), uint64(0), uint64(1), [32]byte{}, [32]byte{}, auth.From, [24][32]byte{})
_, err = etherman.EtrogRollupManager.VerifyBatchesTrustedAggregator(auth, 1, uint64(0), uint64(0), uint64(1), [32]byte{}, [32]byte{}, auth.From, [24][32]byte{})
require.NoError(t, err)

// Mine the tx in a block
Expand Down Expand Up @@ -239,12 +239,12 @@ func TestSequenceForceBatchesEvent(t *testing.T) {
initBlock, err := etherman.EthClient.BlockByNumber(ctx, nil)
require.NoError(t, err)

amount, err := etherman.RollupManager.GetForcedBatchFee(&bind.CallOpts{Pending: false})
amount, err := etherman.EtrogRollupManager.GetForcedBatchFee(&bind.CallOpts{Pending: false})
require.NoError(t, err)
rawTxs := "f84901843b9aca00827b0c945fbdb2315678afecb367f032d93f642f64180aa380a46057361d00000000000000000000000000000000000000000000000000000000000000048203e9808073efe1fa2d3e27f26f32208550ea9b0274d49050b816cadab05a771f4275d0242fd5d92b3fb89575c070e6c930587c520ee65a3aa8cfe382fcad20421bf51d621c"
data, err := hex.DecodeString(rawTxs)
require.NoError(t, err)
_, err = etherman.ZkEVM.ForceBatch(auth, data, amount)
_, err = etherman.EtrogZkEVM.ForceBatch(auth, data, amount)
require.NoError(t, err)
ethBackend.Commit()
ethBackend.Commit()
Expand All @@ -266,13 +266,13 @@ func TestSequenceForceBatchesEvent(t *testing.T) {
prevBlock, err := etherman.EthClient.BlockByNumber(ctx, big.NewInt(0).SetUint64(blocks[0].BlockNumber-1))
require.NoError(t, err)
forcedBlockHashL1 := prevBlock.Hash()
forceBatchData := polygonzkevm.PolygonRollupBaseEtrogBatchData{
forceBatchData := etrogpolygonzkevm.PolygonRollupBaseEtrogBatchData{
Transactions: blocks[0].ForcedBatches[0].RawTxsData,
ForcedGlobalExitRoot: forcedGer,
ForcedTimestamp: forcedTimestamp,
ForcedBlockHashL1: forcedBlockHashL1,
}
_, err = etherman.ZkEVM.SequenceForceBatches(auth, []polygonzkevm.PolygonRollupBaseEtrogBatchData{forceBatchData})
_, err = etherman.EtrogZkEVM.SequenceForceBatches(auth, []etrogpolygonzkevm.PolygonRollupBaseEtrogBatchData{forceBatchData})
require.NoError(t, err)
ethBackend.Commit()

Expand Down
46 changes: 23 additions & 23 deletions etherman/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"fmt"
"math/big"

"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/mockpolygonrollupmanager"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/etrogpolygonrollupmanager"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/etrogpolygonzkevm"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/etrogpolygonzkevmbridge"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/etrogpolygonzkevmglobalexitroot"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/mocketrogpolygonrollupmanager"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/mockverifier"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/pol"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonrollupmanager"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevmbridge"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevmglobalexitroot"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/proxy"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -23,7 +23,7 @@ import (

// NewSimulatedEtherman creates an etherman that uses a simulated blockchain. It's important to notice that the ChainID of the auth
// must be 1337. The address that holds the auth will have an initial balance of 10 ETH
func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (*Client, *simulated.Backend, common.Address, *polygonzkevmbridge.Polygonzkevmbridge, error) {
func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (*Client, *simulated.Backend, common.Address, *etrogpolygonzkevmbridge.Etrogpolygonzkevmbridge, error) {
if auth == nil {
// read only client
return &Client{}, nil, common.Address{}, nil, nil
Expand Down Expand Up @@ -61,18 +61,18 @@ func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (*Client, *simula
const posRollupManager = 4
calculatedRollupManagerAddr := crypto.CreateAddress(auth.From, nonce+posRollupManager)
genesis := common.HexToHash("0xfd3434cd8f67e59d73488a2b8da242dd1f02849ea5dd99f0ca22c836c3d5b4a9") // Random value. Needs to be different to 0x0
exitManagerAddr, _, globalExitRoot, err := polygonzkevmglobalexitroot.DeployPolygonzkevmglobalexitroot(auth, client.Client(), calculatedRollupManagerAddr, calculatedBridgeAddr)
exitManagerAddr, _, globalExitRoot, err := etrogpolygonzkevmglobalexitroot.DeployEtrogpolygonzkevmglobalexitroot(auth, client.Client(), calculatedRollupManagerAddr, calculatedBridgeAddr)
if err != nil {
log.Error("error: ", err)
return nil, nil, common.Address{}, nil, err
}
implementationBridgeAddr, _, _, err := polygonzkevmbridge.DeployPolygonzkevmbridge(auth, client.Client())
implementationBridgeAddr, _, _, err := etrogpolygonzkevmbridge.DeployEtrogpolygonzkevmbridge(auth, client.Client())
if err != nil {
log.Error("error: ", err)
return nil, nil, common.Address{}, nil, err
}

implementationMockRollupManagerAddr, _, _, err := mockpolygonrollupmanager.DeployMockpolygonrollupmanager(auth, client.Client(), exitManagerAddr, polAddr, calculatedBridgeAddr)
implementationMockRollupManagerAddr, _, _, err := mocketrogpolygonrollupmanager.DeployMocketrogpolygonrollupmanager(auth, client.Client(), exitManagerAddr, polAddr, calculatedBridgeAddr)
if err != nil {
log.Error("error: ", err)
return nil, nil, common.Address{}, nil, err
Expand All @@ -92,17 +92,17 @@ func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (*Client, *simula
return nil, nil, common.Address{}, nil, fmt.Errorf("RollupManagerAddr (%s) is different from the expected contract address (%s)",
mockRollupManagerAddr.String(), calculatedRollupManagerAddr.String())
}
initZkevmAddr, _, _, err := polygonzkevm.DeployPolygonzkevm(auth, client.Client(), exitManagerAddr, polAddr, bridgeAddr, mockRollupManagerAddr)
initZkevmAddr, _, _, err := etrogpolygonzkevm.DeployEtrogpolygonzkevm(auth, client.Client(), exitManagerAddr, polAddr, bridgeAddr, mockRollupManagerAddr)
if err != nil {
log.Error("error: ", err)
return nil, nil, common.Address{}, nil, err
}
mockRollupManager, err := mockpolygonrollupmanager.NewMockpolygonrollupmanager(mockRollupManagerAddr, client.Client())
mockRollupManager, err := mocketrogpolygonrollupmanager.NewMocketrogpolygonrollupmanager(mockRollupManagerAddr, client.Client())
if err != nil {
log.Error("error: ", err)
return nil, nil, common.Address{}, nil, err
}
br, err := polygonzkevmbridge.NewPolygonzkevmbridge(bridgeAddr, client.Client())
br, err := etrogpolygonzkevmbridge.NewEtrogpolygonzkevmbridge(bridgeAddr, client.Client())
if err != nil {
log.Error("error: ", err)
return nil, nil, common.Address{}, nil, err
Expand Down Expand Up @@ -157,13 +157,13 @@ func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (*Client, *simula
bridgeAddr.String(), calculatedBridgeAddr.String())
}

rollupManager, err := polygonrollupmanager.NewPolygonrollupmanager(mockRollupManagerAddr, client.Client())
rollupManager, err := etrogpolygonrollupmanager.NewEtrogpolygonrollupmanager(mockRollupManagerAddr, client.Client())
if err != nil {
log.Error("error: ", err)
return nil, nil, common.Address{}, nil, err
}

trueZkevm, err := polygonzkevm.NewPolygonzkevm(zkevmAddr, client.Client()) //nolint
trueZkevm, err := etrogpolygonzkevm.NewEtrogpolygonzkevm(zkevmAddr, client.Client()) //nolint
if err != nil {
log.Error("error: ", err)
return nil, nil, common.Address{}, nil, err
Expand All @@ -190,15 +190,15 @@ func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (*Client, *simula
client.Commit()

c := &Client{
EthClient: client.Client(),
ZkEVM: trueZkevm,
RollupManager: rollupManager,
Pol: polContract,
GlobalExitRootManager: globalExitRoot,
RollupID: rollupID,
SCAddresses: []common.Address{zkevmAddr, mockRollupManagerAddr, exitManagerAddr},
auth: map[common.Address]bind.TransactOpts{},
cfg: cfg,
EthClient: client.Client(),
EtrogZkEVM: trueZkevm,
EtrogRollupManager: rollupManager,
Pol: polContract,
EtrogGlobalExitRootManager: globalExitRoot,
RollupID: rollupID,
SCAddresses: []common.Address{zkevmAddr, mockRollupManagerAddr, exitManagerAddr},
auth: map[common.Address]bind.TransactOpts{},
cfg: cfg,
}
err = c.AddOrReplaceAuth(*auth)
if err != nil {
Expand Down
Loading

0 comments on commit 11ee6e2

Please sign in to comment.