Skip to content

Commit

Permalink
respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeepdino008 committed Jul 1, 2024
1 parent 0173b95 commit ff7ca94
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 172 deletions.
113 changes: 36 additions & 77 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,132 +392,91 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) {
var chainId *uint256.Int

if txJson.Value != nil {
value, overflow = uint256.FromBig((*big.Int)(txJson.Value))
value, overflow = uint256.FromBig(txJson.Value.ToInt())
if overflow {
return nil, fmt.Errorf("value field caused an overflow (uint256)")
}
}

if txJson.GasPrice != nil {
gasPrice, overflow = uint256.FromBig((*big.Int)(txJson.GasPrice))
gasPrice, overflow = uint256.FromBig(txJson.GasPrice.ToInt())
if overflow {
return nil, fmt.Errorf("gasPrice field caused an overflow (uint256)")
}
}

if txJson.ChainID != nil {
chainId, overflow = uint256.FromBig((*big.Int)(txJson.ChainID))
chainId, overflow = uint256.FromBig(txJson.ChainID.ToInt())
if overflow {
return nil, fmt.Errorf("chainId field caused an overflow (uint256)")
}
}

switch txJson.Type {
case types.LegacyTxType, types.AccessListTxType:
var toAddr = libcommon.Address{}
if txJson.To != nil {
toAddr = *txJson.To
}
legacyTx := types.NewTransaction(uint64(txJson.Nonce), toAddr, value, uint64(txJson.Gas), gasPrice, txJson.Input)
legacyTx.V.SetFromBig(txJson.V.ToInt())
legacyTx.S.SetFromBig(txJson.S.ToInt())
legacyTx.R.SetFromBig(txJson.R.ToInt())
commonTx := types.CommonTx{
Nonce: uint64(txJson.Nonce),
To: txJson.To,
Value: value,
Gas: uint64(txJson.Gas),
Data: txJson.Input,
}

if txJson.Type == types.AccessListTxType {
accessListTx := types.AccessListTx{
LegacyTx: *legacyTx,
ChainID: chainId,
AccessList: *txJson.Accesses,
}
commonTx.V.SetFromBig(txJson.V.ToInt())
commonTx.R.SetFromBig(txJson.R.ToInt())
commonTx.S.SetFromBig(txJson.S.ToInt())
if txJson.Type == types.LegacyTxType || txJson.Type == types.AccessListTxType {
legacyTx := types.LegacyTx{
CommonTx: commonTx,
GasPrice: gasPrice,
}

return &accessListTx, nil
} else {
return legacyTx, nil
if txJson.Type == types.LegacyTxType {
return &legacyTx, nil
}

case types.DynamicFeeTxType:
return &types.AccessListTx{
LegacyTx: legacyTx,
ChainID: chainId,
AccessList: *txJson.Accesses,
}, nil
} else if txJson.Type == types.DynamicFeeTxType || txJson.Type == types.SetCodeTxType {
var tip *uint256.Int
var feeCap *uint256.Int
if txJson.Tip != nil {
tip, overflow = uint256.FromBig((*big.Int)(txJson.Tip))
tip, overflow = uint256.FromBig(txJson.Tip.ToInt())
if overflow {
return nil, fmt.Errorf("maxPriorityFeePerGas field caused an overflow (uint256)")
}
}

if txJson.FeeCap != nil {
feeCap, overflow = uint256.FromBig((*big.Int)(txJson.FeeCap))
feeCap, overflow = uint256.FromBig(txJson.FeeCap.ToInt())
if overflow {
return nil, fmt.Errorf("maxFeePerGas field caused an overflow (uint256)")
}
}

dynamicFeeTx := types.DynamicFeeTransaction{
CommonTx: types.CommonTx{
Nonce: uint64(txJson.Nonce),
To: txJson.To,
Value: value,
Gas: uint64(txJson.Gas),
Data: txJson.Input,
},
CommonTx: commonTx,
ChainID: chainId,
Tip: tip,
FeeCap: feeCap,
AccessList: *txJson.Accesses,
}

dynamicFeeTx.V.SetFromBig(txJson.V.ToInt())
dynamicFeeTx.S.SetFromBig(txJson.S.ToInt())
dynamicFeeTx.R.SetFromBig(txJson.R.ToInt())

return &dynamicFeeTx, nil

case types.SetCodeTxType:
var tip *uint256.Int
var feeCap *uint256.Int
if txJson.Tip != nil {
tip, overflow = uint256.FromBig((*big.Int)(txJson.Tip))
if overflow {
return nil, fmt.Errorf("maxPriorityFeePerGas field caused an overflow (uint256)")
}
}

if txJson.FeeCap != nil {
feeCap, overflow = uint256.FromBig((*big.Int)(txJson.FeeCap))
if overflow {
return nil, fmt.Errorf("maxFeePerGas field caused an overflow (uint256)")
}
if txJson.Type == types.DynamicFeeTxType {
return &dynamicFeeTx, nil
}

auths := make([]types.Authorization, 0)
for _, auth := range *txJson.Authorizations {
auths = append(auths, auth.ToAuthorization())
}

setCodeTx := types.SetCodeTransaction{
DynamicFeeTransaction: types.DynamicFeeTransaction{
CommonTx: types.CommonTx{
Nonce: uint64(txJson.Nonce),
To: txJson.To,
Value: value,
Gas: uint64(txJson.Gas),
Data: txJson.Input,
},
ChainID: chainId,
Tip: tip,
FeeCap: feeCap,
AccessList: *txJson.Accesses,
},
Authorizations: auths,
}

setCodeTx.V.SetFromBig(txJson.V.ToInt())
setCodeTx.S.SetFromBig(txJson.S.ToInt())
setCodeTx.R.SetFromBig(txJson.R.ToInt())

return &setCodeTx, nil

default:
return &types.SetCodeTransaction{
DynamicFeeTransaction: dynamicFeeTx,
Authorizations: auths,
}, nil
} else {
return nil, nil
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type Message interface {
}

// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
// TODO: convert the input to a struct
func IntrinsicGas(data []byte, accessList types2.AccessList, isContractCreation bool, isHomestead, isEIP2028, isEIP3860 bool, authorizationsLen uint64) (uint64, error) {
// Zero and non-zero bytes are priced differently
dataLen := uint64(len(data))
Expand Down Expand Up @@ -383,7 +384,7 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*evmtype
defer st.state.SetCode(authority, nil) // reset code after execution

// 6. add authority account to accesses_addresses
if !accessTuples.IsPresent(authority) {
if !accessTuples.HasAddr(authority) {
accessTuples = append(accessTuples, types2.AccessTuple{Address: authority, StorageKeys: nil})
}

Expand Down
4 changes: 2 additions & 2 deletions core/types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ func (tx *AccessListTx) WithSignature(signer Signer, sig []byte) (Transaction, e
cpy.ChainID = signer.ChainID()
return cpy, nil
}
func (tx *AccessListTx) FakeSign(address libcommon.Address) (Transaction, error) {
func (tx *AccessListTx) FakeSign(address libcommon.Address) Transaction {
cpy := tx.copy()
cpy.R.Set(u256.Num1)
cpy.S.Set(u256.Num1)
cpy.V.Set(u256.Num4)
cpy.from.Store(address)
return cpy, nil
return cpy
}

// Hash computes the hash (but not for signatures!)
Expand Down
2 changes: 1 addition & 1 deletion core/types/blob_tx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (txw *BlobTxWrapper) WithSignature(signer Signer, sig []byte) (Transaction,
return txw.Tx.WithSignature(signer, sig)
}

func (txw *BlobTxWrapper) FakeSign(address libcommon.Address) (Transaction, error) {
func (txw *BlobTxWrapper) FakeSign(address libcommon.Address) Transaction {
return txw.Tx.FakeSign(address)
}

Expand Down
8 changes: 4 additions & 4 deletions core/types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ func (tx *DynamicFeeTransaction) WithSignature(signer Signer, sig []byte) (Trans
return cpy, nil
}

func (tx *DynamicFeeTransaction) FakeSign(address libcommon.Address) (Transaction, error) {
func (tx *DynamicFeeTransaction) FakeSign(address libcommon.Address) Transaction {
cpy := tx.copy()
cpy.R.Set(u256.Num1)
cpy.S.Set(u256.Num1)
cpy.V.Set(u256.Num4)
cpy.from.Store(address)
return cpy, nil
return cpy
}

// MarshalBinary returns the canonical encoding of the transaction.
Expand Down Expand Up @@ -256,10 +256,10 @@ func (tx *DynamicFeeTransaction) encodePayload(w io.Writer, b []byte, payloadSiz
func (tx *DynamicFeeTransaction) EncodeRLP(w io.Writer) error {
payloadSize, nonceLen, gasLen, accessListLen := tx.payloadSize()
// size of struct prefix and TxType
envelopSize := 1 + rlp2.ListPrefixLen(payloadSize) + payloadSize
envelopeSize := 1 + rlp2.ListPrefixLen(payloadSize) + payloadSize
var b [33]byte
// envelope
if err := rlp.EncodeStringSizePrefix(envelopSize, w, b[:]); err != nil {
if err := rlp.EncodeStringSizePrefix(envelopeSize, w, b[:]); err != nil {
return err
}
// encode TxType
Expand Down
4 changes: 2 additions & 2 deletions core/types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ func (tx *LegacyTx) WithSignature(signer Signer, sig []byte) (Transaction, error
return cpy, nil
}

func (tx *LegacyTx) FakeSign(address libcommon.Address) (Transaction, error) {
func (tx *LegacyTx) FakeSign(address libcommon.Address) Transaction {
cpy := tx.copy()
cpy.R.Set(u256.Num1)
cpy.S.Set(u256.Num1)
cpy.V.Set(u256.Num4)
cpy.from.Store(address)
return cpy, nil
return cpy
}

// Hash computes the hash (but not for signatures!)
Expand Down
4 changes: 2 additions & 2 deletions core/types/set_code_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func (tx *SetCodeTransaction) WithSignature(signer Signer, sig []byte) (Transact
return cpy, nil
}

func (tx *SetCodeTransaction) FakeSign(address libcommon.Address) (Transaction, error) {
func (tx *SetCodeTransaction) FakeSign(address libcommon.Address) Transaction {
cpy := tx.copy()
cpy.R.Set(u256.Num1)
cpy.S.Set(u256.Num1)
cpy.V.Set(u256.Num4)
cpy.from.Store(address)
return cpy, nil
return cpy
}

func (tx *SetCodeTransaction) MarshalBinary(w io.Writer) error {
Expand Down
4 changes: 2 additions & 2 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Transaction interface {
GetAuthorizations() []Authorization
AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Message, error)
WithSignature(signer Signer, sig []byte) (Transaction, error)
FakeSign(address libcommon.Address) (Transaction, error)
FakeSign(address libcommon.Address) Transaction
Hash() libcommon.Hash
SigningHash(chainID *big.Int) libcommon.Hash
GetData() []byte
Expand Down Expand Up @@ -496,4 +496,4 @@ func DecodeSSZ(data []byte, dest codec.Deserializable) error {

func EncodeSSZ(w io.Writer, obj codec.Serializable) error {
return obj.Serialize(codec.NewEncodingWriter(w))
}
}
1 change: 1 addition & 0 deletions erigon-lib/txpool/txpoolcfg/txpoolcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (r DiscardReason) String() string {
}

// CalcIntrinsicGas computes the 'intrinsic gas' for a message with the given data.
// TODO: move input data to a struct
func CalcIntrinsicGas(dataLen, dataNonZeroLen, authorizationsLen uint64, accessList types.AccessList, isContractCreation, isHomestead, isEIP2028, isShanghai bool) (uint64, DiscardReason) {
// Set the starting gas for the raw transaction
var gas uint64
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/types/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ func (al AccessList) StorageKeys() int {
return sum
}

func (al AccessList) IsPresent(addr common.Address) bool {
func (al AccessList) HasAddr(addr common.Address) bool {
for _, tuple := range al {
if tuple.Address == addr {
return true
Expand Down
Loading

0 comments on commit ff7ca94

Please sign in to comment.