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

[R4R] - {0.4.2}: develop into v0.4.2 release #1147

Merged
merged 15 commits into from
Jun 27, 2023
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
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
# Changelog

## [v0.4.2-alpha.0](https://github.com/mantlenetworkio/mantle/commits/v0.4.2-alpha.0) - 2023-06-27

### Features
- Gas Oracle
- Add additional sources for exchange rates and optimize the calculation method for token ratio([#1014](https://github.com/mantlenetworkio/mantle/pull/1014),[#1108](https://github.com/mantlenetworkio/mantle/pull/1108))
- Improve metrics monitoring([#1102](https://github.com/mantlenetworkio/mantle/pull/1102))
- Added a strategy of real-time adjustment of layer1 overhead based on rollup capacity, to obtain a lower tx fee experience([#926](https://github.com/mantlenetworkio/mantle/pull/926))
- L2 Fee Calculation
- Support L2 fee collection, optimize the method for setting L2 gas price and allow for floating within a certain range([#1144](https://github.com/mantlenetworkio/mantle/pull/1144))
- Upgrade Framework
- Enhance the upgrade framework of l2geth to support management of upgrade heights across different networks([#1007](https://github.com/mantlenetworkio/mantle/pull/1007))
- Batch Submitter
- Expose Tss expected response with metric data, enrich handle logics for unexpected case, enrich control workflow([#1107](https://github.com/mantlenetworkio/mantle/pull/1107))
- L2geth
- Support debug api debug_traceCall([#940](https://github.com/mantlenetworkio/mantle/pull/940))

### Bug Fixes
- Fix issues of missing permission verification in contract([#1118](https://github.com/mantlenetworkio/mantle/pull/1118))
- Fix issues of unreasonable contract naming convention([#1095](https://github.com/mantlenetworkio/mantle/pull/1095))
- Fix smart contract related bugs in audit reports([#1043](https://github.com/mantlenetworkio/mantle/pull/1043), [#1138](https://github.com/mantlenetworkio/mantle/pull/1138))
- Adjust checking strategies for staker staking of MantleDa contracts([#1120](https://github.com/mantlenetworkio/mantle/pull/1120), [#1103](https://github.com/mantlenetworkio/mantle/pull/1103))
- Code optimization for batch-submitter, dtl and mt-batcher([#1063](https://github.com/mantlenetworkio/mantle/pull/1063), [#1045](https://github.com/mantlenetworkio/mantle/pull/1045), [#1043](https://github.com/mantlenetworkio/mantle/pull/1043))
- Add permission verification to tss http api([#854](https://github.com/mantlenetworkio/mantle/pull/854))

## [v0.4.1](https://github.com/mantlenetworkio/mantle/commits/v0.4.1) - 2023-06-25

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(The MIT License)

Copyright 2020-2021 Mantle
Copyright 2022-2023 Mantle

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
3 changes: 3 additions & 0 deletions batch-submitter/drivers/sequencer/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ func writeUint64(w io.Writer, val uint64, n uint) error {
// of `val`.
func readUint64(r io.Reader, val *uint64, n uint) error {
var buf [8]byte
if n > 8 {
return fmt.Errorf("bytes shift out of range")
}
if _, err := r.Read(buf[8-n:]); err != nil {
return err
}
Expand Down
39 changes: 33 additions & 6 deletions batch-submitter/drivers/sequencer/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package sequencer_test

import (
"bytes"
"encoding/binary"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"os"
"testing"

Expand All @@ -15,10 +18,10 @@ import (

// TestBatchContextEncodeDecode tests the (de)serialization of a BatchContext
// against the spec test vector. The encoding should be:
// - num_sequenced_txs: 3 bytes
// - num_subsequent_queue_txs: 3 bytes
// - timestamp: 5 bytes
// - block_number: 5 bytes
// - num_sequenced_txs: 3 bytes
// - num_subsequent_queue_txs: 3 bytes
// - timestamp: 5 bytes
// - block_number: 5 bytes
func TestBatchContextEncodeDecode(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -147,7 +150,7 @@ func testAppendSequencerBatchParamsEncodeDecode(

// Finally, encode the decoded object and assert it matches the original
// hex string.
paramsBytes, err := params.Serialize(sequencer.BatchTypeLegacy)
paramsBytes, err := params.Serialize(sequencer.BatchTypeLegacy, nil, nil)

// Return early when testing error cases, no need to reserialize again
if test.Error {
Expand All @@ -159,7 +162,7 @@ func testAppendSequencerBatchParamsEncodeDecode(
require.Equal(t, test.HexEncoding, hex.EncodeToString(paramsBytes))

// Serialize the batches in compressed form
compressedParamsBytes, err := params.Serialize(sequencer.BatchTypeZlib)
compressedParamsBytes, err := params.Serialize(sequencer.BatchTypeZlib, nil, nil)
require.Nil(t, err)

// Deserialize the compressed batch
Expand Down Expand Up @@ -252,3 +255,27 @@ func TestIsMarkerContext(t *testing.T) {
}
require.True(t, batchContext.IsMarkerContext())
}

func TestReadUint64(t *testing.T) {
readUint64 := func(r io.Reader, val *uint64, n uint) error {
var byteOrder = binary.BigEndian
var buf [8]byte
if n > 8 {
return fmt.Errorf("bytes shift out of range")
}
if _, err := r.Read(buf[8-n:]); err != nil {
return err
}
*val = byteOrder.Uint64(buf[:])
return nil
}

var be = make([]byte, 8)
var x uint64
bytes.NewBuffer(be)
binary.BigEndian.PutUint64(be, 100)
require.NoError(t, readUint64(bytes.NewBuffer(be), &x, 8))
require.Equal(t, x, uint64(100))

require.Error(t, readUint64(bytes.NewBuffer(be), &x, 9))
}
22 changes: 22 additions & 0 deletions bss-core/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright 2022-2023 Mantle

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 22 additions & 0 deletions fraud-proof/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright 2022-2023 Mantle

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion fraud-proof/proof/state/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (st *Stack) Back(n int) *uint256.Int {
}

func (st *Stack) HashAfterPops(n int) common.Hash {
return st.hash[st.Len()-n]
return st.hash[len(st.hash)-n]
}

func (st *Stack) EncodeState() []byte {
Expand Down
6 changes: 6 additions & 0 deletions fraud-proof/rollup/types/tx_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ func NewTxBatch(blocks []*types.Block, maxBatchSize uint64) *TxBatch {
}

func (b *TxBatch) LastBlockNumber() uint64 {
if len(b.Contexts) == 0 {
return 0
}
return b.Contexts[len(b.Contexts)-1].BlockNumber
}

func (b *TxBatch) LastBlockRoot() common.Hash {
if len(b.Blocks) == 0 {
return common.Hash{}
}
return b.Blocks[len(b.Blocks)-1].Root()
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(The MIT License)

Copyright 2020-2021 Mantle
Copyright 2020-2021 Optimism

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.5.4",
"@mantleio/contracts": "0.1.0",
"@mantleio/contracts": "0.1.4",
"@mantleio/core-utils": "0.1.0",
"@mantleio/sdk": "0.1.5",
"@mantleio/sdk": "0.2.1",
"@ethersproject/abstract-provider": "^5.6.1",
"@ethersproject/providers": "^5.6.8",
"@ethersproject/transactions": "^5.6.2",
Expand Down
1 change: 1 addition & 0 deletions l2geth/contracts/checkpointoracle/contract/oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract CheckpointOracle {
*/
constructor(address[] memory _adminlist, uint _sectionSize, uint _processConfirms, uint _threshold) public {
for (uint i = 0; i < _adminlist.length; i++) {
require(_adminlist[i] != address(0),"admin list can't contain 0 address");
admins[_adminlist[i]] = true;
adminList.push(_adminlist[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions l2geth/rollup/fees/rollup_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ func PaysEnough(opts *PaysEnoughOpts) error {
}
// Protect users from overpaying by too much
if opts.ThresholdUp != nil {
// overpaying = user fee - expected fee
overpaying := new(big.Int).Sub(opts.UserGasPrice, opts.ExpectedGasPrice)
// overpaying = user fee
overpaying := opts.UserGasPrice
threshold := mulByFloat(opts.ExpectedGasPrice, opts.ThresholdUp)
// if overpaying > threshold, return error
if overpaying.Cmp(threshold) == 1 {
Expand Down
32 changes: 22 additions & 10 deletions l2geth/rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math"
"math/big"
"strconv"
"sync"
Expand Down Expand Up @@ -39,7 +40,8 @@ var (
// errZeroGasPriceTx is the error for when a user submits a transaction
// with gas price zero and fees are currently enforced
errZeroGasPriceTx = errors.New("cannot accept 0 gas price transaction")
float1 = big.NewFloat(1)
feeThresholdDown = big.NewFloat(1)
feeThresholdUp = big.NewFloat(4000)
)

// SyncService implements the main functionality around pulling in transactions
Expand Down Expand Up @@ -127,17 +129,17 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
}
// Ensure sane values for the fee thresholds
if cfg.FeeThresholdDown != nil {
// The fee threshold down should be less than 1
if cfg.FeeThresholdDown.Cmp(float1) != -1 {
return nil, fmt.Errorf("%w: fee threshold down not lower than 1: %f", errBadConfig,
cfg.FeeThresholdDown)
// The fee threshold down should be <= feeThresholdDown
if cfg.FeeThresholdDown.Cmp(feeThresholdDown) == 1 {
return nil, fmt.Errorf("%w: fee threshold down not lower than %f: %f", errBadConfig,
feeThresholdDown, cfg.FeeThresholdDown)
}
}
if cfg.FeeThresholdUp != nil {
// The fee threshold up should be greater than 1
if cfg.FeeThresholdUp.Cmp(float1) != 1 {
return nil, fmt.Errorf("%w: fee threshold up not larger than 1: %f", errBadConfig,
cfg.FeeThresholdUp)
// The fee threshold up should be >= feeThresholdUp
if cfg.FeeThresholdUp.Cmp(feeThresholdUp) == -1 {
return nil, fmt.Errorf("%w: fee threshold up not larger than %f: %f", errBadConfig,
feeThresholdUp, cfg.FeeThresholdUp)
}
}

Expand Down Expand Up @@ -1249,7 +1251,7 @@ func (s *SyncService) verifyFee(tx *types.Transaction) error {
}
if errors.Is(err, fees.ErrGasPriceTooHigh) {
return fmt.Errorf("%w: %d wei, use at most tx.gasPrice = %s wei",
fees.ErrGasPriceTooHigh, tx.GasPrice(), l2GasPrice)
fees.ErrGasPriceTooHigh, tx.GasPrice(), mulByFloat(l2GasPrice, opts.ThresholdUp))
}
return err
}
Expand Down Expand Up @@ -1626,3 +1628,13 @@ func (s *SyncService) GetTxStatusByNumber(number uint64) (*types.TxStatusRespons

return stateRsp, nil
}

// mulByFloat multiplies a big.Int by a float and returns the
// big.Int rounded upwards
func mulByFloat(num *big.Int, float *big.Float) *big.Int {
n := new(big.Float).SetUint64(num.Uint64())
product := n.Mul(n, float)
pfloat, _ := product.Float64()
rounded := math.Ceil(pfloat)
return new(big.Int).SetUint64(uint64(rounded))
}
22 changes: 22 additions & 0 deletions mt-batcher/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright 2022-2023 Mantle

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 changes: 13 additions & 7 deletions mt-batcher/services/restorer/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"strings"
)

const (
maxCallReceiveMessageSize = 314572800
)

type RollupStoreRequest struct {
BatchIndex int64 `json:"batch_index"`
}
Expand Down Expand Up @@ -94,7 +98,7 @@ func (s *DaService) GetBatchTransactionByDataStoreId(c gecho.Context) error {
defer conn.Close()
client := pb.NewDataRetrievalClient(conn)

opt := grpc.MaxCallRecvMsgSize(1024 * 1024 * 300)
opt := grpc.MaxCallRecvMsgSize(maxCallReceiveMessageSize)
request := &pb.FramesAndDataRequest{
DataStoreId: txReq.StoreNumber,
}
Expand Down Expand Up @@ -125,7 +129,7 @@ func (s *DaService) GetDtlBatchTransactionByDataStoreId(c gecho.Context) error {
defer conn.Close()
client := pb.NewDataRetrievalClient(conn)

opt := grpc.MaxCallRecvMsgSize(1024 * 1024 * 300)
opt := grpc.MaxCallRecvMsgSize(maxCallReceiveMessageSize)
request := &pb.FramesAndDataRequest{
DataStoreId: txReq.StoreNumber,
}
Expand All @@ -148,14 +152,17 @@ func (s *DaService) GetDtlBatchTransactionByDataStoreId(c gecho.Context) error {
for i := 0; i < len(newBatchTxn); i++ {
l2Tx := new(types.Transaction)
txDecodeMetaData := new(eigenda.TransactionMeta)
if newBatchTxn[i].TxMeta == nil {
log.Error("Batch tx metadata shouldn't be nil")
return c.JSON(http.StatusBadRequest, errors.New("Batch tx metadata shouldn't be nil"))
}
err = json.Unmarshal(newBatchTxn[i].TxMeta, txDecodeMetaData)
if err != nil {
log.Error("Unmarshal json fail")
return c.JSON(http.StatusBadRequest, errors.New("Unmarshal json fail"))
}
rlpStream := l2rlp.NewStream(bytes.NewBuffer(newBatchTxn[i].RawTx), 0)
if err := l2Tx.DecodeRLP(rlpStream); err != nil {
log.Error("Decode RLP fail")
continue
return c.JSON(http.StatusBadRequest, errors.New("Decode RLP fail"))
}
log.Info("transaction", "hash", l2Tx.Hash().Hex())
newBlockNumber := new(big.Int).SetBytes(newBatchTxn[i].BlockNumber)
Expand All @@ -167,7 +174,6 @@ func (s *DaService) GetDtlBatchTransactionByDataStoreId(c gecho.Context) error {
l1MessageSender = nil
} else {
queueOrigin = types.QueueOriginL1ToL2
//TODO still need to add the L1msg
addrLs := common2.HexToAddress("")
l1MessageSender = &addrLs
}
Expand Down Expand Up @@ -275,7 +281,7 @@ func (s *DaService) GetTransactionListByStoreNumber(c gecho.Context) error {
rlpStream := l2rlp.NewStream(bytes.NewBuffer(newBatchTxn[i].RawTx), 0)
if err := l2Tx.DecodeRLP(rlpStream); err != nil {
log.Error("Decode RLP fail")
continue
return c.JSON(http.StatusBadRequest, errors.New("Decode RLP fail"))
}
log.Info("transaction", "hash", l2Tx.Hash().Hex())
newBlockNumber := new(big.Int).SetBytes(newBatchTxn[i].BlockNumber)
Expand Down
Loading