Skip to content

Commit

Permalink
Merge pull request #5455 from onflow/ramtin/port-of-5454
Browse files Browse the repository at this point in the history
[Flow EVM] - fix empty tx hash bug for some transactions
  • Loading branch information
sideninja authored Feb 26, 2024
2 parents b295bd5 + c77d2a1 commit 0776bdc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
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

0 comments on commit 0776bdc

Please sign in to comment.