From ff1b1baf6d0725824375b3997b8dff30591d3975 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 20 Sep 2024 12:21:18 +0100 Subject: [PATCH] allow storage at for transparnet contracts (#2059) * allow storage at for transparnet contracts * fix --- go/enclave/rpc/TenStorageRead.go | 11 +++++++++-- go/enclave/storage/interfaces.go | 4 +++- go/enclave/storage/storage.go | 9 +++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/go/enclave/rpc/TenStorageRead.go b/go/enclave/rpc/TenStorageRead.go index 0de76e6470..1fee8dff54 100644 --- a/go/enclave/rpc/TenStorageRead.go +++ b/go/enclave/rpc/TenStorageRead.go @@ -37,8 +37,15 @@ func TenStorageReadValidate(reqParams []any, builder *CallBuilder[storageReadWit return nil } - if !rpc.whitelist.AllowedStorageSlots[slot] { - builder.Err = fmt.Errorf("eth_getStorageAt is not supported on TEN") + contract, err := rpc.storage.ReadContract(builder.ctx, *address) + if err != nil { + builder.Err = fmt.Errorf("eth_getStorageAt is not supported for this contract") + return nil + } + + // block the call for un-transparent contracts and non-whitelisted slots + if !rpc.whitelist.AllowedStorageSlots[slot] && !contract.IsTransparent() { + builder.Err = fmt.Errorf("eth_getStorageAt is not supported for this contract") return nil } diff --git a/go/enclave/storage/interfaces.go b/go/enclave/storage/interfaces.go index d1629fc426..5bf5107be8 100644 --- a/go/enclave/storage/interfaces.go +++ b/go/enclave/storage/interfaces.go @@ -6,6 +6,8 @@ import ( "io" "math/big" + "github.com/ten-protocol/go-ten/go/enclave/storage/enclavedb" + "github.com/ethereum/go-ethereum/triedb" "github.com/ethereum/go-ethereum/core/state" @@ -150,7 +152,7 @@ type Storage interface { // StateDB - return the underlying state database StateDB() state.Database - ReadContractCreator(ctx context.Context, address gethcommon.Address) (*gethcommon.Address, error) + ReadContract(ctx context.Context, address gethcommon.Address) (*enclavedb.Contract, error) } type ScanStorage interface { diff --git a/go/enclave/storage/storage.go b/go/enclave/storage/storage.go index caba3d462a..6d372f3f0f 100644 --- a/go/enclave/storage/storage.go +++ b/go/enclave/storage/storage.go @@ -803,8 +803,13 @@ func (s *storageImpl) readOrWriteEOA(ctx context.Context, dbTX *sql.Tx, addr get }) } -func (s *storageImpl) ReadContractCreator(ctx context.Context, address gethcommon.Address) (*gethcommon.Address, error) { - return enclavedb.ReadContractCreator(ctx, s.db.GetSQLDB(), address) +func (s *storageImpl) ReadContract(ctx context.Context, address gethcommon.Address) (*enclavedb.Contract, error) { + dbtx, err := s.db.GetSQLDB().BeginTx(ctx, nil) + if err != nil { + return nil, err + } + defer dbtx.Rollback() + return enclavedb.ReadContractByAddress(ctx, dbtx, address) } func (s *storageImpl) logDuration(method string, stopWatch *measure.Stopwatch) {