Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

New smc version #1581

Merged
merged 8 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
New smc version
  • Loading branch information
ARR552 committed Jan 24, 2023
commit 5f57c38b1de8da1ee3a47c1bda05071ad0714888
30 changes: 15 additions & 15 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

"github.com/0xPolygonHermez/zkevm-node/etherman/etherscan"
"github.com/0xPolygonHermez/zkevm-node/etherman/ethgasstation"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/globalexitrootmanager"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevmglobalexitroot"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/matic"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/proofofefficiency"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm"
ethmanTypes "github.com/0xPolygonHermez/zkevm-node/etherman/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
Expand Down Expand Up @@ -105,8 +105,8 @@ type externalGasProviders struct {
// Client is a simple implementation of EtherMan.
type Client struct {
EthClient ethereumClient
PoE *proofofefficiency.Proofofefficiency
GlobalExitRootManager *globalexitrootmanager.Globalexitrootmanager
PoE *polygonzkevm.Polygonzkevm
GlobalExitRootManager *polygonzkevmglobalexitroot.Polygonzkevmglobalexitroot
Matic *matic.Matic
SCAddresses []common.Address

Expand All @@ -125,11 +125,11 @@ func NewClient(cfg Config) (*Client, error) {
return nil, err
}
// Create smc clients
poe, err := proofofefficiency.NewProofofefficiency(cfg.PoEAddr, ethClient)
poe, err := polygonzkevm.NewPolygonzkevm(cfg.PoEAddr, ethClient)
if err != nil {
return nil, err
}
globalExitRoot, err := globalexitrootmanager.NewGlobalexitrootmanager(cfg.GlobalExitRootManagerAddr, ethClient)
globalExitRoot, err := polygonzkevmglobalexitroot.NewPolygonzkevmglobalexitroot(cfg.GlobalExitRootManagerAddr, ethClient)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -347,13 +347,13 @@ func (etherMan *Client) BuildSequenceBatchesTxData(sender common.Address, sequen
}

func (etherMan *Client) sequenceBatches(opts bind.TransactOpts, sequences []ethmanTypes.Sequence) (*types.Transaction, error) {
var batches []proofofefficiency.ProofOfEfficiencyBatchData
var batches []polygonzkevm.PolygonZkEVMBatchData
for _, seq := range sequences {
batchL2Data, err := state.EncodeTransactions(seq.Txs)
if err != nil {
return nil, fmt.Errorf("failed to encode transactions, err: %v", err)
}
batch := proofofefficiency.ProofOfEfficiencyBatchData{
batch := polygonzkevm.PolygonZkEVMBatchData{
Transactions: batchL2Data,
GlobalExitRoot: seq.GlobalExitRoot,
Timestamp: uint64(seq.Timestamp),
Expand Down Expand Up @@ -467,7 +467,7 @@ func (etherMan *Client) forcedBatchEvent(ctx context.Context, vLog types.Log, bl
txData := tx.Data()
// Extract coded txs.
// Load contract ABI
abi, err := abi.JSON(strings.NewReader(proofofefficiency.ProofofefficiencyABI))
abi, err := abi.JSON(strings.NewReader(polygonzkevm.PolygonzkevmABI))
if err != nil {
return err
}
Expand Down Expand Up @@ -561,7 +561,7 @@ func (etherMan *Client) sequencedBatchesEvent(ctx context.Context, vLog types.Lo
func decodeSequences(txData []byte, lastBatchNumber uint64, sequencer common.Address, txHash common.Hash, nonce uint64) ([]SequencedBatch, error) {
// Extract coded txs.
// Load contract ABI
abi, err := abi.JSON(strings.NewReader(proofofefficiency.ProofofefficiencyABI))
abi, err := abi.JSON(strings.NewReader(polygonzkevm.PolygonzkevmABI))
if err != nil {
return nil, err
}
Expand All @@ -577,7 +577,7 @@ func decodeSequences(txData []byte, lastBatchNumber uint64, sequencer common.Add
if err != nil {
return nil, err
}
var sequences []proofofefficiency.ProofOfEfficiencyBatchData
var sequences []polygonzkevm.PolygonZkEVMBatchData
bytedata, err := json.Marshal(data[0])
if err != nil {
return nil, err
Expand All @@ -595,7 +595,7 @@ func decodeSequences(txData []byte, lastBatchNumber uint64, sequencer common.Add
Coinbase: sequencer,
TxHash: txHash,
Nonce: nonce,
ProofOfEfficiencyBatchData: seq,
PolygonZkEVMBatchData: seq,
}
}

Expand Down Expand Up @@ -686,7 +686,7 @@ func (etherMan *Client) forceSequencedBatchesEvent(ctx context.Context, vLog typ
func decodeSequencedForceBatches(txData []byte, lastBatchNumber uint64, sequencer common.Address, txHash common.Hash, block *types.Block, nonce uint64) ([]SequencedForceBatch, error) {
// Extract coded txs.
// Load contract ABI
abi, err := abi.JSON(strings.NewReader(proofofefficiency.ProofofefficiencyABI))
abi, err := abi.JSON(strings.NewReader(polygonzkevm.PolygonzkevmABI))
if err != nil {
return nil, err
}
Expand All @@ -703,7 +703,7 @@ func decodeSequencedForceBatches(txData []byte, lastBatchNumber uint64, sequence
return nil, err
}

var forceBatches []proofofefficiency.ProofOfEfficiencyForcedBatchData
var forceBatches []polygonzkevm.PolygonZkEVMBatchData
bytedata, err := json.Marshal(data[0])
if err != nil {
return nil, err
Expand All @@ -722,7 +722,7 @@ func decodeSequencedForceBatches(txData []byte, lastBatchNumber uint64, sequence
TxHash: txHash,
Timestamp: time.Unix(int64(block.Time()), 0),
Nonce: nonce,
ProofOfEfficiencyForcedBatchData: force,
PolygonZkEVMBatchData: force,
}
}
return sequencedForcedBatches, nil
Expand Down
20 changes: 10 additions & 10 deletions etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"
"time"

"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/bridge"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/proofofefficiency"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevmbridge"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm"
ethmanTypes "github.com/0xPolygonHermez/zkevm-node/etherman/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum"
Expand All @@ -30,7 +30,7 @@ func init() {
}

// This function prepare the blockchain, the wallet with funds and deploy the smc
func newTestingEnv() (ethman *Client, ethBackend *backends.SimulatedBackend, auth *bind.TransactOpts, maticAddr common.Address, br *bridge.Bridge) {
func newTestingEnv() (ethman *Client, ethBackend *backends.SimulatedBackend, auth *bind.TransactOpts, maticAddr common.Address, br *polygonzkevmbridge.Polygonzkevmbridge) {
privateKey, err := crypto.GenerateKey()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -150,14 +150,14 @@ func TestSequencedBatchesEvent(t *testing.T) {
currentBlockNumber := currentBlock.NumberU64()
blocks, _, err := etherman.GetRollupInfoByBlockRange(ctx, initBlock.NumberU64(), &currentBlockNumber)
require.NoError(t, err)
var sequences []proofofefficiency.ProofOfEfficiencyBatchData
sequences = append(sequences, proofofefficiency.ProofOfEfficiencyBatchData{
var sequences []polygonzkevm.PolygonZkEVMBatchData
sequences = append(sequences, polygonzkevm.PolygonZkEVMBatchData{
GlobalExitRoot: ger,
Timestamp: currentBlock.Time(),
MinForcedTimestamp: uint64(blocks[1].ForcedBatches[0].ForcedAt.Unix()),
Transactions: common.Hex2Bytes(rawTxs),
})
sequences = append(sequences, proofofefficiency.ProofOfEfficiencyBatchData{
sequences = append(sequences, polygonzkevm.PolygonZkEVMBatchData{
GlobalExitRoot: ger,
Timestamp: currentBlock.Time() + 1,
MinForcedTimestamp: 0,
Expand Down Expand Up @@ -195,13 +195,13 @@ func TestVerifyBatchEvent(t *testing.T) {
require.NoError(t, err)

rawTxs := "f84901843b9aca00827b0c945fbdb2315678afecb367f032d93f642f64180aa380a46057361d00000000000000000000000000000000000000000000000000000000000000048203e9808073efe1fa2d3e27f26f32208550ea9b0274d49050b816cadab05a771f4275d0242fd5d92b3fb89575c070e6c930587c520ee65a3aa8cfe382fcad20421bf51d621c"
tx := proofofefficiency.ProofOfEfficiencyBatchData{
tx := polygonzkevm.PolygonZkEVMBatchData{
GlobalExitRoot: common.Hash{},
Timestamp: initBlock.Time(),
MinForcedTimestamp: 0,
Transactions: common.Hex2Bytes(rawTxs),
}
_, err = etherman.PoE.SequenceBatches(auth, []proofofefficiency.ProofOfEfficiencyBatchData{tx})
_, err = etherman.PoE.SequenceBatches(auth, []polygonzkevm.PolygonZkEVMBatchData{tx})
require.NoError(t, err)

// Mine the tx in a block
Expand Down Expand Up @@ -264,12 +264,12 @@ func TestSequenceForceBatchesEvent(t *testing.T) {
blocks, _, err := etherman.GetRollupInfoByBlockRange(ctx, initBlock.NumberU64(), &finalBlockNumber)
require.NoError(t, err)

forceBatchData := proofofefficiency.ProofOfEfficiencyForcedBatchData{
forceBatchData := polygonzkevm.PolygonZkEVMForcedBatchData{
Transactions: blocks[0].ForcedBatches[0].RawTxsData,
GlobalExitRoot: blocks[0].ForcedBatches[0].GlobalExitRoot,
MinForcedTimestamp: uint64(blocks[0].ForcedBatches[0].ForcedAt.Unix()),
}
_, err = etherman.PoE.SequenceForceBatches(auth, []proofofefficiency.ProofOfEfficiencyForcedBatchData{forceBatchData})
_, err = etherman.PoE.SequenceForceBatches(auth, []polygonzkevm.PolygonZkEVMForcedBatchData{forceBatchData})
require.NoError(t, err)
ethBackend.Commit()

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

"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/bridge"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/globalexitrootmanager"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevmbridge"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevmglobalexitroot"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/matic"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/mockverifier"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/proofofefficiency"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -19,7 +19,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) (etherman *Client, ethBackend *backends.SimulatedBackend, maticAddr common.Address, br *bridge.Bridge, err error) {
func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (etherman *Client, ethBackend *backends.SimulatedBackend, maticAddr common.Address, br *polygonzkevmbridge.Polygonzkevmbridge, err error) {
if auth == nil {
// read only client
return &Client{}, nil, common.Address{}, nil, nil
Expand Down Expand Up @@ -55,19 +55,19 @@ func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (etherman *Client
const posPoE = 3
calculatedPoEAddr := crypto.CreateAddress(auth.From, nonce+posPoE)
genesis := common.HexToHash("0xfd3434cd8f67e59d73488a2b8da242dd1f02849ea5dd99f0ca22c836c3d5b4a9") // Random value. Needs to be different to 0x0
exitManagerAddr, _, globalExitRoot, err := globalexitrootmanager.DeployGlobalexitrootmanager(auth, client)
exitManagerAddr, _, globalExitRoot, err := polygonzkevmglobalexitroot.DeployPolygonzkevmglobalexitroot(auth, client)
if err != nil {
return nil, nil, common.Address{}, nil, err
}
_, err = globalExitRoot.Initialize(auth, calculatedPoEAddr, calculatedBridgeAddr)
if err != nil {
return nil, nil, common.Address{}, nil, err
}
bridgeAddr, _, br, err := bridge.DeployBridge(auth, client)
bridgeAddr, _, br, err := polygonzkevmbridge.DeployPolygonzkevmbridge(auth, client)
if err != nil {
return nil, nil, common.Address{}, nil, err
}
poeAddr, _, poe, err := proofofefficiency.DeployProofofefficiency(auth, client)
poeAddr, _, poe, err := polygonzkevm.DeployPolygonzkevm(auth, client)
if err != nil {
return nil, nil, common.Address{}, nil, err
}
Expand All @@ -76,7 +76,7 @@ func NewSimulatedEtherman(cfg Config, auth *bind.TransactOpts) (etherman *Client
return nil, nil, common.Address{}, nil, err
}

poeParams := proofofefficiency.ProofOfEfficiencyInitializePackedParameters{
poeParams := polygonzkevm.PolygonZkEVMInitializePackedParameters{
Admin: auth.From,
ChainID: 1000, //nolint:gomnd
TrustedSequencer: auth.From,
Expand Down
Loading