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

Can provide a demo for building an eth tx and sign it then send to endpoint? #296

Open
Eric0718 opened this issue May 10, 2024 · 5 comments

Comments

@Eric0718
Copy link

I'm a little confused, how to construct an eth transaction and sign it with tss signing, and finally send it to the target blockchain.

@Eric0718
Copy link
Author

func rebuildSignature(unsignedTx *types.Transaction, siger types.EIP155Signer, sigData *MPCSignatureData) (*types.Transaction, error) {
mpcSignature, err := hex.DecodeString(sigData.Signature)
if err != nil {
return nil, err
}
if len(mpcSignature) != 64 {
return nil, errors.New("signature length not 64!")
}

//does recid use 0 or 1 ??
var recid int64 = 0
V := byte(big.NewInt(recid).Uint64())
mpcSignature = append(mpcSignature, V)
return unsignedTx.WithSignature(siger, mpcSignature)

}

//I'm trying to reconstruct an eth signature using MPC signatureData without the V , can anyone tell me if this is correct? And does recid choose 0 or 1?

@tuanna7593
Copy link

tuanna7593 commented Jun 5, 2024

You can reconstruct signature by combine Signature and SignatureRecovery from SignatureData that you got from the endCh channel.

https://github.com/bnb-chain/tss-lib/blob/master/common/signature.pb.go#L36-L38

signatureData <- endCh
signature := append(signatureData.GetSignature(), signatureData.GetSignatureRecovery()...)
unsignedTx.WithSignature(siger, signature)

@huantt
Copy link

huantt commented Jun 26, 2024

You can follow this sample:

https://github.com/IBM/TSS/tree/main/mpc/binance/ecdsa

@anggapur
Copy link

anggapur commented Aug 6, 2024

Hi, I'm getting failed when trying to sign a constructed transaction.
Is there any particular way to construct transaction that will be signed?

@anggapur
Copy link

anggapur commented Aug 9, 2024

https://github.com/bnb-chain/tss-lib/blob/master/common/signature.pb.go#L36-L38

Hi, I try to reconstruct the signature this way along with the transaction. But when I do ecrecover, the address is always different on every attempt of signing while the transaction data still the same.
Here my code

addr := common.HexToAddress("0x000000000000000000000000000000000000aaaa")
tx := types.NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil)

... Signing process,  got the signature 

// Recover the address from the signed transaction
signer := types.NewEIP155Signer(big.NewInt(18))
dataWithSignature, err := tx.WithSignature(signer, signature)
recoveredAddress, err := types.Sender(signer, dataWithSignature)
if err != nil {
log.Fatalf("Failed to recover address from transaction: %v", err)
}

fmt.Printf("Recovered Address: %s\n", recoveredAddress.Hex())

On this case, the recovered address alwayd produce different address.
Is there something wrong on my code?

@tuanna7593 @huantt @Eric0718

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants