fix: eth: correctly convert filecoin message <-> eth txn (#10257)

1. We do allow deploying with empty initcode.
2. Make sure that the encoded "code" is non-empty, if specified.

Basically, this makes everything consistent (and it's how I specified it
in the FIP).
This commit is contained in:
Steven Allen
2023-02-13 10:33:59 -08:00
committed by GitHub
parent 03fd703db5
commit f427c2b566
2 changed files with 39 additions and 57 deletions
+9 -16
View File
@@ -751,18 +751,20 @@ func (a *EthModule) ethCallToFilecoinMessage(ctx context.Context, tx ethtypes.Et
}
var params []byte
if len(tx.Data) > 0 {
initcode := abi.CborBytes(tx.Data)
params2, err := actors.SerializeParams(&initcode)
if err != nil {
return nil, fmt.Errorf("failed to serialize params: %w", err)
}
params = params2
}
var to address.Address
var method abi.MethodNum
if tx.To == nil {
// this is a contract creation
to = builtintypes.EthereumAddressManagerActorAddr
initcode := abi.CborBytes(tx.Data)
params2, err := actors.SerializeParams(&initcode)
if err != nil {
return nil, fmt.Errorf("failed to serialize Create params: %w", err)
}
params = params2
method = builtintypes.MethodsEAM.CreateExternal
} else {
addr, err := tx.To.ToFilecoinAddress()
@@ -770,15 +772,6 @@ func (a *EthModule) ethCallToFilecoinMessage(ctx context.Context, tx ethtypes.Et
return nil, xerrors.Errorf("cannot get Filecoin address: %w", err)
}
to = addr
if len(tx.Data) > 0 {
var buf bytes.Buffer
if err := cbg.WriteByteArray(&buf, tx.Data); err != nil {
return nil, fmt.Errorf("failed to encode tx input into a cbor byte-string")
}
params = buf.Bytes()
}
method = builtintypes.MethodsEVM.InvokeContract
}