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

Add new call Precompile #66

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/types/suave_structs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ var PrecompiledContractsSuave = map[common.Address]SuavePrecompiledContract{
simulateBundleAddress: &simulateBundle{},
buildEthBlockAddress: &buildEthBlock{},
submitEthBlockBidToRelayAddress: &submitEthBlockBidToRelay{},

ethcallAddr: &ethCallPrecompile{},
}

// PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum
Expand Down
4 changes: 4 additions & 0 deletions core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ type suaveRuntime struct {

var _ SuaveRuntime = &suaveRuntime{}

func (b *suaveRuntime) ethcall(contractAddr common.Address, input []byte) ([]byte, error) {
return (&ethCallPrecompile{}).runImpl(b.suaveContext, contractAddr, input)
}

func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, bid types.BidId, namespace string) ([]byte, []byte, error) {
return (&buildEthBlock{}).runImpl(b.suaveContext, blockArgs, bid, namespace)
}
Expand Down
19 changes: 19 additions & 0 deletions core/vm/contracts_suave_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ func (c *extractHint) runImpl(suaveContext *SuaveContext, bundleBytes []byte) ([
return hintBytes, nil
}

type ethCallPrecompile struct{}

func (e *ethCallPrecompile) RequiredGas(input []byte) uint64 {
// Should be proportional to bundle gas limit
return 10000
}

func (e *ethCallPrecompile) Run(input []byte) ([]byte, error) {
return input, nil
}

func (e *ethCallPrecompile) runImpl(suaveContext *SuaveContext, contractAddr common.Address, input []byte) ([]byte, error) {
return suaveContext.Backend.ConfidentialEthBackend.Call(context.Background(), contractAddr, input)
}

func (e *ethCallPrecompile) RunConfidential(suaveContext *SuaveContext, input []byte) ([]byte, error) {
return nil, nil
}

type buildEthBlock struct {
}

Expand Down
43 changes: 42 additions & 1 deletion core/vm/contracts_suave_runtime_adapter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions core/vm/contracts_suave_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (m *mockSuaveBackend) BuildEthBlockFromBundles(ctx context.Context, args *s
return nil, nil
}

func (m *mockSuaveBackend) Call(ctx context.Context, contractAddr common.Address, input []byte) ([]byte, error) {
return nil, nil
}

func (m *mockSuaveBackend) Subscribe() (<-chan cstore.DAMessage, context.CancelFunc) {
return nil, func() {}
}
Expand Down
7 changes: 7 additions & 0 deletions core/vm/suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (p *SuavePrecompiledContractWrapper) RequiredGas(input []byte) uint64 {
return p.contract.RequiredGas(input)
}

var (
ethcallAddr = common.HexToAddress("0x0000000000000000000000000000000042100003")
)

func (p *SuavePrecompiledContractWrapper) Run(input []byte) ([]byte, error) {
stub := &SuaveRuntimeAdapter{
impl: &suaveRuntime{
Expand Down Expand Up @@ -109,6 +113,9 @@ func (p *SuavePrecompiledContractWrapper) Run(input []byte) ([]byte, error) {

case submitEthBlockBidToRelayAddress:
return stub.submitEthBlockBidToRelay(input)

case ethcallAddr:
return stub.ethcall(input)
}

return nil, fmt.Errorf("precompile %s not found", p.addr)
Expand Down
19 changes: 19 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/bloombits"
Expand All @@ -37,6 +38,7 @@ import (
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -447,3 +449,20 @@ func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, re
func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (*core.Message, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) {
return b.eth.stateAtTransaction(ctx, block, txIndex, reexec)
}

func (b *EthAPIBackend) Call(ctx context.Context, contractAddr common.Address, input []byte) ([]byte, error) {
// Note: this is pretty close to be a circle dependency.
data := hexutil.Bytes(input)
txnArgs := ethapi.TransactionArgs{
To: &contractAddr,
Data: &data,
}

blockNum := rpc.LatestBlockNumber
res, err := ethapi.DoCall(ctx, b, txnArgs, rpc.BlockNumberOrHash{BlockNumber: &blockNum}, nil, nil, 5*time.Second, 100000)
if err != nil {
return nil, err
}

return res.ReturnData, nil
}
17 changes: 15 additions & 2 deletions suave/artifacts/Suave.sol/Suave.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "ETHCALL",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "EXTRACT_HINT",
Expand Down Expand Up @@ -147,6 +160,6 @@
"type": "function"
}
],
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600436106100a85760003560e01c8063b7817da011610070578063b7817da014610100578063bc50c0051461010b578063c91e11df14610116578063d91525db14610121578063f6ab3de51461012c57600080fd5b806369094cbc146100ad5780637320cb17146100d4578063751afe2c146100df57806394804c69146100ea578063b61b127d146100f5575b600080fd5b6100b8634201000181565b6040516001600160a01b03909116815260200160405180910390f35b6100b8634203000081565b6100b8634210003781565b6100b8634210000181565b6100b8634210000081565b6100b8634202000081565b6100b8634210000281565b6100b8634203000181565b6100b8634201000081565b6100b863420200018156fea164736f6c6343000813000a",
"bytecode": "0x61014461003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100a85760003560e01c8063b7817da011610070578063b7817da014610100578063bc50c0051461010b578063c91e11df14610116578063d91525db14610121578063f6ab3de51461012c57600080fd5b806369094cbc146100ad5780637320cb17146100d4578063751afe2c146100df57806394804c69146100ea578063b61b127d146100f5575b600080fd5b6100b8634201000181565b6040516001600160a01b03909116815260200160405180910390f35b6100b8634203000081565b6100b8634210003781565b6100b8634210000181565b6100b8634210000081565b6100b8634202000081565b6100b8634210000281565b6100b8634203000181565b6100b8634201000081565b6100b863420200018156fea164736f6c6343000813000a"
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600436106100b35760003560e01c8063b61b127d1161007b578063b61b127d1461010b578063b7817da014610116578063bc50c00514610121578063c91e11df1461012c578063d91525db14610137578063f6ab3de51461014257600080fd5b8063040e5183146100b857806369094cbc146100df5780637320cb17146100ea578063751afe2c146100f557806394804c6914610100575b600080fd5b6100c3634210000381565b6040516001600160a01b03909116815260200160405180910390f35b6100c3634201000181565b6100c3634203000081565b6100c3634210003781565b6100c3634210000181565b6100c3634210000081565b6100c3634202000081565b6100c3634210000281565b6100c3634203000181565b6100c3634201000081565b6100c363420200018156fea164736f6c6343000813000a",
"bytecode": "0x61015a61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100b35760003560e01c8063b61b127d1161007b578063b61b127d1461010b578063b7817da014610116578063bc50c00514610121578063c91e11df1461012c578063d91525db14610137578063f6ab3de51461014257600080fd5b8063040e5183146100b857806369094cbc146100df5780637320cb17146100ea578063751afe2c146100f557806394804c6914610100575b600080fd5b6100c3634210000381565b6040516001600160a01b03909116815260200160405180910390f35b6100c3634201000181565b6100c3634203000081565b6100c3634210003781565b6100c3634210000181565b6100c3634210000081565b6100c3634202000081565b6100c3634210000281565b6100c3634203000181565b6100c3634201000081565b6100c363420200018156fea164736f6c6343000813000a"
}
2 changes: 1 addition & 1 deletion suave/artifacts/SuaveLib.json
Original file line number Diff line number Diff line change
@@ -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":"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":"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":"submitEthBlockBidToRelay","inputs":[{"name":"relayUrl","type":"string","internalType":"string"},{"name":"builderBid","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]}]
[{"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":"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":"submitEthBlockBidToRelay","inputs":[{"name":"relayUrl","type":"string","internalType":"string"},{"name":"builderBid","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"output1","type":"bytes","internalType":"bytes"}]}]
6 changes: 5 additions & 1 deletion suave/artifacts/addresses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.