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

GetStorageAt with whitelist for proxies deployment #1987

Merged
merged 12 commits into from
Jul 16, 2024
7 changes: 4 additions & 3 deletions go/common/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type Enclave interface {
// GetCode returns the code stored at the given address in the state for the given rollup hash.
GetCode(ctx context.Context, address gethcommon.Address, rollupHash *gethcommon.Hash) ([]byte, SystemError)

GetStorageSlot(ctx context.Context, encryptedParams EncryptedParamsGetStorageSlot) (*responses.EnclaveResponse, SystemError)

// Subscribe adds a log subscription to the enclave under the given ID, provided the request is authenticated
// correctly. The events will be populated in the BlockSubmissionResponse. If there is an existing subscription
// with the given ID, it is overwritten.
Expand Down Expand Up @@ -141,9 +143,8 @@ type EnclaveScan interface {
// GetTotalContractCount returns the total number of contracts that have been deployed
GetTotalContractCount(context.Context) (*big.Int, SystemError)

// GetCustomQuery returns the data of a custom query
// todo - better name and description
GetCustomQuery(ctx context.Context, encryptedParams EncryptedParamsGetStorageAt) (*responses.PrivateQueryResponse, SystemError)
// GetPersonalTransactions returns the user's recent transactions according to specified pagination
GetPersonalTransactions(ctx context.Context, encryptedParams EncryptedParamsGetPersonalTransactions) (*responses.PersonalTransactionsResponse, SystemError)

// EnclavePublicConfig returns network data that is known to the enclave but can be shared publicly
EnclavePublicConfig(context.Context) (*EnclavePublicConfig, SystemError)
Expand Down
14 changes: 2 additions & 12 deletions go/common/gethencoding/geth_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,10 @@ func (enc *gethEncodingServiceImpl) CreateEthBlockFromBatch(ctx context.Context,
return (*types.Block)(unsafe.Pointer(&lb)), nil
}

// ExtractPrivateCustomQuery is designed to support a wide range of custom Ten queries.
// ExtractPrivateTransactionsQuery is designed to support a wide range of custom Ten queries.
// The first parameter here is the method name, which is used to determine the query type.
// The second parameter is the query parameters.
func ExtractPrivateCustomQuery(methodName any, queryParams any) (*common.ListPrivateTransactionsQueryParams, error) {
// we expect the first parameter to be a string
methodNameStr, ok := methodName.(string)
if !ok {
return nil, fmt.Errorf("expected methodName as string but was type %T", methodName)
}
// currently we only have to support this custom query method in the enclave
if methodNameStr != common.ListPrivateTransactionsCQMethod {
return nil, fmt.Errorf("unsupported method %s", methodNameStr)
}

func ExtractPrivateTransactionsQuery(methodName any, queryParams any) (*common.ListPrivateTransactionsQueryParams, error) {
// we expect second param to be a json string
queryParamsStr, ok := queryParams.(string)
if !ok {
Expand Down
40 changes: 40 additions & 0 deletions go/common/privacy/whitelist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package privacy

import (
"math/big"

"github.com/ethereum/go-ethereum/crypto"
)

type Whitelist struct {
AllowedStorageSlots map[string]bool
}

func NewWhitelist() *Whitelist {
whitelistMap := make(map[string]bool)
whitelistMap[toEip1967HashHex("eip1967.proxy.beacon")] = true
whitelistMap[toEip1967HashHex("eip1967.proxy.implementation")] = true
whitelistMap[toEip1967FallbackHashHex("org.zeppelinos.proxy.implementation")] = true
whitelistMap[toEip1967HashHex("eip1967.proxy.admin")] = true
whitelistMap[toEip1967FallbackHashHex("org.zeppelinos.proxy.admin")] = true

return &Whitelist{
AllowedStorageSlots: whitelistMap,
}
}

func toEip1967HashHex(key string) string {
hash := crypto.Keccak256Hash([]byte(key))
hashAsBig := hash.Big()
eipHashHex := "0x" + hashAsBig.Sub(hashAsBig, big.NewInt(1)).Text(16)

return eipHashHex
}

func toEip1967FallbackHashHex(key string) string {
hash := crypto.Keccak256Hash([]byte(key))
hashAsBig := hash.Big()
eipHashHex := "0x" + hashAsBig.Text(16)

return eipHashHex
}
Loading
Loading