diff --git a/core/types/suave_structs.go b/core/types/suave_structs.go index 606bb30b76..250af51a2c 100755 --- a/core/types/suave_structs.go +++ b/core/types/suave_structs.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: 5f7dc4aaca73e07546a16000edda8fa3b804777ed38fea2121bc0e09b889103e +// Hash: 23a6dd8b9b224b11b8baea19a80c55c7787c50c0eb2fc69727e66d615c913483 package types import "github.com/ethereum/go-ethereum/common" diff --git a/core/vm/contracts.go b/core/vm/contracts.go index abdf49cd64..9f8d7a9623 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -98,6 +98,7 @@ var PrecompiledContractsSuave = map[common.Address]SuavePrecompiledContract{ fetchBidsAddress: newFetchBids(), extractHintAddress: &extractHint{}, + signEthTransactionAddress: &signEthTransaction{}, simulateBundleAddress: &simulateBundle{}, buildEthBlockAddress: &buildEthBlock{}, submitEthBlockBidToRelayAddress: &submitEthBlockBidToRelay{}, diff --git a/core/vm/contracts_suave.go b/core/vm/contracts_suave.go index 0ce0e3757c..9310dbddb7 100644 --- a/core/vm/contracts_suave.go +++ b/core/vm/contracts_suave.go @@ -344,6 +344,10 @@ func (b *suaveRuntime) confidentialStoreStore(bidId types.BidId, key string, dat return (&confStoreStore{}).runImpl(b.suaveContext, bidId, key, data) } +func (b *suaveRuntime) signEthTransaction(txn []byte, chainId string, signingKey string) ([]byte, error) { + return (&signEthTransaction{}).runImpl(txn, chainId, signingKey) +} + func (b *suaveRuntime) extractHint(bundleData []byte) ([]byte, error) { return (&extractHint{}).runImpl(b.suaveContext, bundleData) } diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index 416bbe264c..efd4ea1943 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -34,6 +34,7 @@ import ( ) var ( + signEthTransactionAddress = common.HexToAddress("0x40100001") simulateBundleAddress = common.HexToAddress("0x42100000") extractHintAddress = common.HexToAddress("0x42100037") buildEthBlockAddress = common.HexToAddress("0x42100001") @@ -43,6 +44,53 @@ var ( fillMevShareBundleAddress = common.HexToAddress("0x43200001") ) +type signEthTransaction struct{} + +func (c *signEthTransaction) RequiredGas(input []byte) uint64 { + // Should be proportional to bundle gas limit + return 1000 +} + +func (c *signEthTransaction) Run(input []byte) ([]byte, error) { + return nil, errors.New("not available in this context") +} + +func (c *signEthTransaction) RunConfidential(suaveContext *SuaveContext, input []byte) ([]byte, error) { + return nil, errors.New("not available in this context") +} + +func (c *signEthTransaction) runImpl(txn []byte, chainId string, signingKey string) ([]byte, error) { + key, err := crypto.HexToECDSA(signingKey) + if err != nil { + return nil, fmt.Errorf("key not formatted properly: %w", err) + } + + chainIdInt, err := hexutil.DecodeBig(chainId) + if err != nil { + return nil, fmt.Errorf("chainId not formatted properly: %w", err) + } + + var tx types.Transaction + err = tx.UnmarshalBinary(txn) + if err != nil { + return nil, fmt.Errorf("txn not formatted properly: %w", err) + } + + signer := types.LatestSignerForChainID(chainIdInt) + + signedTx, err := types.SignTx(&tx, signer, key) + if err != nil { + return nil, fmt.Errorf("could not sign: %w", err) + } + + signedBytes, err := signedTx.MarshalBinary() + if err != nil { + return nil, fmt.Errorf("could not encode signed transaction: %w", err) + } + + return signedBytes, nil +} + type simulateBundle struct { } diff --git a/core/vm/contracts_suave_runtime_adapter.go b/core/vm/contracts_suave_runtime_adapter.go index 331fc511e3..54105247f8 100644 --- a/core/vm/contracts_suave_runtime_adapter.go +++ b/core/vm/contracts_suave_runtime_adapter.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: 5f7dc4aaca73e07546a16000edda8fa3b804777ed38fea2121bc0e09b889103e +// Hash: 23a6dd8b9b224b11b8baea19a80c55c7787c50c0eb2fc69727e66d615c913483 package vm import ( @@ -26,6 +26,7 @@ type SuaveRuntime interface { fetchBids(cond uint64, namespace string) ([]types.Bid, error) fillMevShareBundle(bidId types.BidId) ([]byte, error) newBid(decryptionCondition uint64, allowedPeekers []common.Address, allowedStores []common.Address, bidType string) (types.Bid, error) + signEthTransaction(txn []byte, chainId string, signingKey string) ([]byte, error) simulateBundle(bundleData []byte) (uint64, error) submitBundleJsonRPC(url string, method string, params []byte) ([]byte, error) submitEthBlockBidToRelay(relayUrl string, builderBid []byte) ([]byte, error) @@ -390,6 +391,48 @@ func (b *SuaveRuntimeAdapter) newBid(input []byte) (res []byte, err error) { } +func (b *SuaveRuntimeAdapter) signEthTransaction(input []byte) (res []byte, err error) { + var ( + unpacked []interface{} + result []byte + ) + + _ = unpacked + _ = result + + unpacked, err = artifacts.SuaveAbi.Methods["signEthTransaction"].Inputs.Unpack(input) + if err != nil { + err = errFailedToUnpackInput + return + } + + var ( + txn []byte + chainId string + signingKey string + ) + + txn = unpacked[0].([]byte) + chainId = unpacked[1].(string) + signingKey = unpacked[2].(string) + + var ( + output1 []byte + ) + + if output1, err = b.impl.signEthTransaction(txn, chainId, signingKey); err != nil { + return + } + + result, err = artifacts.SuaveAbi.Methods["signEthTransaction"].Outputs.Pack(output1) + if err != nil { + err = errFailedToPackOutput + return + } + return result, nil + +} + func (b *SuaveRuntimeAdapter) simulateBundle(input []byte) (res []byte, err error) { var ( unpacked []interface{} diff --git a/core/vm/contracts_suave_test.go b/core/vm/contracts_suave_test.go index 55b6806212..fa817c6ad5 100644 --- a/core/vm/contracts_suave_test.go +++ b/core/vm/contracts_suave_test.go @@ -3,6 +3,7 @@ package vm import ( "context" "math/big" + "regexp" "strings" "testing" @@ -123,6 +124,10 @@ func TestSuavePrecompileStub(t *testing.T) { "precompile buildEthBlock (0000000000000000000000000000000042100001) not allowed on 00000000000000000000000000000000", } + expectedVariableErrors := []*regexp.Regexp{ + regexp.MustCompile("key not formatted properly: invalid hex character.*in private key"), + } + for name, addr := range artifacts.SuaveMethods { abiMethod, ok := artifacts.SuaveAbi.Methods[name] if !ok { @@ -140,6 +145,18 @@ func TestSuavePrecompileStub(t *testing.T) { for _, expectedError := range expectedErrors { if strings.Contains(err.Error(), expectedError) { found = true + break + } + } + + if found { + continue + } + + for _, expectedErrRe := range expectedVariableErrors { + if expectedErrRe.Match([]byte(err.Error())) { + found = true + break } } if !found { diff --git a/core/vm/suave.go b/core/vm/suave.go index 269bcc5e76..34c726e3cb 100644 --- a/core/vm/suave.go +++ b/core/vm/suave.go @@ -114,6 +114,9 @@ func (p *SuavePrecompiledContractWrapper) Run(input []byte) ([]byte, error) { case extractHintAddress: ret, err = stub.extractHint(input) + case signEthTransactionAddress: + ret, err = stub.signEthTransaction(input) + case simulateBundleAddress: ret, err = stub.simulateBundle(input) diff --git a/suave/artifacts/Suave.sol/Suave.json b/suave/artifacts/Suave.sol/Suave.json index f563d9c6de..1bb8dd8f07 100644 --- a/suave/artifacts/Suave.sol/Suave.json +++ b/suave/artifacts/Suave.sol/Suave.json @@ -146,6 +146,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "SIGN_ETH_TRANSACTION", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SIMULATE_BUNDLE", @@ -187,9 +200,9 @@ } ], "deployedBytecode": { - "object": "0x73000000000000000000000000000000000000000030146080604052600436106100d95760003560e01c8063b61b127d11610096578063c91e11df11610070578063c91e11df1461015d578063d91525db14610168578063f0608b1c14610173578063f6ab3de51461017e57600080fd5b8063b61b127d1461013c578063b7817da014610147578063bc50c0051461015257600080fd5b806301c19530146100de578063040e51831461010557806369094cbc146101105780637320cb171461011b578063751afe2c1461012657806394804c6914610131575b600080fd5b6100e9634320000181565b6040516001600160a01b03909116815260200160405180910390f35b6100e9634210000381565b6100e9634201000181565b6100e9634203000081565b6100e9634210003781565b6100e9634210000181565b6100e9634210000081565b6100e9634202000081565b6100e9634210000281565b6100e9634203000181565b6100e9634201000081565b6100e9634300000181565b6100e963420200018156fea164736f6c6343000813000a" + "object": "0x73000000000000000000000000000000000000000030146080604052600436106100f45760003560e01c8063b61b127d11610096578063c91e11df11610070578063c91e11df14610183578063d91525db1461018e578063f0608b1c14610199578063f6ab3de5146101a457600080fd5b8063b61b127d14610162578063b7817da01461016d578063bc50c0051461017857600080fd5b80637320cb17116100d25780637320cb1714610136578063744795b914610141578063751afe2c1461014c57806394804c691461015757600080fd5b806301c19530146100f9578063040e51831461012057806369094cbc1461012b575b600080fd5b610104634320000181565b6040516001600160a01b03909116815260200160405180910390f35b610104634210000381565b610104634201000181565b610104634203000081565b610104634010000181565b610104634210003781565b610104634210000181565b610104634210000081565b610104634202000081565b610104634210000281565b610104634203000181565b610104634201000081565b610104634300000181565b61010463420200018156fea164736f6c6343000813000a" }, "bytecode": { - "object": "0x61019661003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100d95760003560e01c8063b61b127d11610096578063c91e11df11610070578063c91e11df1461015d578063d91525db14610168578063f0608b1c14610173578063f6ab3de51461017e57600080fd5b8063b61b127d1461013c578063b7817da014610147578063bc50c0051461015257600080fd5b806301c19530146100de578063040e51831461010557806369094cbc146101105780637320cb171461011b578063751afe2c1461012657806394804c6914610131575b600080fd5b6100e9634320000181565b6040516001600160a01b03909116815260200160405180910390f35b6100e9634210000381565b6100e9634201000181565b6100e9634203000081565b6100e9634210003781565b6100e9634210000181565b6100e9634210000081565b6100e9634202000081565b6100e9634210000281565b6100e9634203000181565b6100e9634201000081565b6100e9634300000181565b6100e963420200018156fea164736f6c6343000813000a" + "object": "0x6101bc61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100f45760003560e01c8063b61b127d11610096578063c91e11df11610070578063c91e11df14610183578063d91525db1461018e578063f0608b1c14610199578063f6ab3de5146101a457600080fd5b8063b61b127d14610162578063b7817da01461016d578063bc50c0051461017857600080fd5b80637320cb17116100d25780637320cb1714610136578063744795b914610141578063751afe2c1461014c57806394804c691461015757600080fd5b806301c19530146100f9578063040e51831461012057806369094cbc1461012b575b600080fd5b610104634320000181565b6040516001600160a01b03909116815260200160405180910390f35b610104634210000381565b610104634201000181565b610104634203000081565b610104634010000181565b610104634210003781565b610104634210000181565b610104634210000081565b610104634202000081565b610104634210000281565b610104634203000181565b610104634201000081565b610104634300000181565b61010463420200018156fea164736f6c6343000813000a" } } diff --git a/suave/artifacts/SuaveAbi.sol/SuaveAbi.json b/suave/artifacts/SuaveAbi.sol/SuaveAbi.json index ec15413320..848a77b5c7 100644 --- a/suave/artifacts/SuaveAbi.sol/SuaveAbi.json +++ b/suave/artifacts/SuaveAbi.sol/SuaveAbi.json @@ -321,6 +321,35 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "txn", + "type": "bytes" + }, + { + "internalType": "string", + "name": "chainId", + "type": "string" + }, + { + "internalType": "string", + "name": "signingKey", + "type": "string" + } + ], + "name": "signEthTransaction", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -395,9 +424,9 @@ } ], "deployedBytecode": { - "object": "0x608060405234801561001057600080fd5b506004361061009e5760003560e01c806392649e7d1161006657806392649e7d14610139578063a90a6c5f14610150578063ae9a604014610165578063b2c1714c14610173578063bd5bcdf31461018e57600080fd5b8063023e8e2f146100a357806320f16c3e146100d457806337a5686a146100f55780634f5631411461010b5780638735d6171461012b575b600080fd5b6100b76100b13660046102ef565b50600090565b6040516001600160401b0390911681526020015b60405180910390f35b6100e86100e23660046102ef565b50606090565b6040516100cb9190610369565b6100e8610103366004610383565b606092915050565b61011e6101193660046104ae565b6101b5565b6040516100cb9190610619565b6100e86100e236600461064d565b6100e8610147366004610668565b60609392505050565b61016361015e3660046106ef565b505050565b005b6100e8610103366004610729565b61018161010336600461076c565b6040516100cb9190610788565b6101a761019c366004610899565b606080935093915050565b6040516100cb92919061098a565b6040805160c0810182526000808252602082018190529181019190915260608082018190526080820181905260a08201525b949350505050565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715610227576102276101ef565b60405290565b60405161010081016001600160401b0381118282101715610227576102276101ef565b604051601f8201601f191681016001600160401b0381118282101715610278576102786101ef565b604052919050565b600082601f83011261029157600080fd5b81356001600160401b038111156102aa576102aa6101ef565b6102bd601f8201601f1916602001610250565b8181528460208386010111156102d257600080fd5b816020850160208301376000918101602001919091529392505050565b60006020828403121561030157600080fd5b81356001600160401b0381111561031757600080fd5b6101e784828501610280565b6000815180845260005b818110156103495760208185018101518683018201520161032d565b506000602082860101526020601f19601f83011685010191505092915050565b60208152600061037c6020830184610323565b9392505050565b6000806040838503121561039657600080fd5b82356001600160401b03808211156103ad57600080fd5b6103b986838701610280565b935060208501359150808211156103cf57600080fd5b506103dc85828601610280565b9150509250929050565b80356001600160401b03811681146103fd57600080fd5b919050565b60006001600160401b0382111561041b5761041b6101ef565b5060051b60200190565b80356001600160a01b03811681146103fd57600080fd5b600082601f83011261044d57600080fd5b8135602061046261045d83610402565b610250565b82815260059290921b8401810191818101908684111561048157600080fd5b8286015b848110156104a35761049681610425565b8352918301918301610485565b509695505050505050565b600080600080608085870312156104c457600080fd5b6104cd856103e6565b935060208501356001600160401b03808211156104e957600080fd5b6104f58883890161043c565b9450604087013591508082111561050b57600080fd5b6105178883890161043c565b9350606087013591508082111561052d57600080fd5b5061053a87828801610280565b91505092959194509250565b600081518084526020808501945080840160005b8381101561057f5781516001600160a01b03168752958201959082019060010161055a565b509495945050505050565b60006fffffffffffffffffffffffffffffffff19808351168452806020840151166020850152506001600160401b036040830151166040840152606082015160c060608501526105dd60c0850182610546565b9050608083015184820360808601526105f68282610546565b91505060a083015184820360a08601526106108282610323565b95945050505050565b60208152600061037c602083018461058a565b80356fffffffffffffffffffffffffffffffff19811681146103fd57600080fd5b60006020828403121561065f57600080fd5b61037c8261062c565b60008060006060848603121561067d57600080fd5b83356001600160401b038082111561069457600080fd5b6106a087838801610280565b945060208601359150808211156106b657600080fd5b6106c287838801610280565b935060408601359150808211156106d857600080fd5b506106e586828701610280565b9150509250925092565b60008060006060848603121561070457600080fd5b61070d8461062c565b925060208401356001600160401b03808211156106b657600080fd5b6000806040838503121561073c57600080fd5b6107458361062c565b915060208301356001600160401b0381111561076057600080fd5b6103dc85828601610280565b6000806040838503121561077f57600080fd5b610745836103e6565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156107dd57603f198886030184526107cb85835161058a565b945092850192908501906001016107af565b5092979650505050505050565b600082601f8301126107fb57600080fd5b8135602061080b61045d83610402565b82815260079290921b8401810191818101908684111561082a57600080fd5b8286015b848110156104a357608081890312156108475760008081fd5b61084f610205565b610858826103e6565b81526108658583016103e6565b858201526040610876818401610425565b9082015260606108878382016103e6565b9082015283529183019160800161082e565b6000806000606084860312156108ae57600080fd5b83356001600160401b03808211156108c557600080fd5b9085019061010082880312156108da57600080fd5b6108e261022d565b6108eb836103e6565b81526020830135828111156108ff57600080fd5b61090b89828601610280565b60208301525060408301356040820152610927606084016103e6565b606082015261093860808401610425565b608082015261094960a084016103e6565b60a082015260c083013560c082015260e08301358281111561096a57600080fd5b610976898286016107ea565b60e08301525094506106c26020870161062c565b60408152600061099d6040830185610323565b8281036020840152610610818561032356fea164736f6c6343000813000a" + "object": "0x608060405234801561001057600080fd5b50600436106100a95760003560e01c806392649e7d1161007157806392649e7d14610144578063a90a6c5f1461015b578063ae9a604014610170578063b2c1714c1461017e578063bd5bcdf314610199578063fb4f1e0d1461014457600080fd5b8063023e8e2f146100ae57806320f16c3e146100df57806337a5686a146101005780634f563141146101165780638735d61714610136575b600080fd5b6100c26100bc3660046102fa565b50600090565b6040516001600160401b0390911681526020015b60405180910390f35b6100f36100ed3660046102fa565b50606090565b6040516100d69190610374565b6100f361010e36600461038e565b606092915050565b6101296101243660046104b9565b6101c0565b6040516100d69190610624565b6100f36100ed366004610658565b6100f3610152366004610673565b60609392505050565b61016e6101693660046106fa565b505050565b005b6100f361010e366004610734565b61018c61010e366004610777565b6040516100d69190610793565b6101b26101a73660046108a4565b606080935093915050565b6040516100d6929190610995565b6040805160c0810182526000808252602082018190529181019190915260608082018190526080820181905260a08201525b949350505050565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715610232576102326101fa565b60405290565b60405161010081016001600160401b0381118282101715610232576102326101fa565b604051601f8201601f191681016001600160401b0381118282101715610283576102836101fa565b604052919050565b600082601f83011261029c57600080fd5b81356001600160401b038111156102b5576102b56101fa565b6102c8601f8201601f191660200161025b565b8181528460208386010111156102dd57600080fd5b816020850160208301376000918101602001919091529392505050565b60006020828403121561030c57600080fd5b81356001600160401b0381111561032257600080fd5b6101f28482850161028b565b6000815180845260005b8181101561035457602081850181015186830182015201610338565b506000602082860101526020601f19601f83011685010191505092915050565b602081526000610387602083018461032e565b9392505050565b600080604083850312156103a157600080fd5b82356001600160401b03808211156103b857600080fd5b6103c48683870161028b565b935060208501359150808211156103da57600080fd5b506103e78582860161028b565b9150509250929050565b80356001600160401b038116811461040857600080fd5b919050565b60006001600160401b03821115610426576104266101fa565b5060051b60200190565b80356001600160a01b038116811461040857600080fd5b600082601f83011261045857600080fd5b8135602061046d6104688361040d565b61025b565b82815260059290921b8401810191818101908684111561048c57600080fd5b8286015b848110156104ae576104a181610430565b8352918301918301610490565b509695505050505050565b600080600080608085870312156104cf57600080fd5b6104d8856103f1565b935060208501356001600160401b03808211156104f457600080fd5b61050088838901610447565b9450604087013591508082111561051657600080fd5b61052288838901610447565b9350606087013591508082111561053857600080fd5b506105458782880161028b565b91505092959194509250565b600081518084526020808501945080840160005b8381101561058a5781516001600160a01b031687529582019590820190600101610565565b509495945050505050565b60006fffffffffffffffffffffffffffffffff19808351168452806020840151166020850152506001600160401b036040830151166040840152606082015160c060608501526105e860c0850182610551565b9050608083015184820360808601526106018282610551565b91505060a083015184820360a086015261061b828261032e565b95945050505050565b6020815260006103876020830184610595565b80356fffffffffffffffffffffffffffffffff198116811461040857600080fd5b60006020828403121561066a57600080fd5b61038782610637565b60008060006060848603121561068857600080fd5b83356001600160401b038082111561069f57600080fd5b6106ab8783880161028b565b945060208601359150808211156106c157600080fd5b6106cd8783880161028b565b935060408601359150808211156106e357600080fd5b506106f08682870161028b565b9150509250925092565b60008060006060848603121561070f57600080fd5b61071884610637565b925060208401356001600160401b03808211156106c157600080fd5b6000806040838503121561074757600080fd5b61075083610637565b915060208301356001600160401b0381111561076b57600080fd5b6103e78582860161028b565b6000806040838503121561078a57600080fd5b610750836103f1565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156107e857603f198886030184526107d6858351610595565b945092850192908501906001016107ba565b5092979650505050505050565b600082601f83011261080657600080fd5b813560206108166104688361040d565b82815260079290921b8401810191818101908684111561083557600080fd5b8286015b848110156104ae57608081890312156108525760008081fd5b61085a610210565b610863826103f1565b81526108708583016103f1565b858201526040610881818401610430565b9082015260606108928382016103f1565b90820152835291830191608001610839565b6000806000606084860312156108b957600080fd5b83356001600160401b03808211156108d057600080fd5b9085019061010082880312156108e557600080fd5b6108ed610238565b6108f6836103f1565b815260208301358281111561090a57600080fd5b6109168982860161028b565b60208301525060408301356040820152610932606084016103f1565b606082015261094360808401610430565b608082015261095460a084016103f1565b60a082015260c083013560c082015260e08301358281111561097557600080fd5b610981898286016107f5565b60e08301525094506106cd60208701610637565b6040815260006109a8604083018561032e565b828103602084015261061b818561032e56fea164736f6c6343000813000a" }, "bytecode": { - "object": "0x608060405234801561001057600080fd5b506109bc806100206000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c806392649e7d1161006657806392649e7d14610139578063a90a6c5f14610150578063ae9a604014610165578063b2c1714c14610173578063bd5bcdf31461018e57600080fd5b8063023e8e2f146100a357806320f16c3e146100d457806337a5686a146100f55780634f5631411461010b5780638735d6171461012b575b600080fd5b6100b76100b13660046102ef565b50600090565b6040516001600160401b0390911681526020015b60405180910390f35b6100e86100e23660046102ef565b50606090565b6040516100cb9190610369565b6100e8610103366004610383565b606092915050565b61011e6101193660046104ae565b6101b5565b6040516100cb9190610619565b6100e86100e236600461064d565b6100e8610147366004610668565b60609392505050565b61016361015e3660046106ef565b505050565b005b6100e8610103366004610729565b61018161010336600461076c565b6040516100cb9190610788565b6101a761019c366004610899565b606080935093915050565b6040516100cb92919061098a565b6040805160c0810182526000808252602082018190529181019190915260608082018190526080820181905260a08201525b949350505050565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715610227576102276101ef565b60405290565b60405161010081016001600160401b0381118282101715610227576102276101ef565b604051601f8201601f191681016001600160401b0381118282101715610278576102786101ef565b604052919050565b600082601f83011261029157600080fd5b81356001600160401b038111156102aa576102aa6101ef565b6102bd601f8201601f1916602001610250565b8181528460208386010111156102d257600080fd5b816020850160208301376000918101602001919091529392505050565b60006020828403121561030157600080fd5b81356001600160401b0381111561031757600080fd5b6101e784828501610280565b6000815180845260005b818110156103495760208185018101518683018201520161032d565b506000602082860101526020601f19601f83011685010191505092915050565b60208152600061037c6020830184610323565b9392505050565b6000806040838503121561039657600080fd5b82356001600160401b03808211156103ad57600080fd5b6103b986838701610280565b935060208501359150808211156103cf57600080fd5b506103dc85828601610280565b9150509250929050565b80356001600160401b03811681146103fd57600080fd5b919050565b60006001600160401b0382111561041b5761041b6101ef565b5060051b60200190565b80356001600160a01b03811681146103fd57600080fd5b600082601f83011261044d57600080fd5b8135602061046261045d83610402565b610250565b82815260059290921b8401810191818101908684111561048157600080fd5b8286015b848110156104a35761049681610425565b8352918301918301610485565b509695505050505050565b600080600080608085870312156104c457600080fd5b6104cd856103e6565b935060208501356001600160401b03808211156104e957600080fd5b6104f58883890161043c565b9450604087013591508082111561050b57600080fd5b6105178883890161043c565b9350606087013591508082111561052d57600080fd5b5061053a87828801610280565b91505092959194509250565b600081518084526020808501945080840160005b8381101561057f5781516001600160a01b03168752958201959082019060010161055a565b509495945050505050565b60006fffffffffffffffffffffffffffffffff19808351168452806020840151166020850152506001600160401b036040830151166040840152606082015160c060608501526105dd60c0850182610546565b9050608083015184820360808601526105f68282610546565b91505060a083015184820360a08601526106108282610323565b95945050505050565b60208152600061037c602083018461058a565b80356fffffffffffffffffffffffffffffffff19811681146103fd57600080fd5b60006020828403121561065f57600080fd5b61037c8261062c565b60008060006060848603121561067d57600080fd5b83356001600160401b038082111561069457600080fd5b6106a087838801610280565b945060208601359150808211156106b657600080fd5b6106c287838801610280565b935060408601359150808211156106d857600080fd5b506106e586828701610280565b9150509250925092565b60008060006060848603121561070457600080fd5b61070d8461062c565b925060208401356001600160401b03808211156106b657600080fd5b6000806040838503121561073c57600080fd5b6107458361062c565b915060208301356001600160401b0381111561076057600080fd5b6103dc85828601610280565b6000806040838503121561077f57600080fd5b610745836103e6565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156107dd57603f198886030184526107cb85835161058a565b945092850192908501906001016107af565b5092979650505050505050565b600082601f8301126107fb57600080fd5b8135602061080b61045d83610402565b82815260079290921b8401810191818101908684111561082a57600080fd5b8286015b848110156104a357608081890312156108475760008081fd5b61084f610205565b610858826103e6565b81526108658583016103e6565b858201526040610876818401610425565b9082015260606108878382016103e6565b9082015283529183019160800161082e565b6000806000606084860312156108ae57600080fd5b83356001600160401b03808211156108c557600080fd5b9085019061010082880312156108da57600080fd5b6108e261022d565b6108eb836103e6565b81526020830135828111156108ff57600080fd5b61090b89828601610280565b60208301525060408301356040820152610927606084016103e6565b606082015261093860808401610425565b608082015261094960a084016103e6565b60a082015260c083013560c082015260e08301358281111561096a57600080fd5b610976898286016107ea565b60e08301525094506106c26020870161062c565b60408152600061099d6040830185610323565b8281036020840152610610818561032356fea164736f6c6343000813000a" + "object": "0x608060405234801561001057600080fd5b506109c7806100206000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c806392649e7d1161007157806392649e7d14610144578063a90a6c5f1461015b578063ae9a604014610170578063b2c1714c1461017e578063bd5bcdf314610199578063fb4f1e0d1461014457600080fd5b8063023e8e2f146100ae57806320f16c3e146100df57806337a5686a146101005780634f563141146101165780638735d61714610136575b600080fd5b6100c26100bc3660046102fa565b50600090565b6040516001600160401b0390911681526020015b60405180910390f35b6100f36100ed3660046102fa565b50606090565b6040516100d69190610374565b6100f361010e36600461038e565b606092915050565b6101296101243660046104b9565b6101c0565b6040516100d69190610624565b6100f36100ed366004610658565b6100f3610152366004610673565b60609392505050565b61016e6101693660046106fa565b505050565b005b6100f361010e366004610734565b61018c61010e366004610777565b6040516100d69190610793565b6101b26101a73660046108a4565b606080935093915050565b6040516100d6929190610995565b6040805160c0810182526000808252602082018190529181019190915260608082018190526080820181905260a08201525b949350505050565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715610232576102326101fa565b60405290565b60405161010081016001600160401b0381118282101715610232576102326101fa565b604051601f8201601f191681016001600160401b0381118282101715610283576102836101fa565b604052919050565b600082601f83011261029c57600080fd5b81356001600160401b038111156102b5576102b56101fa565b6102c8601f8201601f191660200161025b565b8181528460208386010111156102dd57600080fd5b816020850160208301376000918101602001919091529392505050565b60006020828403121561030c57600080fd5b81356001600160401b0381111561032257600080fd5b6101f28482850161028b565b6000815180845260005b8181101561035457602081850181015186830182015201610338565b506000602082860101526020601f19601f83011685010191505092915050565b602081526000610387602083018461032e565b9392505050565b600080604083850312156103a157600080fd5b82356001600160401b03808211156103b857600080fd5b6103c48683870161028b565b935060208501359150808211156103da57600080fd5b506103e78582860161028b565b9150509250929050565b80356001600160401b038116811461040857600080fd5b919050565b60006001600160401b03821115610426576104266101fa565b5060051b60200190565b80356001600160a01b038116811461040857600080fd5b600082601f83011261045857600080fd5b8135602061046d6104688361040d565b61025b565b82815260059290921b8401810191818101908684111561048c57600080fd5b8286015b848110156104ae576104a181610430565b8352918301918301610490565b509695505050505050565b600080600080608085870312156104cf57600080fd5b6104d8856103f1565b935060208501356001600160401b03808211156104f457600080fd5b61050088838901610447565b9450604087013591508082111561051657600080fd5b61052288838901610447565b9350606087013591508082111561053857600080fd5b506105458782880161028b565b91505092959194509250565b600081518084526020808501945080840160005b8381101561058a5781516001600160a01b031687529582019590820190600101610565565b509495945050505050565b60006fffffffffffffffffffffffffffffffff19808351168452806020840151166020850152506001600160401b036040830151166040840152606082015160c060608501526105e860c0850182610551565b9050608083015184820360808601526106018282610551565b91505060a083015184820360a086015261061b828261032e565b95945050505050565b6020815260006103876020830184610595565b80356fffffffffffffffffffffffffffffffff198116811461040857600080fd5b60006020828403121561066a57600080fd5b61038782610637565b60008060006060848603121561068857600080fd5b83356001600160401b038082111561069f57600080fd5b6106ab8783880161028b565b945060208601359150808211156106c157600080fd5b6106cd8783880161028b565b935060408601359150808211156106e357600080fd5b506106f08682870161028b565b9150509250925092565b60008060006060848603121561070f57600080fd5b61071884610637565b925060208401356001600160401b03808211156106c157600080fd5b6000806040838503121561074757600080fd5b61075083610637565b915060208301356001600160401b0381111561076b57600080fd5b6103e78582860161028b565b6000806040838503121561078a57600080fd5b610750836103f1565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156107e857603f198886030184526107d6858351610595565b945092850192908501906001016107ba565b5092979650505050505050565b600082601f83011261080657600080fd5b813560206108166104688361040d565b82815260079290921b8401810191818101908684111561083557600080fd5b8286015b848110156104ae57608081890312156108525760008081fd5b61085a610210565b610863826103f1565b81526108708583016103f1565b858201526040610881818401610430565b9082015260606108928382016103f1565b90820152835291830191608001610839565b6000806000606084860312156108b957600080fd5b83356001600160401b03808211156108d057600080fd5b9085019061010082880312156108e557600080fd5b6108ed610238565b6108f6836103f1565b815260208301358281111561090a57600080fd5b6109168982860161028b565b60208301525060408301356040820152610932606084016103f1565b606082015261094360808401610430565b608082015261095460a084016103f1565b60a082015260c083013560c082015260e08301358281111561097557600080fd5b610981898286016107f5565b60e08301525094506106cd60208701610637565b6040815260006109a8604083018561032e565b828103602084015261061b818561032e56fea164736f6c6343000813000a" } } diff --git a/suave/artifacts/SuaveLib.json b/suave/artifacts/SuaveLib.json index 6831312da9..b2dd7839fd 100644 --- a/suave/artifacts/SuaveLib.json +++ b/suave/artifacts/SuaveLib.json @@ -1 +1 @@ -[{"type":"function","name":"buildEthBlock","inputs":[{"name":"blockArgs","type":"tuple","internalType":"struct Suave.BuildBlockArgs","components":[{"name":"slot","type":"uint64","internalType":"uint64"},{"name":"proposerPubkey","type":"bytes","internalType":"bytes"},{"name":"parent","type":"bytes32","internalType":"bytes32"},{"name":"timestamp","type":"uint64","internalType":"uint64"},{"name":"feeRecipient","type":"address","internalType":"address"},{"name":"gasLimit","type":"uint64","internalType":"uint64"},{"name":"random","type":"bytes32","internalType":"bytes32"},{"name":"withdrawals","type":"tuple[]","internalType":"struct Suave.Withdrawal[]","components":[{"name":"index","type":"uint64","internalType":"uint64"},{"name":"validator","type":"uint64","internalType":"uint64"},{"name":"Address","type":"address","internalType":"address"},{"name":"amount","type":"uint64","internalType":"uint64"}]}]},{"name":"bidId","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"},{"name":"output2","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialInputs","outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialStoreRetrieve","inputs":[{"name":"bidId","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"key","type":"string","internalType":"string"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialStoreStore","inputs":[{"name":"bidId","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"key","type":"string","internalType":"string"},{"name":"data1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"ethcall","inputs":[{"name":"contractAddr","type":"address","internalType":"address"},{"name":"input1","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"extractHint","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"fetchBids","inputs":[{"name":"cond","type":"uint64","internalType":"uint64"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"bid","type":"tuple[]","internalType":"struct Suave.Bid[]","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"fillMevShareBundle","inputs":[{"name":"bidId","type":"bytes16","internalType":"struct Suave.BidId"}],"outputs":[{"name":"encodedBundle","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"newBid","inputs":[{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"bidType","type":"string","internalType":"string"}],"outputs":[{"name":"bid","type":"tuple","internalType":"struct Suave.Bid","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"simulateBundle","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"uint64","internalType":"uint64"}]},{"type":"function","name":"submitBundleJsonRPC","inputs":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"params","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"submitEthBlockBidToRelay","inputs":[{"name":"relayUrl","type":"string","internalType":"string"},{"name":"builderBid","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]}] \ No newline at end of file +[{"type":"function","name":"buildEthBlock","inputs":[{"name":"blockArgs","type":"tuple","internalType":"struct Suave.BuildBlockArgs","components":[{"name":"slot","type":"uint64","internalType":"uint64"},{"name":"proposerPubkey","type":"bytes","internalType":"bytes"},{"name":"parent","type":"bytes32","internalType":"bytes32"},{"name":"timestamp","type":"uint64","internalType":"uint64"},{"name":"feeRecipient","type":"address","internalType":"address"},{"name":"gasLimit","type":"uint64","internalType":"uint64"},{"name":"random","type":"bytes32","internalType":"bytes32"},{"name":"withdrawals","type":"tuple[]","internalType":"struct Suave.Withdrawal[]","components":[{"name":"index","type":"uint64","internalType":"uint64"},{"name":"validator","type":"uint64","internalType":"uint64"},{"name":"Address","type":"address","internalType":"address"},{"name":"amount","type":"uint64","internalType":"uint64"}]}]},{"name":"bidId","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"},{"name":"output2","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialInputs","outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialStoreRetrieve","inputs":[{"name":"bidId","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"key","type":"string","internalType":"string"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialStoreStore","inputs":[{"name":"bidId","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"key","type":"string","internalType":"string"},{"name":"data1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"ethcall","inputs":[{"name":"contractAddr","type":"address","internalType":"address"},{"name":"input1","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"extractHint","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"fetchBids","inputs":[{"name":"cond","type":"uint64","internalType":"uint64"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"bid","type":"tuple[]","internalType":"struct Suave.Bid[]","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"fillMevShareBundle","inputs":[{"name":"bidId","type":"bytes16","internalType":"struct Suave.BidId"}],"outputs":[{"name":"encodedBundle","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"newBid","inputs":[{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"bidType","type":"string","internalType":"string"}],"outputs":[{"name":"bid","type":"tuple","internalType":"struct Suave.Bid","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.BidId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"signEthTransaction","inputs":[{"name":"txn","type":"bytes","internalType":"bytes"},{"name":"chainId","type":"string","internalType":"string"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"simulateBundle","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"uint64","internalType":"uint64"}]},{"type":"function","name":"submitBundleJsonRPC","inputs":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"params","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"submitEthBlockBidToRelay","inputs":[{"name":"relayUrl","type":"string","internalType":"string"},{"name":"builderBid","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]}] \ No newline at end of file diff --git a/suave/artifacts/addresses.go b/suave/artifacts/addresses.go index f8ec26d5c5..3abe51d486 100644 --- a/suave/artifacts/addresses.go +++ b/suave/artifacts/addresses.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: 5f7dc4aaca73e07546a16000edda8fa3b804777ed38fea2121bc0e09b889103e +// Hash: 23a6dd8b9b224b11b8baea19a80c55c7787c50c0eb2fc69727e66d615c913483 package artifacts import ( @@ -17,6 +17,7 @@ var ( fetchBidsAddr = common.HexToAddress("0x0000000000000000000000000000000042030001") fillMevShareBundleAddr = common.HexToAddress("0x0000000000000000000000000000000043200001") newBidAddr = common.HexToAddress("0x0000000000000000000000000000000042030000") + signEthTransactionAddr = common.HexToAddress("0x0000000000000000000000000000000040100001") simulateBundleAddr = common.HexToAddress("0x0000000000000000000000000000000042100000") submitBundleJsonRPCAddr = common.HexToAddress("0x0000000000000000000000000000000043000001") submitEthBlockBidToRelayAddr = common.HexToAddress("0x0000000000000000000000000000000042100002") @@ -32,6 +33,7 @@ var SuaveMethods = map[string]common.Address{ "fetchBids": fetchBidsAddr, "fillMevShareBundle": fillMevShareBundleAddr, "newBid": newBidAddr, + "signEthTransaction": signEthTransactionAddr, "simulateBundle": simulateBundleAddr, "submitBundleJsonRPC": submitBundleJsonRPCAddr, "submitEthBlockBidToRelay": submitEthBlockBidToRelayAddr, @@ -57,6 +59,8 @@ func PrecompileAddressToName(addr common.Address) string { return "fillMevShareBundle" case newBidAddr: return "newBid" + case signEthTransactionAddr: + return "signEthTransaction" case simulateBundleAddr: return "simulateBundle" case submitBundleJsonRPCAddr: diff --git a/suave/e2e/workflow_test.go b/suave/e2e/workflow_test.go index b8dbdafb3c..8cd8c1a89b 100644 --- a/suave/e2e/workflow_test.go +++ b/suave/e2e/workflow_test.go @@ -36,6 +36,7 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/suave/artifacts" suave "github.com/ethereum/go-ethereum/suave/core" "github.com/ethereum/go-ethereum/suave/cstore" "github.com/ethereum/go-ethereum/suave/sdk" @@ -230,6 +231,57 @@ func TestMempool(t *testing.T) { } } +func TestTxSigningPrecompile(t *testing.T) { + fr := newFramework(t) + defer fr.Close() + + tx := types.NewTransaction(15, common.Address{0x14}, big.NewInt(50), 1000000, big.NewInt(42313), []byte{0x42}) + txBytes, err := tx.MarshalBinary() + require.NoError(t, err) + + sk, err := crypto.GenerateKey() + require.NoError(t, err) + skHex := hex.EncodeToString(crypto.FromECDSA(sk)) + + txChainId := big.NewInt(13) + chainIdHex := hexutil.EncodeBig(txChainId) + + // function signEthTransaction(bytes memory txn, string memory chainId, string memory signingKey) + args, err := artifacts.SuaveAbi.Methods["signEthTransaction"].Inputs.Pack(txBytes, chainIdHex, skHex) + require.NoError(t, err) + + gas := hexutil.Uint64(1000000) + chainId := hexutil.Big(*testSuaveGenesis.Config.ChainID) + + var callResult hexutil.Bytes + err = fr.suethSrv.RPCNode().Call(&callResult, "eth_call", setTxArgsDefaults(ethapi.TransactionArgs{ + To: &signEthTransaction, + Gas: &gas, + IsConfidential: true, + ChainID: &chainId, + Data: (*hexutil.Bytes)(&args), + }), "latest") + requireNoRpcError(t, err) + + unpackedCallResult, err := artifacts.SuaveAbi.Methods["signEthTransaction"].Outputs.Unpack(callResult) + require.NoError(t, err) + + var signedTx types.Transaction + require.NoError(t, signedTx.UnmarshalBinary(unpackedCallResult[0].([]byte))) + + require.Equal(t, tx.Nonce(), signedTx.Nonce()) + require.Equal(t, *tx.To(), *signedTx.To()) + require.Equal(t, 0, tx.Value().Cmp(signedTx.Value())) + require.Equal(t, tx.Gas(), signedTx.Gas()) + require.Equal(t, tx.GasPrice(), signedTx.GasPrice()) + require.Equal(t, tx.Data(), signedTx.Data()) + + sender, err := types.Sender(types.LatestSignerForChainID(txChainId), &signedTx) + require.NoError(t, err) + + require.Equal(t, crypto.PubkeyToAddress(sk.PublicKey), sender) +} + func TestBundleBid(t *testing.T) { // t.Fatal("not implemented") @@ -1155,8 +1207,10 @@ var ( isConfidentialAddress = common.HexToAddress("0x42010000") fetchBidsAddress = common.HexToAddress("0x42030001") fillMevShareBundleAddress = common.HexToAddress("0x43200001") - simulateBundleAddress = common.HexToAddress("0x42100000") - buildEthBlockAddress = common.HexToAddress("0x42100001") + + signEthTransaction = common.HexToAddress("0x40100001") + simulateBundleAddress = common.HexToAddress("0x42100000") + buildEthBlockAddress = common.HexToAddress("0x42100001") /* contracts */ newBundleBidAddress = common.HexToAddress("0x642300000") diff --git a/suave/gen/suave_spec.yaml b/suave/gen/suave_spec.yaml index 28c4ee19da..e60fc74434 100644 --- a/suave/gen/suave_spec.yaml +++ b/suave/gen/suave_spec.yaml @@ -99,6 +99,19 @@ functions: fields: - name: output1 type: bytes + - name: signEthTransaction + address: "0x0000000000000000000000000000000040100001" + input: + - name: txn + type: bytes + - name: chainId + type: string + - name: signingKey + type: string + output: + fields: + - name: output1 + type: bytes - name: simulateBundle address: "0x0000000000000000000000000000000042100000" input: diff --git a/suave/sol/libraries/Suave.sol b/suave/sol/libraries/Suave.sol index 2d78be9120..3923371d53 100644 --- a/suave/sol/libraries/Suave.sol +++ b/suave/sol/libraries/Suave.sol @@ -53,6 +53,8 @@ library Suave { address public constant NEW_BID = 0x0000000000000000000000000000000042030000; + address public constant SIGN_ETH_TRANSACTION = 0x0000000000000000000000000000000040100001; + address public constant SIMULATE_BUNDLE = 0x0000000000000000000000000000000042100000; address public constant SUBMIT_BUNDLE_JSON_RPC = 0x0000000000000000000000000000000043000001; @@ -164,6 +166,19 @@ library Suave { return abi.decode(data, (Bid)); } + function signEthTransaction(bytes memory txn, string memory chainId, string memory signingKey) + internal + view + returns (bytes memory) + { + (bool success, bytes memory data) = SIGN_ETH_TRANSACTION.staticcall(abi.encode(txn, chainId, signingKey)); + if (!success) { + revert PeekerReverted(SIGN_ETH_TRANSACTION, data); + } + + return abi.decode(data, (bytes)); + } + function simulateBundle(bytes memory bundleData) internal view returns (uint64) { (bool success, bytes memory data) = SIMULATE_BUNDLE.staticcall(abi.encode(bundleData)); if (!success) { diff --git a/suave/sol/libraries/SuaveAbi.sol b/suave/sol/libraries/SuaveAbi.sol index 2b583884ac..a4da325c50 100644 --- a/suave/sol/libraries/SuaveAbi.sol +++ b/suave/sol/libraries/SuaveAbi.sol @@ -9,6 +9,7 @@ contract SuaveAbi { function fetchBids(uint64 cond, string memory namespace) external view returns (Suave.Bid[] memory) {} function confidentialStoreStore(Suave.BidId bidId, string memory key, bytes memory data) external view {} function confidentialStoreRetrieve(Suave.BidId bidId, string memory key) external view returns (bytes memory) {} + function signEthTransaction(bytes memory txn, string memory chainId, string memory signingKey) external view returns (bytes memory) {} function simulateBundle(bytes memory bundleData) external view returns (uint64) {} function extractHint(bytes memory bundleData) external view returns (bytes memory) {} function buildEthBlock(Suave.BuildBlockArgs memory blockArgs, Suave.BidId bid, string memory namespace) external view returns (bytes memory, bytes memory) {} diff --git a/suave/sol/libraries/SuaveForge.sol b/suave/sol/libraries/SuaveForge.sol index 207b5338f9..490a94a680 100644 --- a/suave/sol/libraries/SuaveForge.sol +++ b/suave/sol/libraries/SuaveForge.sol @@ -101,6 +101,16 @@ library SuaveForge { return abi.decode(data, (Suave.Bid)); } + function signEthTransaction(bytes memory txn, string memory chainId, string memory signingKey) + internal + view + returns (bytes memory) + { + bytes memory data = forgeIt("0x0000000000000000000000000000000040100001", abi.encode(txn, chainId, signingKey)); + + return abi.decode(data, (bytes)); + } + function simulateBundle(bytes memory bundleData) internal view returns (uint64) { bytes memory data = forgeIt("0x0000000000000000000000000000000042100000", abi.encode(bundleData));