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

allow storage at for transparnet contracts #2059

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions go/enclave/rpc/TenStorageRead.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion go/enclave/storage/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions go/enclave/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down