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

Add entitlement CopyValue and require it for Account.Storage.copyValue #2765

Merged
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
1 change: 1 addition & 0 deletions encoding/ccf/ccf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7862,6 +7862,7 @@ func TestEncodeSimpleTypes(t *testing.T) {
ccf.SimpleTypeStorage: cadence.StorageType,
ccf.SimpleTypeSaveValue: cadence.SaveValueType,
ccf.SimpleTypeLoadValue: cadence.LoadValueType,
ccf.SimpleTypeCopyValue: cadence.CopyValueType,
ccf.SimpleTypeBorrowValue: cadence.BorrowValueType,
ccf.SimpleTypeContracts: cadence.ContractsType,
ccf.SimpleTypeAddContract: cadence.AddContractType,
Expand Down
5 changes: 5 additions & 0 deletions encoding/ccf/simpletype.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const ( // Cadence simple type IDs
SimpleTypeStorage
SimpleTypeSaveValue
SimpleTypeLoadValue
SimpleTypeCopyValue
SimpleTypeBorrowValue
SimpleTypeContracts
SimpleTypeAddContract
Expand Down Expand Up @@ -275,6 +276,8 @@ func simpleTypeIDByType(typ cadence.Type) (SimpleType, bool) {
return SimpleTypeSaveValue, true
case cadence.LoadValueType:
return SimpleTypeLoadValue, true
case cadence.CopyValueType:
return SimpleTypeCopyValue, true
case cadence.BorrowValueType:
return SimpleTypeBorrowValue, true
case cadence.ContractsType:
Expand Down Expand Up @@ -464,6 +467,8 @@ func typeBySimpleTypeID(simpleTypeID SimpleType) cadence.Type {
return cadence.SaveValueType
case SimpleTypeLoadValue:
return cadence.LoadValueType
case SimpleTypeCopyValue:
return cadence.CopyValueType
case SimpleTypeBorrowValue:
return cadence.BorrowValueType
case SimpleTypeContracts:
Expand Down
55 changes: 28 additions & 27 deletions encoding/ccf/simpletype_string.go

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

2 changes: 2 additions & 0 deletions runtime/convertTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ func ExportMeteredType(
return cadence.SaveValueType
case sema.LoadValueType:
return cadence.LoadValueType
case sema.CopyValueType:
return cadence.CopyValueType
case sema.BorrowValueType:
return cadence.BorrowValueType
case sema.ContractsType:
Expand Down
6 changes: 6 additions & 0 deletions runtime/interpreter/primitivestatictype.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const (
PrimitiveStaticTypeStorage
PrimitiveStaticTypeSaveValue
PrimitiveStaticTypeLoadValue
PrimitiveStaticTypeCopyValue
PrimitiveStaticTypeBorrowValue
PrimitiveStaticTypeContracts
PrimitiveStaticTypeAddContract
Expand Down Expand Up @@ -351,6 +352,7 @@ func (t PrimitiveStaticType) elementSize() uint {
PrimitiveStaticTypeStorage,
PrimitiveStaticTypeSaveValue,
PrimitiveStaticTypeLoadValue,
PrimitiveStaticTypeCopyValue,
PrimitiveStaticTypeBorrowValue,
PrimitiveStaticTypeContracts,
PrimitiveStaticTypeAddContract,
Expand Down Expand Up @@ -604,6 +606,8 @@ func (t PrimitiveStaticType) SemaType() sema.Type {
return sema.SaveValueType
case PrimitiveStaticTypeLoadValue:
return sema.LoadValueType
case PrimitiveStaticTypeCopyValue:
return sema.CopyValueType
case PrimitiveStaticTypeBorrowValue:
return sema.BorrowValueType
case PrimitiveStaticTypeContracts:
Expand Down Expand Up @@ -817,6 +821,8 @@ func ConvertSemaToPrimitiveStaticType(
typ = PrimitiveStaticTypeSaveValue
case sema.LoadValueType:
typ = PrimitiveStaticTypeLoadValue
case sema.CopyValueType:
typ = PrimitiveStaticTypeCopyValue
case sema.BorrowValueType:
typ = PrimitiveStaticTypeBorrowValue
case sema.ContractsType:
Expand Down
100 changes: 51 additions & 49 deletions runtime/interpreter/primitivestatictype_string.go

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

7 changes: 6 additions & 1 deletion runtime/interpreter/statictype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ func TestPrimitiveStaticTypeCount(t *testing.T) {
// (before the PrimitiveStaticType_Count of course).
// Only update this test if you are certain your change to this enum was to append new types to the end.
t.Run("No new types added in between", func(t *testing.T) {
require.Equal(t, byte(151), byte(PrimitiveStaticType_Count))
require.Equal(t, byte(152), byte(PrimitiveStaticType_Count))
})
}

Expand Down Expand Up @@ -1289,6 +1289,11 @@ func TestStaticTypeConversion(t *testing.T) {
semaType: sema.LoadValueType,
staticType: PrimitiveStaticTypeLoadValue,
},
{
name: "CopyValue",
semaType: sema.CopyValueType,
staticType: PrimitiveStaticTypeCopyValue,
},
{
name: "BorrowValue",
semaType: sema.BorrowValueType,
Expand Down
4 changes: 3 additions & 1 deletion runtime/sema/account.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct Account {
/// The given type must not necessarily be exactly the same as the type of the copied structure.
///
/// The path must be a storage path, i.e., only the domain `storage` is allowed.
access(all)
access(Storage | CopyValue)
view fun copy<T: AnyStruct>(from: StoragePath): T?

/// Returns true if the object in account storage under the given path satisfies the given type,
Expand Down Expand Up @@ -401,6 +401,7 @@ entitlement Storage

entitlement SaveValue
entitlement LoadValue
entitlement CopyValue
entitlement BorrowValue

/* Contract entitlements */
Expand Down Expand Up @@ -449,6 +450,7 @@ entitlement mapping AccountMapping {

Storage -> SaveValue
Storage -> LoadValue
Storage -> CopyValue
Storage -> BorrowValue

Contracts -> AddContract
Expand Down
15 changes: 14 additions & 1 deletion runtime/sema/account.gen.go

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

Loading