add support for f4 addresses in the Eth JSON-RPC and signature.
This commit is contained in:
parent
17e9e97064
commit
98e534cc77
@ -109,6 +109,9 @@ func (tx *EthTxArgs) ToSignedMessage() (*types.SignedMessage, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if tx.To == nil {
|
if tx.To == nil {
|
||||||
|
// TODO https://github.com/filecoin-project/ref-fvm/issues/992
|
||||||
|
// TODO unify with applyEvmMsg
|
||||||
|
|
||||||
// this is a contract creation
|
// this is a contract creation
|
||||||
to = builtintypes.InitActorAddr
|
to = builtintypes.InitActorAddr
|
||||||
|
|
||||||
@ -263,7 +266,12 @@ func (tx *EthTxArgs) Sender() (address.Address, error) {
|
|||||||
return address.Undef, err
|
return address.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return address.NewSecp256k1Address(pubk)
|
// Calculate the f4 address based on the keccak hash of the pubkey.
|
||||||
|
hasher.Reset()
|
||||||
|
hasher.Write(pubk)
|
||||||
|
addrHash := hasher.Sum(nil)
|
||||||
|
|
||||||
|
return address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, addrHash[len(addrHash)-20:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseEip1559Tx(data []byte) (*EthTxArgs, error) {
|
func parseEip1559Tx(data []byte) (*EthTxArgs, error) {
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/builtin"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/multiformats/go-multihash"
|
"github.com/multiformats/go-multihash"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
@ -23,9 +24,6 @@ import (
|
|||||||
|
|
||||||
type EthUint64 uint64
|
type EthUint64 uint64
|
||||||
|
|
||||||
// EthAddressManagerActorID is the actor ID of the Ethereum Address Manager singleton.
|
|
||||||
const EthAddressManagerActorID = 10
|
|
||||||
|
|
||||||
func (e EthUint64) MarshalJSON() ([]byte, error) {
|
func (e EthUint64) MarshalJSON() ([]byte, error) {
|
||||||
if e == 0 {
|
if e == 0 {
|
||||||
return json.Marshal("0x0")
|
return json.Marshal("0x0")
|
||||||
@ -294,7 +292,7 @@ func (ea EthAddress) ToFilecoinAddress() (address.Address, error) {
|
|||||||
|
|
||||||
// Otherwise, translate the address into an address controlled by the
|
// Otherwise, translate the address into an address controlled by the
|
||||||
// Ethereum Address Manager.
|
// Ethereum Address Manager.
|
||||||
addr, err := address.NewDelegatedAddress(EthAddressManagerActorID, ea[:])
|
addr, err := address.NewDelegatedAddress(builtin.EthereumAddressManagerActorID, ea[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return address.Undef, fmt.Errorf("failed to translate supplied address (%s) into a "+
|
return address.Undef, fmt.Errorf("failed to translate supplied address (%s) into a "+
|
||||||
"Filecoin f4 address: %w", hex.EncodeToString(ea[:]), err)
|
"Filecoin f4 address: %w", hex.EncodeToString(ea[:]), err)
|
||||||
|
2
go.sum
2
go.sum
@ -351,6 +351,8 @@ github.com/filecoin-project/go-state-types v0.1.11-0.20220923222823-af1291888ee8
|
|||||||
github.com/filecoin-project/go-state-types v0.1.11-0.20220923222823-af1291888ee8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
|
github.com/filecoin-project/go-state-types v0.1.11-0.20220923222823-af1291888ee8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
|
||||||
github.com/filecoin-project/go-state-types v0.1.11-0.20220929211033-a2339f216f21 h1:9asw8iXwZES+/kULEPCmbcmE95QVfE/5BIuYsbFMQZc=
|
github.com/filecoin-project/go-state-types v0.1.11-0.20220929211033-a2339f216f21 h1:9asw8iXwZES+/kULEPCmbcmE95QVfE/5BIuYsbFMQZc=
|
||||||
github.com/filecoin-project/go-state-types v0.1.11-0.20220929211033-a2339f216f21/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
|
github.com/filecoin-project/go-state-types v0.1.11-0.20220929211033-a2339f216f21/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
|
||||||
|
github.com/filecoin-project/go-state-types v0.1.11-0.20221020121916-001de75ef54e h1:Bl8982sk/ZAfoPNszIddnqjfezOJmvyiuzjMR+YhqOY=
|
||||||
|
github.com/filecoin-project/go-state-types v0.1.11-0.20221020121916-001de75ef54e/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
|
||||||
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
|
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
|
||||||
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
|
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
|
||||||
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
|
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
|
||||||
|
@ -3,6 +3,7 @@ package delegated
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/builtin"
|
||||||
"golang.org/x/crypto/sha3"
|
"golang.org/x/crypto/sha3"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -40,7 +41,11 @@ func (delegatedSigner) Verify(sig []byte, a address.Address, msg []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeaddr, err := address.NewSecp256k1Address(pubk)
|
hasher.Reset()
|
||||||
|
hasher.Write(pubk)
|
||||||
|
addrHash := hasher.Sum(nil)
|
||||||
|
|
||||||
|
maybeaddr, err := address.NewDelegatedAddress(builtin.EthereumAddressManagerActorID, addrHash[len(addrHash)-20:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
builtinactors "github.com/filecoin-project/lotus/chain/actors/builtin"
|
|
||||||
"github.com/filecoin-project/lotus/chain/messagepool"
|
"github.com/filecoin-project/lotus/chain/messagepool"
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
@ -433,39 +432,20 @@ func (a *EthModule) EthSendRawTransaction(ctx context.Context, rawTx api.EthByte
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *EthModule) applyEvmMsg(ctx context.Context, tx api.EthCall) (*api.InvocResult, error) {
|
func (a *EthModule) applyEvmMsg(ctx context.Context, tx api.EthCall) (*api.InvocResult, error) {
|
||||||
// FIXME: this is a workaround, remove this when f4 address is ready
|
// The from address must be translatable to an f4 address.
|
||||||
var from address.Address
|
from, err := tx.From.ToFilecoinAddress()
|
||||||
var err error
|
if err != nil {
|
||||||
if tx.From[0] == 0xff && tx.From[1] == 0 && tx.From[2] == 0 {
|
return nil, fmt.Errorf("failed to translate sender address (%s): %w", tx.From.String(), err)
|
||||||
addr, err := tx.From.ToFilecoinAddress()
|
}
|
||||||
if err != nil {
|
if p := from.Protocol(); p != address.Delegated {
|
||||||
return nil, err
|
return nil, fmt.Errorf("expected a class 4 address, got: %d: %w", p, err)
|
||||||
}
|
|
||||||
from = addr
|
|
||||||
} else {
|
|
||||||
id := uint64(100)
|
|
||||||
for ; id < 300; id++ {
|
|
||||||
idAddr, err := address.NewIDAddress(id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
from = idAddr
|
|
||||||
act, err := a.StateGetActor(ctx, idAddr, types.EmptyTSK)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if builtinactors.IsAccountActor(act.Code) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if id == 300 {
|
|
||||||
return nil, fmt.Errorf("cannot find a dummy account")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var params []byte
|
var params []byte
|
||||||
var to address.Address
|
var to address.Address
|
||||||
if tx.To == nil {
|
if tx.To == nil {
|
||||||
|
// TODO need to construct the actor through the EAM so that it acquires an f4 address.
|
||||||
|
// https://github.com/filecoin-project/ref-fvm/issues/992
|
||||||
to = builtintypes.InitActorAddr
|
to = builtintypes.InitActorAddr
|
||||||
constructorParams, err := actors.SerializeParams(&evm.ConstructorParams{
|
constructorParams, err := actors.SerializeParams(&evm.ConstructorParams{
|
||||||
Bytecode: tx.Data,
|
Bytecode: tx.Data,
|
||||||
@ -543,7 +523,7 @@ func (a *EthModule) EthCall(ctx context.Context, tx api.EthCall, blkParam string
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(invokeResult.MsgRct.Return) > 0 {
|
if len(invokeResult.MsgRct.Return) > 0 {
|
||||||
return api.EthBytes(invokeResult.MsgRct.Return), nil
|
return invokeResult.MsgRct.Return, nil
|
||||||
}
|
}
|
||||||
return api.EthBytes{}, nil
|
return api.EthBytes{}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user