Skip to content
Open
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
6 changes: 3 additions & 3 deletions action/blob_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func (tx *BlobTxData) SanityCheck() error {
if len(tx.blobHashes) == 0 {
return errors.New("blobless blob transaction")
}
if permitted := params.MaxBlobGasPerBlock / params.BlobTxBlobGasPerBlob; len(tx.blobHashes) > permitted {
return errors.Errorf("too many blobs in transaction: have %d, permitted %d", len(tx.blobHashes), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)
if permitted := MaxBlobGasPerBlock / params.BlobTxBlobGasPerBlob; len(tx.blobHashes) > permitted {
return errors.Errorf("too many blobs in transaction: have %d, permitted %d", len(tx.blobHashes), MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)
}
return nil
}
Expand Down Expand Up @@ -192,7 +192,7 @@ func verifySidecar(sidecar *types.BlobTxSidecar, hashes []common.Hash) error {
// Blob commitments match with the hashes in the transaction, verify the
// blobs themselves via KZG
for i := range sidecar.Blobs {
if err := kzg4844.VerifyBlobProof(sidecar.Blobs[i], sidecar.Commitments[i], sidecar.Proofs[i]); err != nil {
if err := kzg4844.VerifyBlobProof(&sidecar.Blobs[i], sidecar.Commitments[i], sidecar.Proofs[i]); err != nil {
return errors.Errorf("invalid blob %d: %v", i, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions action/blob_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ func TestBlobTxData(t *testing.T) {
}

var (
testBlob = kzg4844.Blob{1, 2, 3, 4}
testBlob = &kzg4844.Blob{1, 2, 3, 4}
testBlobCommit = MustNoErrorV(kzg4844.BlobToCommitment(testBlob))
testBlobProof = MustNoErrorV(kzg4844.ComputeBlobProof(testBlob, testBlobCommit))
)

func createTestBlobTxData() *BlobTxData {
sidecar := &types.BlobTxSidecar{
Blobs: []kzg4844.Blob{testBlob},
Blobs: []kzg4844.Blob{*testBlob},
Commitments: []kzg4844.Commitment{testBlobCommit},
Proofs: []kzg4844.Proof{testBlobProof},
}
Expand Down
4 changes: 2 additions & 2 deletions action/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ func TestEthTxUtils(t *testing.T) {
act := NewClaimFromRewardingFund(big.NewInt(1), addr, []byte("any"))
elp := (&EnvelopeBuilder{}).SetNonce(100).SetGasLimit(21000).
SetGasPrice(big.NewInt(101)).SetAction(act).Build()
tx, err := elp.ToEthTx(chainID, iotextypes.Encoding_ETHEREUM_EIP155)
tx, err := elp.ToEthTx()
r.NoError(err)

var (
signer1, _ = NewEthSigner(iotextypes.Encoding_ETHEREUM_EIP155, chainID)
sig1, _ = sk1.Sign(tx.Hash().Bytes())
signer2 = types.NewCancunSigner(big.NewInt(int64(chainID)))
signer2 = types.NewPragueSigner(big.NewInt(int64(chainID)))
sig2, _ = ethercrypto.Sign(tx.Hash().Bytes(), sk2)
)
r.Equal(signer1, signer2)
Expand Down
4 changes: 2 additions & 2 deletions action/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type (
IntrinsicGas() (uint64, error)
Size() uint32
Action() Action
ToEthTx(uint32, iotextypes.Encoding) (*types.Transaction, error)
Proto() *iotextypes.ActionCore
ProtoForHash() *iotextypes.ActionCore
LoadProto(*iotextypes.ActionCore) error
Expand All @@ -44,6 +43,7 @@ type (
Value() *big.Int
To() *common.Address
Data() []byte
ToEthTx() (*types.Transaction, error)
}

TxCommon interface {
Expand Down Expand Up @@ -234,7 +234,7 @@ func (elp *envelope) Size() uint32 {
func (elp *envelope) Action() Action { return elp.payload }

// ToEthTx converts to Ethereum tx
func (elp *envelope) ToEthTx(evmNetworkID uint32, encoding iotextypes.Encoding) (*types.Transaction, error) {
func (elp *envelope) ToEthTx() (*types.Transaction, error) {
tx, ok := elp.Action().(EthCompatibleAction)
if !ok {
// action type not supported
Expand Down
1 change: 1 addition & 0 deletions action/evm_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type (
TxData
SanityCheck() error
Proto() *iotextypes.ActionCore
Action() Action
}
)

Expand Down
9 changes: 9 additions & 0 deletions action/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package action

import "github.com/ethereum/go-ethereum/params"

const (
MaxBlobGasPerBlock = 6 * params.BlobTxBlobGasPerBlob
BlobTxTargetBlobGasPerBlock = 3 * params.BlobTxBlobGasPerBlob
BlobTxBlobGaspriceUpdateFraction = 3338477
)
11 changes: 4 additions & 7 deletions action/protocol/account/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ func StoreAccount(sm protocol.StateManager, addr address.Address, account *state
}

// Recorded tests if an account has been actually stored
func Recorded(sr protocol.StateReader, addr address.Address) (bool, error) {
func Recorded(sr protocol.StateReader, addr address.Address) (*state.Account, error) {
account := &state.Account{}
_, err := sr.State(account, protocol.LegacyKeyOption(hash.BytesToHash160(addr.Bytes())))
switch errors.Cause(err) {
case nil:
return true, nil
case state.ErrStateNotExist:
return false, nil
if err != nil {
return nil, err
}
return false, err
return account, nil
}

// AccountState returns the confirmed account state on the chain
Expand Down
2 changes: 2 additions & 0 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ type (
CandidateSlashByOwner bool
CandidateBLSPublicKeyNotCopied bool
OnlyOwnerCanUpdateBLSPublicKey bool
PrePectraEVM bool
}

// FeatureWithHeightCtx provides feature check functions.
Expand Down Expand Up @@ -335,6 +336,7 @@ func WithFeatureCtx(ctx context.Context) context.Context {
CandidateSlashByOwner: !g.IsXinguBeta(height),
CandidateBLSPublicKeyNotCopied: !g.IsXinguBeta(height),
OnlyOwnerCanUpdateBLSPublicKey: !g.IsToBeEnabled(height),
PrePectraEVM: !g.IsToBeEnabled(height),
},
)
}
Expand Down
13 changes: 9 additions & 4 deletions action/protocol/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/pkg/errors"

"github.com/iotexproject/iotex-core/v2/action"
Expand Down Expand Up @@ -56,8 +55,10 @@ func CalcBaseFee(g genesis.Blockchain, parent *TipInfo) *big.Int {
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(action.DefaultBaseFeeChangeDenominator))
baseFeeDelta := math.BigMax(num, common.Big1)
return num.Add(parent.BaseFee, baseFeeDelta)
if num.Cmp(common.Big1) < 0 {
return num.Add(parent.BaseFee, common.Big1)
}
return num.Add(parent.BaseFee, num)
} else {
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
Expand All @@ -66,6 +67,10 @@ func CalcBaseFee(g genesis.Blockchain, parent *TipInfo) *big.Int {
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(action.DefaultBaseFeeChangeDenominator))
baseFee := num.Sub(parent.BaseFee, num)
return math.BigMax(baseFee, new(big.Int).SetUint64(action.InitialBaseFee))
initBaseFee := new(big.Int).SetUint64(action.InitialBaseFee)
if baseFee.Cmp(initBaseFee) < 0 {
baseFee = initBaseFee
}
return baseFee
}
}
12 changes: 7 additions & 5 deletions action/protocol/eip4844.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/params"

"github.com/iotexproject/iotex-core/v2/action"
)

type (
Expand All @@ -17,16 +19,16 @@ type (

var (
minBlobGasPrice = big.NewInt(params.BlobTxMinBlobGasprice)
blobGaspriceUpdateFraction = big.NewInt(params.BlobTxBlobGaspriceUpdateFraction)
blobGaspriceUpdateFraction = big.NewInt(action.BlobTxBlobGaspriceUpdateFraction)
)

// VerifyEIP4844Header verifies the presence of the excessBlobGas field and that
// if the current block contains no transactions, the excessBlobGas is updated
// accordingly.
func VerifyEIP4844Header(parent *TipInfo, header blockHeader) error {
// Verify that the blob gas used remains within reasonable limits.
if header.BlobGasUsed() > params.MaxBlobGasPerBlock {
return fmt.Errorf("blob gas used %d exceeds maximum allowance %d", header.BlobGasUsed(), params.MaxBlobGasPerBlock)
if header.BlobGasUsed() > action.MaxBlobGasPerBlock {
return fmt.Errorf("blob gas used %d exceeds maximum allowance %d", header.BlobGasUsed(), action.MaxBlobGasPerBlock)
}
if header.BlobGasUsed()%params.BlobTxBlobGasPerBlob != 0 {
return fmt.Errorf("blob gas used %d not a multiple of blob gas per blob %d", header.BlobGasUsed(), params.BlobTxBlobGasPerBlob)
Expand All @@ -48,10 +50,10 @@ func VerifyEIP4844Header(parent *TipInfo, header blockHeader) error {
// blobs on top of the excess blob gas.
func CalcExcessBlobGas(parentExcessBlobGas uint64, parentBlobGasUsed uint64) uint64 {
excessBlobGas := parentExcessBlobGas + parentBlobGasUsed
if excessBlobGas < params.BlobTxTargetBlobGasPerBlock {
if excessBlobGas < action.BlobTxTargetBlobGasPerBlock {
return 0
}
return excessBlobGas - params.BlobTxTargetBlobGasPerBlock
return excessBlobGas - action.BlobTxTargetBlobGasPerBlock
}

// CalcBlobFee calculates the blobfee from the header's excess blob gas field.
Expand Down
21 changes: 10 additions & 11 deletions action/protocol/eip4844_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"

"github.com/iotexproject/iotex-core/v2/action"
)

func TestCalcExcessBlobGas(t *testing.T) {
Expand All @@ -20,20 +22,20 @@ func TestCalcExcessBlobGas(t *testing.T) {
// slots are below - or equal - to the target.
{0, 0, 0},
{0, 1, 0},
{0, params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob, 0},
{0, action.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob, 0},

// If the target blob gas is exceeded, the excessBlobGas should increase
// by however much it was overshot
{0, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 1, params.BlobTxBlobGasPerBlob},
{1, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 1, params.BlobTxBlobGasPerBlob + 1},
{1, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 2, 2*params.BlobTxBlobGasPerBlob + 1},
{0, (action.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 1, params.BlobTxBlobGasPerBlob},
{1, (action.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 1, params.BlobTxBlobGasPerBlob + 1},
{1, (action.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 2, 2*params.BlobTxBlobGasPerBlob + 1},

// The excess blob gas should decrease by however much the target was
// under-shot, capped at zero.
{params.BlobTxTargetBlobGasPerBlock, params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob, params.BlobTxTargetBlobGasPerBlock},
{params.BlobTxTargetBlobGasPerBlock, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 1, params.BlobTxTargetBlobGasPerBlock - params.BlobTxBlobGasPerBlob},
{params.BlobTxTargetBlobGasPerBlock, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 2, params.BlobTxTargetBlobGasPerBlock - (2 * params.BlobTxBlobGasPerBlob)},
{params.BlobTxBlobGasPerBlob - 1, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 1, 0},
{action.BlobTxTargetBlobGasPerBlock, action.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob, action.BlobTxTargetBlobGasPerBlock},
{action.BlobTxTargetBlobGasPerBlock, (action.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 1, action.BlobTxTargetBlobGasPerBlock - params.BlobTxBlobGasPerBlob},
{action.BlobTxTargetBlobGasPerBlock, (action.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 2, action.BlobTxTargetBlobGasPerBlock - (2 * params.BlobTxBlobGasPerBlob)},
{params.BlobTxBlobGasPerBlob - 1, (action.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 1, 0},
}
for i, tt := range tests {
result := CalcExcessBlobGas(tt.excess, tt.blobs*params.BlobTxBlobGasPerBlob)
Expand Down Expand Up @@ -96,10 +98,7 @@ func TestFakeExponential(t *testing.T) {
func TestEIP4844Params(t *testing.T) {
require := require.New(t)
require.Equal(1<<17, params.BlobTxBlobGasPerBlob)
require.Equal(3*params.BlobTxBlobGasPerBlob, params.BlobTxTargetBlobGasPerBlock)
require.Equal(6*params.BlobTxBlobGasPerBlob, params.MaxBlobGasPerBlock)
require.Equal(1, params.BlobTxMinBlobGasprice)
require.Equal(3338477, params.BlobTxBlobGaspriceUpdateFraction)
require.Equal(4096, params.BlobTxFieldElementsPerBlob)
require.Equal(32, params.BlobTxBytesPerFieldElement)
}
Loading