Skip to content

Commit

Permalink
rollback unwanted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsachiherman committed Oct 1, 2024
1 parent 693b7c0 commit 0da1d84
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
2 changes: 1 addition & 1 deletion examples/vmwithcontracts/actions/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/consts"
"github.com/ava-labs/hypersdk/examples/vmwithcontracts/storage"
"github.com/ava-labs/hypersdk/state"
"github.com/ava-labs/hypersdk/x/contracts/runtime"

mconsts "github.com/ava-labs/hypersdk/examples/vmwithcontracts/consts"
"github.com/ava-labs/hypersdk/examples/vmwithcontracts/storage"
)

var _ chain.Action = (*Call)(nil)
Expand Down
22 changes: 0 additions & 22 deletions examples/vmwithcontracts/storage/programs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"github.com/ava-labs/hypersdk/x/contracts/runtime"
)

var ErrUnpermissionedKeyAccessed = errors.New("unpermissioned key accessed")

// [accountStatePrefix] + [account]
func accountStateKey(account codec.Address) (k []byte) {
k = make([]byte, 2+codec.AddressLen)
Expand Down Expand Up @@ -62,14 +60,6 @@ var _ runtime.StateManager = (*ContractStateManager)(nil)

type ContractStateManager struct {
state.Mutable
limitStateKeys map[string]state.Permissions
}

func NewContractStateManager(mu state.Mutable, limitStateKeys map[string]state.Permissions) *ContractStateManager {
return &ContractStateManager{
Mutable: mu,
limitStateKeys: limitStateKeys,
}
}

func (p *ContractStateManager) GetBalance(ctx context.Context, address codec.Address) (uint64, error) {
Expand All @@ -91,9 +81,6 @@ func (p *ContractStateManager) GetContractState(address codec.Address) state.Mut

func (p *ContractStateManager) GetAccountContract(ctx context.Context, account codec.Address) (runtime.ContractID, error) {
key, _ := keys.Encode(AccountContractKey(account), 36)
if perm, has := p.limitStateKeys[string(key)]; has && !perm.Has(state.Read) {
return ids.Empty[:], ErrUnpermissionedKeyAccessed
}
result, err := p.GetValue(ctx, key)
if err != nil {
return ids.Empty[:], err
Expand All @@ -102,18 +89,12 @@ func (p *ContractStateManager) GetAccountContract(ctx context.Context, account c
}

func (p *ContractStateManager) GetContractBytes(ctx context.Context, contractID runtime.ContractID) ([]byte, error) {
if perm, has := p.limitStateKeys[string(contractID)]; has && !perm.Has(state.Read) {
return ids.Empty[:], ErrUnpermissionedKeyAccessed
}
return p.GetValue(ctx, contractID)
}

func (p *ContractStateManager) NewAccountWithContract(ctx context.Context, contractID runtime.ContractID, accountCreationData []byte) (codec.Address, error) {
newAddress := GetAddressForDeploy(0, accountCreationData)
key, _ := keys.Encode(AccountContractKey(newAddress), 36)
if perm, has := p.limitStateKeys[string(contractID)]; has && !perm.Has(state.Read) {
return codec.EmptyAddress, ErrUnpermissionedKeyAccessed
}
_, err := p.GetValue(ctx, key)
if err != nil && !errors.Is(err, database.ErrNotFound) {
return codec.EmptyAddress, err
Expand All @@ -126,9 +107,6 @@ func (p *ContractStateManager) NewAccountWithContract(ctx context.Context, contr

func (p *ContractStateManager) SetAccountContract(ctx context.Context, account codec.Address, contractID runtime.ContractID) error {
key, _ := keys.Encode(AccountContractKey(account), 36)
if perm, has := p.limitStateKeys[string(key)]; has && !perm.Has(state.Write) && !perm.Has(state.Allocate) {
return ErrUnpermissionedKeyAccessed
}
return p.Insert(ctx, key, contractID)
}

Expand Down

0 comments on commit 0da1d84

Please sign in to comment.