Skip to content

Commit

Permalink
Use code generation for suave precompiles switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Sep 21, 2023
1 parent 8f443af commit 77f23b8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, bid types.B
}

func (b *suaveRuntime) confidentialInputs() ([]byte, error) {
return nil, nil
return (&confidentialInputsPrecompile{}).RunConfidential(b.backend, nil)
}

func (b *suaveRuntime) confidentialStoreRetrieve(bidId types.BidId, key string) ([]byte, error) {
Expand Down
46 changes: 46 additions & 0 deletions core/vm/contracts_suave_runtime_adapter.go

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

35 changes: 3 additions & 32 deletions core/vm/suave.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package vm

import (
"fmt"

"github.com/ethereum/go-ethereum/common"
suave "github.com/ethereum/go-ethereum/suave/core"
)
Expand Down Expand Up @@ -51,37 +49,10 @@ func (p *SuavePrecompiledContractWrapper) Run(input []byte) ([]byte, error) {
},
}

switch p.addr {
case isConfidentialAddress:
if p.addr == isConfidentialAddress {
// 'isConfidential' is a special precompile
return (&isConfidentialPrecompile{}).RunConfidential(p.backend, input)

case confidentialInputsAddress:
return (&confidentialInputsPrecompile{}).RunConfidential(p.backend, input)

case confStoreStoreAddress:
return stub.confidentialStoreStore(input)

case confStoreRetrieveAddress:
return stub.confidentialStoreRetrieve(input)

case newBidAddress:
return stub.newBid(input)

case fetchBidsAddress:
return stub.fetchBids(input)

case extractHintAddress:
return stub.extractHint(input)

case simulateBundleAddress:
return stub.simulateBundle(input)

case buildEthBlockAddress:
return stub.buildEthBlock(input)

case submitEthBlockBidToRelayAddress:
return stub.submitEthBlockBidToRelay(input)
}

return nil, fmt.Errorf("precompile %s not found", p.addr)
return stub.run(p.addr, input)
}
14 changes: 14 additions & 0 deletions suave/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,24 @@ type SuaveRuntime interface {
{{.Name}}({{range .Input}}{{.Name}} {{typ2 .Typ}}, {{end}}) ({{range .Output.Fields}}{{typ2 .Typ}}, {{end}}error){{end}}
}
var ({{range .Functions}}
{{.Name}}Addr = common.HexToAddress("{{.Address}}"){{end}}
)
type SuaveRuntimeAdapter struct {
impl SuaveRuntime
}
func (b *SuaveRuntimeAdapter) run(addr common.Address, input []byte) ([]byte, error) {
switch addr { {{range .Functions}}
case {{.Name}}Addr:
return b.{{.Name}}(input)
{{end}}
default:
return nil, fmt.Errorf("suave precompile not found for " + addr.String())
}
}
{{range .Functions}}
func (b *SuaveRuntimeAdapter) {{.Name}}(input []byte) (res []byte, err error) {
var (
Expand Down

0 comments on commit 77f23b8

Please sign in to comment.