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

[Flow EVM] - fix empty tx hash bug for some transactions #5455

Merged
merged 1 commit into from
Feb 26, 2024
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
fix tx hash issue for direct calls
  • Loading branch information
ramtinms committed Feb 24, 2024
commit c77d2a11bfde996d057842123c3be807964bd58b
22 changes: 17 additions & 5 deletions fvm/evm/emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ func (bl *BlockView) DirectCall(call *types.DirectCall) (*types.Result, error) {
}
switch call.SubType {
case types.DepositCallSubType:
return proc.mintTo(call.To, call.Value)
return proc.mintTo(call.To, call.Value, txHash)
case types.WithdrawCallSubType:
return proc.withdrawFrom(call.From, call.Value)
return proc.withdrawFrom(call.From, call.Value, txHash)
case types.DeployCallSubType:
if !call.EmptyToField() {
return proc.deployAt(call.From, call.To, call.Data, call.GasLimit, call.Value)
return proc.deployAt(call.From, call.To, call.Data, call.GasLimit, call.Value, txHash)
}
fallthrough
default:
Expand Down Expand Up @@ -199,11 +199,16 @@ func (proc *procedure) commit() error {
return nil
}

func (proc *procedure) mintTo(address types.Address, amount *big.Int) (*types.Result, error) {
func (proc *procedure) mintTo(
address types.Address,
amount *big.Int,
txHash gethCommon.Hash,
) (*types.Result, error) {
addr := address.ToCommon()
res := &types.Result{
GasConsumed: proc.config.DirectCallBaseGasUsage,
TxType: types.DirectCallTxType,
TxHash: txHash,
}

// create account if not exist
Expand All @@ -218,12 +223,17 @@ func (proc *procedure) mintTo(address types.Address, amount *big.Int) (*types.Re
return res, proc.commit()
}

func (proc *procedure) withdrawFrom(address types.Address, amount *big.Int) (*types.Result, error) {
func (proc *procedure) withdrawFrom(
address types.Address,
amount *big.Int,
txHash gethCommon.Hash,
) (*types.Result, error) {

addr := address.ToCommon()
res := &types.Result{
GasConsumed: proc.config.DirectCallBaseGasUsage,
TxType: types.DirectCallTxType,
TxHash: txHash,
}

// check if account exists
Expand Down Expand Up @@ -264,13 +274,15 @@ func (proc *procedure) deployAt(
data types.Code,
gasLimit uint64,
value *big.Int,
txHash gethCommon.Hash,
) (*types.Result, error) {
if value.Sign() < 0 {
return nil, types.ErrInvalidBalance
}

res := &types.Result{
TxType: types.DirectCallTxType,
TxHash: txHash,
}
addr := to.ToCommon()

Expand Down
10 changes: 10 additions & 0 deletions fvm/evm/types/call.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"fmt"
"math/big"

gethCommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -47,6 +48,15 @@ type DirectCall struct {
Nonce uint64
}

// DirectCallFromEncoded constructs a DirectCall from encoded data
func DirectCallFromEncoded(encoded []byte) (*DirectCall, error) {
if encoded[0] != DirectCallTxType {
return nil, fmt.Errorf("tx type mismatch")
}
dc := &DirectCall{}
return dc, rlp.DecodeBytes(encoded[1:], dc)
}

// Encode encodes the direct call it also adds the type
// as the very first byte, similar to how evm encodes types.
func (dc *DirectCall) Encode() ([]byte, error) {
Expand Down
Loading