Skip to content

Commit

Permalink
working renames
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarzzz committed Dec 15, 2023
1 parent f3bb216 commit ea6a831
Show file tree
Hide file tree
Showing 33 changed files with 604 additions and 563 deletions.
22 changes: 11 additions & 11 deletions core/types/suave_structs.go

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

18 changes: 9 additions & 9 deletions core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (b *suaveRuntime) confidentialInputs() ([]byte, error) {

/* Confidential store precompiles */

func (b *suaveRuntime) confidentialStore(bidId types.BidId, key string, data []byte) error {
bid, err := b.suaveContext.Backend.ConfidentialStore.FetchBidById(bidId)
func (b *suaveRuntime) confidentialStore(bidId types.DataId, key string, data []byte) error {
bid, err := b.suaveContext.Backend.ConfidentialStore.FetchBidByID(bidId)
if err != nil {
return suave.ErrBidNotFound
}
Expand All @@ -54,8 +54,8 @@ func (b *suaveRuntime) confidentialStore(bidId types.BidId, key string, data []b
return nil
}

func (b *suaveRuntime) confidentialRetrieve(bidId types.BidId, key string) ([]byte, error) {
bid, err := b.suaveContext.Backend.ConfidentialStore.FetchBidById(bidId)
func (b *suaveRuntime) confidentialRetrieve(bidId types.DataId, key string) ([]byte, error) {
bid, err := b.suaveContext.Backend.ConfidentialStore.FetchBidByID(bidId)
if err != nil {
return nil, suave.ErrBidNotFound
}
Expand All @@ -79,29 +79,29 @@ func (b *suaveRuntime) confidentialRetrieve(bidId types.BidId, key string) ([]by

/* Bid precompiles */

func (b *suaveRuntime) newBid(decryptionCondition uint64, allowedPeekers []common.Address, allowedStores []common.Address, BidType string) (types.Bid, error) {
func (b *suaveRuntime) newDataRecord(decryptionCondition uint64, allowedPeekers []common.Address, allowedStores []common.Address, BidType string) (types.DataRecord, error) {
if b.suaveContext.ConfidentialComputeRequestTx == nil {
panic("newBid: source transaction not present")
}

bid, err := b.suaveContext.Backend.ConfidentialStore.InitializeBid(types.Bid{
bid, err := b.suaveContext.Backend.ConfidentialStore.InitializeBid(types.DataRecord{
Salt: suave.RandomBidId(),
DecryptionCondition: decryptionCondition,
AllowedPeekers: allowedPeekers,
AllowedStores: allowedStores,
Version: BidType, // TODO : make generic
})
if err != nil {
return types.Bid{}, err
return types.DataRecord{}, err
}

return bid, nil
}

func (b *suaveRuntime) fetchBids(targetBlock uint64, namespace string) ([]types.Bid, error) {
func (b *suaveRuntime) fetchDataRecords(targetBlock uint64, namespace string) ([]types.DataRecord, error) {
bids1 := b.suaveContext.Backend.ConfidentialStore.FetchBidsByProtocolAndBlock(targetBlock, namespace)

bids := make([]types.Bid, 0, len(bids1))
bids := make([]types.DataRecord, 0, len(bids1))
for _, bid := range bids1 {
bids = append(bids, bid.ToInnerBid())
}
Expand Down
25 changes: 17 additions & 8 deletions core/vm/contracts_suave_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func (b *suaveRuntime) ethcall(contractAddr common.Address, input []byte) ([]byt
return b.suaveContext.Backend.ConfidentialEthBackend.Call(context.Background(), contractAddr, input)
}

func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, bidId types.BidId, namespace string) ([]byte, []byte, error) {
func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, bidId types.DataId, namespace string) ([]byte, []byte, error) {
bidIds := [][16]byte{}
// first check for merged bid, else assume regular bid
if mergedBidsBytes, err := b.suaveContext.Backend.ConfidentialStore.Retrieve(bidId, buildEthBlockAddr, "default:v0:mergedBids"); err == nil {
if mergedBidsBytes, err := b.suaveContext.Backend.ConfidentialStore.Retrieve(bidId, buildEthBlockAddr, "default:v0:mergedDataRecords"); err == nil {
unpacked, err := bidIdsAbi.Inputs.Unpack(mergedBidsBytes)

if err != nil {
Expand All @@ -126,11 +126,11 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, bidId types
bidIds = append(bidIds, bidId)
}

var bidsToMerge = make([]types.Bid, len(bidIds))
var bidsToMerge = make([]types.DataRecord, len(bidIds))
for i, bidId := range bidIds {
var err error

bid, err := b.suaveContext.Backend.ConfidentialStore.FetchBidById(bidId)
bid, err := b.suaveContext.Backend.ConfidentialStore.FetchBidByID(bidId)
if err != nil {
return nil, nil, fmt.Errorf("could not fetch bid id %v: %w", bidId, err)
}
Expand All @@ -147,7 +147,7 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, bidId types
switch bid.Version {
case "mevshare:v0:matchBids":
// fetch the matched ids and merge the bundle
matchedBundleIdsBytes, err := b.suaveContext.Backend.ConfidentialStore.Retrieve(bid.Id, buildEthBlockAddr, "mevshare:v0:mergedBids")
matchedBundleIdsBytes, err := b.suaveContext.Backend.ConfidentialStore.Retrieve(bid.Id, buildEthBlockAddr, "mevshare:v0:mergedDataRecords")
if err != nil {
return nil, nil, fmt.Errorf("could not retrieve bid ids data for bid %v, from cdas: %w", bid, err)
}
Expand Down Expand Up @@ -407,45 +407,53 @@ func (c *suaveRuntime) submitBundleJsonRPC(url string, method string, params []b
return nil, nil
}

func (c *suaveRuntime) fillMevShareBundle(bidId types.BidId) ([]byte, error) {
bid, err := c.suaveContext.Backend.ConfidentialStore.FetchBidById(bidId)
func (c *suaveRuntime) fillMevShareBundle(bidId types.DataId) ([]byte, error) {
bid, err := c.suaveContext.Backend.ConfidentialStore.FetchBidByID(bidId)
if err != nil {
fmt.Println(err.Error())
return nil, err
}

if _, err := checkIsPrecompileCallAllowed(c.suaveContext, fillMevShareBundleAddr, bid); err != nil {
fmt.Println(err.Error())
return nil, err
}

matchedBundleIdsBytes, err := c.confidentialRetrieve(bidId, "mevshare:v0:mergedBids")
matchedBundleIdsBytes, err := c.confidentialRetrieve(bidId, "mevshare:v0:mergedDataRecords")
if err != nil {
fmt.Println(err.Error())
return nil, err
}

unpackedBidIds, err := bidIdsAbi.Inputs.Unpack(matchedBundleIdsBytes)
if err != nil {
fmt.Println(err.Error())
return nil, fmt.Errorf("could not unpack bid ids data for bid %v, from cdas: %w", bid, err)
}

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

userBundleBytes, err := c.confidentialRetrieve(matchBidIds[0], "mevshare:v0:ethBundles")
if err != nil {
fmt.Println(err.Error())
return nil, fmt.Errorf("could not retrieve bundle data for bidId %v: %w", matchBidIds[0], err)
}

var userBundle types.SBundle
if err := json.Unmarshal(userBundleBytes, &userBundle); err != nil {
fmt.Println(err.Error())
return nil, fmt.Errorf("could not unmarshal user bundle data for bidId %v: %w", matchBidIds[0], err)
}

matchBundleBytes, err := c.confidentialRetrieve(matchBidIds[1], "mevshare:v0:ethBundles")
if err != nil {
fmt.Println(err.Error())
return nil, fmt.Errorf("could not retrieve match bundle data for bidId %v: %w", matchBidIds[1], err)
}

var matchBundle types.SBundle
if err := json.Unmarshal(matchBundleBytes, &matchBundle); err != nil {
fmt.Println(err.Error())
return nil, fmt.Errorf("could not unmarshal match bundle data for bidId %v: %w", matchBidIds[1], err)
}

Expand All @@ -459,6 +467,7 @@ func (c *suaveRuntime) fillMevShareBundle(bidId types.BidId) ([]byte, error) {
for _, tx := range append(userBundle.Txs, matchBundle.Txs...) {
txBytes, err := tx.MarshalBinary()
if err != nil {
fmt.Println(err.Error())
return nil, fmt.Errorf("could not marshal transaction: %w", err)
}

Expand Down
Loading

0 comments on commit ea6a831

Please sign in to comment.