Skip to content

Commit

Permalink
change names to confidentialStore and confidentialRetrieve (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
andytudhope authored Nov 2, 2023
1 parent 3c636ac commit b328d64
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 100 deletions.
4 changes: 2 additions & 2 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ var PrecompiledContractsSuave = map[common.Address]SuavePrecompiledContract{
isConfidentialAddress: &isConfidentialPrecompile{},
confidentialInputsAddress: &confidentialInputsPrecompile{},

confStoreStoreAddress: newConfStoreStore(),
confStoreRetrieveAddress: newConfStoreRetrieve(),
confStoreAddress: newconfStore(),
confRetrieveAddress: newconfRetrieve(),

newBidAddress: newNewBid(),
fetchBidsAddress: newFetchBids(),
Expand Down
46 changes: 23 additions & 23 deletions core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var (

confidentialInputsAddress = common.HexToAddress("0x42010001")

confStoreStoreAddress = common.HexToAddress("0x42020000")
confStoreRetrieveAddress = common.HexToAddress("0x42020001")
confStoreAddress = common.HexToAddress("0x42020000")
confRetrieveAddress = common.HexToAddress("0x42020001")

newBidAddress = common.HexToAddress("0x42030000")
fetchBidsAddress = common.HexToAddress("0x42030001")
Expand Down Expand Up @@ -80,25 +80,25 @@ func (c *confidentialInputsPrecompile) RunConfidential(suaveContext *SuaveContex

/* Confidential store precompiles */

type confStoreStore struct {
type confStore struct {
inoutAbi abi.Method
}

func newConfStoreStore() *confStoreStore {
func newconfStore() *confStore {
inoutAbi := mustParseMethodAbi(`[{"inputs":[{"type":"bytes16"}, {"type":"bytes16"}, {"type":"string"}, {"type":"bytes"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"}]`, "store")

return &confStoreStore{inoutAbi}
return &confStore{inoutAbi}
}

func (c *confStoreStore) RequiredGas(input []byte) uint64 {
func (c *confStore) RequiredGas(input []byte) uint64 {
return uint64(100 * len(input))
}

func (c *confStoreStore) Run(input []byte) ([]byte, error) {
func (c *confStore) Run(input []byte) ([]byte, error) {
return nil, errors.New("not available in this suaveContext")
}

func (c *confStoreStore) RunConfidential(suaveContext *SuaveContext, input []byte) ([]byte, error) {
func (c *confStore) RunConfidential(suaveContext *SuaveContext, input []byte) ([]byte, error) {
if len(suaveContext.CallerStack) == 0 {
return []byte("not allowed"), errors.New("not allowed in this suaveContext")
}
Expand All @@ -118,15 +118,15 @@ func (c *confStoreStore) RunConfidential(suaveContext *SuaveContext, input []byt
return nil, nil
}

func (c *confStoreStore) runImpl(suaveContext *SuaveContext, bidId suave.BidId, key string, data []byte) error {
func (c *confStore) runImpl(suaveContext *SuaveContext, bidId suave.BidId, key string, data []byte) error {
bid, err := suaveContext.Backend.ConfidentialStore.FetchBidById(bidId)
if err != nil {
return suave.ErrBidNotFound
}

log.Info("confStoreStore", "bidId", bidId, "key", key)
log.Info("confStore", "bidId", bidId, "key", key)

caller, err := checkIsPrecompileCallAllowed(suaveContext, confStoreStoreAddress, bid)
caller, err := checkIsPrecompileCallAllowed(suaveContext, confStoreAddress, bid)
if err != nil {
return err
}
Expand All @@ -143,21 +143,21 @@ func (c *confStoreStore) runImpl(suaveContext *SuaveContext, bidId suave.BidId,
return nil
}

type confStoreRetrieve struct{}
type confRetrieve struct{}

func newConfStoreRetrieve() *confStoreRetrieve {
return &confStoreRetrieve{}
func newconfRetrieve() *confRetrieve {
return &confRetrieve{}
}

func (c *confStoreRetrieve) RequiredGas(input []byte) uint64 {
func (c *confRetrieve) RequiredGas(input []byte) uint64 {
return 100
}

func (c *confStoreRetrieve) Run(input []byte) ([]byte, error) {
func (c *confRetrieve) Run(input []byte) ([]byte, error) {
return nil, errors.New("not available in this suaveContext")
}

func (c *confStoreRetrieve) RunConfidential(suaveContext *SuaveContext, input []byte) ([]byte, error) {
func (c *confRetrieve) RunConfidential(suaveContext *SuaveContext, input []byte) ([]byte, error) {
if len(suaveContext.CallerStack) == 0 {
return []byte("not allowed"), errors.New("not allowed in this suaveContext")
}
Expand All @@ -173,13 +173,13 @@ func (c *confStoreRetrieve) RunConfidential(suaveContext *SuaveContext, input []
return c.runImpl(suaveContext, bidId, key)
}

func (c *confStoreRetrieve) runImpl(suaveContext *SuaveContext, bidId suave.BidId, key string) ([]byte, error) {
func (c *confRetrieve) runImpl(suaveContext *SuaveContext, bidId suave.BidId, key string) ([]byte, error) {
bid, err := suaveContext.Backend.ConfidentialStore.FetchBidById(bidId)
if err != nil {
return nil, suave.ErrBidNotFound
}

caller, err := checkIsPrecompileCallAllowed(suaveContext, confStoreRetrieveAddress, bid)
caller, err := checkIsPrecompileCallAllowed(suaveContext, confRetrieveAddress, bid)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -336,12 +336,12 @@ func (b *suaveRuntime) confidentialInputs() ([]byte, error) {
return (&confidentialInputsPrecompile{}).RunConfidential(b.suaveContext, nil)
}

func (b *suaveRuntime) confidentialStoreRetrieve(bidId types.BidId, key string) ([]byte, error) {
return (&confStoreRetrieve{}).runImpl(b.suaveContext, bidId, key)
func (b *suaveRuntime) confidentialRetrieve(bidId types.BidId, key string) ([]byte, error) {
return (&confRetrieve{}).runImpl(b.suaveContext, bidId, key)
}

func (b *suaveRuntime) confidentialStoreStore(bidId types.BidId, key string, data []byte) error {
return (&confStoreStore{}).runImpl(b.suaveContext, bidId, key, data)
func (b *suaveRuntime) confidentialStore(bidId types.BidId, key string, data []byte) error {
return (&confStore{}).runImpl(b.suaveContext, bidId, key, data)
}

func (b *suaveRuntime) signEthTransaction(txn []byte, chainId string, signingKey string) ([]byte, error) {
Expand Down
6 changes: 3 additions & 3 deletions core/vm/contracts_suave_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ func (c *fillMevShareBundle) runImpl(suaveContext *SuaveContext, bidId types.Bid
return nil, err
}

matchedBundleIdsBytes, err := (&confStoreRetrieve{}).runImpl(suaveContext, bidId, "mevshare:v0:mergedBids")
matchedBundleIdsBytes, err := (&confRetrieve{}).runImpl(suaveContext, bidId, "mevshare:v0:mergedBids")
if err != nil {
return nil, err
}
Expand All @@ -632,7 +632,7 @@ func (c *fillMevShareBundle) runImpl(suaveContext *SuaveContext, bidId types.Bid

matchBidIds := unpackedBidIds[0].([][16]byte)

userBundleBytes, err := (&confStoreRetrieve{}).runImpl(suaveContext, matchBidIds[0], "mevshare:v0:ethBundles")
userBundleBytes, err := (&confRetrieve{}).runImpl(suaveContext, matchBidIds[0], "mevshare:v0:ethBundles")
if err != nil {
return nil, fmt.Errorf("could not retrieve bundle data for bidId %v: %w", matchBidIds[0], err)
}
Expand All @@ -642,7 +642,7 @@ func (c *fillMevShareBundle) runImpl(suaveContext *SuaveContext, bidId types.Bid
return nil, fmt.Errorf("could not unmarshal user bundle data for bidId %v: %w", matchBidIds[0], err)
}

matchBundleBytes, err := (&confStoreRetrieve{}).runImpl(suaveContext, matchBidIds[1], "mevshare:v0:ethBundles")
matchBundleBytes, err := (&confRetrieve{}).runImpl(suaveContext, matchBidIds[1], "mevshare:v0:ethBundles")
if err != nil {
return nil, fmt.Errorf("could not retrieve match bundle data for bidId %v: %w", matchBidIds[1], err)
}
Expand Down
28 changes: 14 additions & 14 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.

14 changes: 7 additions & 7 deletions core/vm/contracts_suave_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func TestSuavePrecompileStub(t *testing.T) {
// error in 'buildEthBlock' when it expects to retrieve bids in abi format from the
// confidential store.
"could not unpack merged bid ids",
"no caller of confidentialStoreRetrieve (0000000000000000000000000000000042020001) is allowed on 00000000000000000000000000000000",
"no caller of confidentialRetrieve (0000000000000000000000000000000042020001) is allowed on 00000000000000000000000000000000",
"precompile fillMevShareBundle (0000000000000000000000000000000043200001) not allowed on 00000000000000000000000000000000",
"no caller of confidentialStoreStore (0000000000000000000000000000000042020000) is allowed on 00000000000000000000000000000000",
"no caller of confidentialStore (0000000000000000000000000000000042020000) is allowed on 00000000000000000000000000000000",
"precompile buildEthBlock (0000000000000000000000000000000042100001) not allowed on 00000000000000000000000000000000",
}

Expand Down Expand Up @@ -229,27 +229,27 @@ func TestSuave_ConfStoreWorkflow(t *testing.T) {
data := []byte{0x1}

// cannot store a value for a bid that does not exist
err := b.confidentialStoreStore(types.BidId{}, "key", data)
err := b.confidentialStore(types.BidId{}, "key", data)
require.Error(t, err)

bid, err := b.newBid(5, []common.Address{callerAddr}, nil, "a")
require.NoError(t, err)

// cannot store the bid if the caller is not allowed to
err = b.confidentialStoreStore(bid.Id, "key", data)
err = b.confidentialStore(bid.Id, "key", data)
require.Error(t, err)

// now, the caller is allowed to store the bid
b.suaveContext.CallerStack = append(b.suaveContext.CallerStack, &callerAddr)
err = b.confidentialStoreStore(bid.Id, "key", data)
err = b.confidentialStore(bid.Id, "key", data)
require.NoError(t, err)

val, err := b.confidentialStoreRetrieve(bid.Id, "key")
val, err := b.confidentialRetrieve(bid.Id, "key")
require.NoError(t, err)
require.Equal(t, data, val)

// cannot retrieve the value if the caller is not allowed to
b.suaveContext.CallerStack = []*common.Address{}
_, err = b.confidentialStoreRetrieve(bid.Id, "key")
_, err = b.confidentialRetrieve(bid.Id, "key")
require.Error(t, err)
}
2 changes: 1 addition & 1 deletion core/vm/suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func checkIsPrecompileCallAllowed(suaveContext *SuaveContext, precompile common.
isPrecompileAllowed := slices.Contains(bid.AllowedPeekers, precompile)

// Special case for confStore as those are implicitly allowed
if !isPrecompileAllowed && precompile != confStoreStoreAddress && precompile != confStoreRetrieveAddress {
if !isPrecompileAllowed && precompile != confStoreAddress && precompile != confRetrieveAddress {
return common.Address{}, fmt.Errorf("precompile %s (%x) not allowed on %x", artifacts.PrecompileAddressToName(precompile), precompile, bid.Id)
}

Expand Down
8 changes: 4 additions & 4 deletions suave/artifacts/Suave.sol/Suave.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
{
"inputs": [],
"name": "CONFIDENTIAL_STORE_RETRIEVE",
"name": "CONFIDENTIAL_RETRIEVE",
"outputs": [
{
"internalType": "address",
Expand All @@ -57,7 +57,7 @@
},
{
"inputs": [],
"name": "CONFIDENTIAL_STORE_STORE",
"name": "CONFIDENTIAL_STORE",
"outputs": [
{
"internalType": "address",
Expand Down Expand Up @@ -200,9 +200,9 @@
}
],
"deployedBytecode": {
"object": "0x73000000000000000000000000000000000000000030146080604052600436106100f45760003560e01c8063b61b127d11610096578063c91e11df11610070578063c91e11df14610183578063d91525db1461018e578063f0608b1c14610199578063f6ab3de5146101a457600080fd5b8063b61b127d14610162578063b7817da01461016d578063bc50c0051461017857600080fd5b80637320cb17116100d25780637320cb1714610136578063744795b914610141578063751afe2c1461014c57806394804c691461015757600080fd5b806301c19530146100f9578063040e51831461012057806369094cbc1461012b575b600080fd5b610104634320000181565b6040516001600160a01b03909116815260200160405180910390f35b610104634210000381565b610104634201000181565b610104634203000081565b610104634010000181565b610104634210003781565b610104634210000181565b610104634210000081565b610104634202000081565b610104634210000281565b610104634203000181565b610104634201000081565b610104634300000181565b61010463420200018156fea164736f6c6343000813000a"
"object": "0x73000000000000000000000000000000000000000030146080604052600436106100f45760003560e01c8063ad05aae411610096578063c91e11df11610070578063c91e11df14610183578063d91525db1461018e578063f057975914610199578063f0608b1c146101a457600080fd5b8063ad05aae414610162578063b61b127d1461016d578063bc50c0051461017857600080fd5b80637320cb17116100d25780637320cb1714610136578063744795b914610141578063751afe2c1461014c57806394804c691461015757600080fd5b806301c19530146100f9578063040e51831461012057806369094cbc1461012b575b600080fd5b610104634320000181565b6040516001600160a01b03909116815260200160405180910390f35b610104634210000381565b610104634201000181565b610104634203000081565b610104634010000181565b610104634210003781565b610104634210000181565b610104634202000081565b610104634210000081565b610104634210000281565b610104634203000181565b610104634201000081565b610104634202000181565b61010463430000018156fea164736f6c6343000813000a"
},
"bytecode": {
"object": "0x6101bc61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100f45760003560e01c8063b61b127d11610096578063c91e11df11610070578063c91e11df14610183578063d91525db1461018e578063f0608b1c14610199578063f6ab3de5146101a457600080fd5b8063b61b127d14610162578063b7817da01461016d578063bc50c0051461017857600080fd5b80637320cb17116100d25780637320cb1714610136578063744795b914610141578063751afe2c1461014c57806394804c691461015757600080fd5b806301c19530146100f9578063040e51831461012057806369094cbc1461012b575b600080fd5b610104634320000181565b6040516001600160a01b03909116815260200160405180910390f35b610104634210000381565b610104634201000181565b610104634203000081565b610104634010000181565b610104634210003781565b610104634210000181565b610104634210000081565b610104634202000081565b610104634210000281565b610104634203000181565b610104634201000081565b610104634300000181565b61010463420200018156fea164736f6c6343000813000a"
"object": "0x6101bc61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100f45760003560e01c8063ad05aae411610096578063c91e11df11610070578063c91e11df14610183578063d91525db1461018e578063f057975914610199578063f0608b1c146101a457600080fd5b8063ad05aae414610162578063b61b127d1461016d578063bc50c0051461017857600080fd5b80637320cb17116100d25780637320cb1714610136578063744795b914610141578063751afe2c1461014c57806394804c691461015757600080fd5b806301c19530146100f9578063040e51831461012057806369094cbc1461012b575b600080fd5b610104634320000181565b6040516001600160a01b03909116815260200160405180910390f35b610104634210000381565b610104634201000181565b610104634203000081565b610104634010000181565b610104634210003781565b610104634210000181565b610104634202000081565b610104634210000081565b610104634210000281565b610104634203000181565b610104634201000081565b610104634202000181565b61010463430000018156fea164736f6c6343000813000a"
}
}
Loading

0 comments on commit b328d64

Please sign in to comment.