From f9c4e94e009c7e0ff231ad560ce3df14ea41fd7f Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 10 May 2024 12:09:59 +0300 Subject: [PATCH 1/3] debug: prints in transaction --- core/types/transaction_signing.go | 2 ++ ethclient/signer.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index b3850d643f14..872b638948bc 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -129,6 +129,7 @@ func MustSignNewTx(prv *ecdsa.PrivateKey, s Signer, txdata TxData) *Transaction // signing method. The cache is invalidated if the cached signer does // not match the signer used in the current call. func Sender(signer Signer, tx *Transaction) (common.Address, error) { + fmt.Println("signer", signer) if sc := tx.from.Load(); sc != nil { sigCache := sc.(sigCache) // If the signer used to derive from in a previous @@ -140,6 +141,7 @@ func Sender(signer Signer, tx *Transaction) (common.Address, error) { } addr, err := signer.Sender(tx) + fmt.Println("addr", addr, "err", err) if err != nil { return common.Address{}, err } diff --git a/ethclient/signer.go b/ethclient/signer.go index d74d135bf308..44775015a446 100644 --- a/ethclient/signer.go +++ b/ethclient/signer.go @@ -25,7 +25,7 @@ import ( ) // senderFromServer is a types.Signer that remembers the sender address returned by the RPC -// server. It is stored in the transaction's sender address cache to avoid an additional +// server. It is stored goin the transaction's sender address cache to avoid an additional // request in TransactionSender. type senderFromServer struct { addr common.Address From e8ed71aa69422523efe30b0bd52b3549a06e4b29 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 3 Jun 2024 12:01:26 +0300 Subject: [PATCH 2/3] WIP --- core/types/callback_signer.go | 44 +++++++++++++++++++++++++++++++ core/types/transaction_signing.go | 4 ++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 core/types/callback_signer.go diff --git a/core/types/callback_signer.go b/core/types/callback_signer.go new file mode 100644 index 000000000000..4e45ef1d9190 --- /dev/null +++ b/core/types/callback_signer.go @@ -0,0 +1,44 @@ +package types + +import ( + "fmt" + "github.com/ethereum/go-ethereum/common" + "math/big" +) + +var _ Signer = callbackSigner{} + +type callbackSigner struct { + chainID *big.Int + relayerAddress common.Address +} + +func NewCallbackSigner(chainID *big.Int, relayerAddress common.Address) Signer { + return callbackSigner{chainID: chainID, relayerAddress: relayerAddress} +} + +func (c callbackSigner) Sender(tx *Transaction) (common.Address, error) { + if c.relayerAddress == (common.Address{}) { + return common.Address{}, fmt.Errorf("relayer address not set") + } + return c.relayerAddress, nil +} + +func (c callbackSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error) { + // TODO: Return dummy values for now + return new(big.Int), new(big.Int), new(big.Int), nil +} + +func (c callbackSigner) ChainID() *big.Int { + return c.chainID +} + +func (c callbackSigner) Hash(tx *Transaction) common.Hash { + // Assume a simple RLP hash of the transaction is sufficient + return rlpHash([]interface{}{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data()}) +} + +func (c callbackSigner) Equal(signer Signer) bool { + _, ok := signer.(callbackSigner) + return ok +} diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 872b638948bc..c22b8719bebc 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -37,9 +37,11 @@ type sigCache struct { } // MakeSigner returns a Signer based on the given chain config and block number. -func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer { +func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, senderAddr common.Address) Signer { var signer Signer switch { + case senderAddr != (common.Address{}): + signer = NewCallbackSigner(config.ChainID, senderAddr) case config.IsLondon(blockNumber): signer = NewLondonSigner(config.ChainID) case config.IsBerlin(blockNumber): From 1f0a787161fd68230f425608ed7ebaf30824e477 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 3 Jun 2024 12:04:46 +0300 Subject: [PATCH 3/3] fix: typos --- core/types/transaction_signing.go | 2 -- ethclient/signer.go | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index c22b8719bebc..ad3301a3b1ec 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -131,7 +131,6 @@ func MustSignNewTx(prv *ecdsa.PrivateKey, s Signer, txdata TxData) *Transaction // signing method. The cache is invalidated if the cached signer does // not match the signer used in the current call. func Sender(signer Signer, tx *Transaction) (common.Address, error) { - fmt.Println("signer", signer) if sc := tx.from.Load(); sc != nil { sigCache := sc.(sigCache) // If the signer used to derive from in a previous @@ -143,7 +142,6 @@ func Sender(signer Signer, tx *Transaction) (common.Address, error) { } addr, err := signer.Sender(tx) - fmt.Println("addr", addr, "err", err) if err != nil { return common.Address{}, err } diff --git a/ethclient/signer.go b/ethclient/signer.go index 44775015a446..d74d135bf308 100644 --- a/ethclient/signer.go +++ b/ethclient/signer.go @@ -25,7 +25,7 @@ import ( ) // senderFromServer is a types.Signer that remembers the sender address returned by the RPC -// server. It is stored goin the transaction's sender address cache to avoid an additional +// server. It is stored in the transaction's sender address cache to avoid an additional // request in TransactionSender. type senderFromServer struct { addr common.Address