From 340772755ceafd4ee03797540686f780cd79cd3d Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Mon, 12 Aug 2024 18:30:50 -0700 Subject: [PATCH 1/2] Add capability stored path info to the report --- migrations/capcons/capabilitymigration.go | 3 ++- migrations/capcons/migration_test.go | 30 +++++++++++++++++------ migrations/capcons/storagecapmigration.go | 19 ++++++++------ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/migrations/capcons/capabilitymigration.go b/migrations/capcons/capabilitymigration.go index b664e4b58a..ed7298ce43 100644 --- a/migrations/capcons/capabilitymigration.go +++ b/migrations/capcons/capabilitymigration.go @@ -39,7 +39,8 @@ type CapabilityMigrationReporter interface { ) MissingBorrowType( accountAddress common.Address, - addressPath interpreter.AddressPath, + targetPath interpreter.AddressPath, + storedPath Path, ) } diff --git a/migrations/capcons/migration_test.go b/migrations/capcons/migration_test.go index 9834cbb1e3..14d6c9d9cf 100644 --- a/migrations/capcons/migration_test.go +++ b/migrations/capcons/migration_test.go @@ -100,13 +100,15 @@ type testStorageCapConIssued struct { type testStorageCapConsMissingBorrowType struct { accountAddress common.Address - addressPath interpreter.AddressPath + targetPath interpreter.AddressPath + storedPath Path } type testStorageCapConsInferredBorrowType struct { accountAddress common.Address - addressPath interpreter.AddressPath + targetPath interpreter.AddressPath borrowType *interpreter.ReferenceStaticType + storedPath Path } type testMigration struct { @@ -196,28 +198,32 @@ func (t *testMigrationReporter) MissingCapabilityID( func (t *testMigrationReporter) MissingBorrowType( accountAddress common.Address, - addressPath interpreter.AddressPath, + targetPath interpreter.AddressPath, + storedPath Path, ) { t.missingStorageCapConBorrowTypes = append( t.missingStorageCapConBorrowTypes, testStorageCapConsMissingBorrowType{ accountAddress: accountAddress, - addressPath: addressPath, + targetPath: targetPath, + storedPath: storedPath, }, ) } func (t *testMigrationReporter) InferredMissingBorrowType( accountAddress common.Address, - addressPath interpreter.AddressPath, + targetPath interpreter.AddressPath, borrowType *interpreter.ReferenceStaticType, + storedPath Path, ) { t.inferredStorageCapConBorrowTypes = append( t.inferredStorageCapConBorrowTypes, testStorageCapConsInferredBorrowType{ accountAddress: accountAddress, - addressPath: addressPath, + targetPath: targetPath, borrowType: borrowType, + storedPath: storedPath, }, ) } @@ -3414,12 +3420,16 @@ func TestUntypedStorageCapMigration(t *testing.T) { []testStorageCapConsInferredBorrowType{ { accountAddress: testAddress, - addressPath: testAddressPath, + targetPath: testAddressPath, borrowType: interpreter.NewReferenceStaticType( nil, inferredAuth, interpreter.PrimitiveStaticTypeString, ), + storedPath: Path{ + Domain: "storage", + Path: "cap", + }, }, }, reporter.inferredStorageCapConBorrowTypes, @@ -3633,10 +3643,14 @@ func TestUntypedStorageCapWithMissingTargetMigration(t *testing.T) { []testStorageCapConsMissingBorrowType{ { accountAddress: addressA, - addressPath: interpreter.AddressPath{ + targetPath: interpreter.AddressPath{ Address: addressA, Path: targetPath, }, + storedPath: Path{ + Domain: "storage", + Path: "cap", + }, }, }, reporter.missingStorageCapConBorrowTypes, diff --git a/migrations/capcons/storagecapmigration.go b/migrations/capcons/storagecapmigration.go index 73787112fa..2e00c6dd99 100644 --- a/migrations/capcons/storagecapmigration.go +++ b/migrations/capcons/storagecapmigration.go @@ -29,7 +29,8 @@ import ( type StorageCapabilityMigrationReporter interface { MissingBorrowType( accountAddress common.Address, - addressPath interpreter.AddressPath, + targetPath interpreter.AddressPath, + storedPath Path, ) IssuedStorageCapabilityController( accountAddress common.Address, @@ -39,8 +40,9 @@ type StorageCapabilityMigrationReporter interface { ) InferredMissingBorrowType( accountAddress common.Address, - addressPath interpreter.AddressPath, + targetPath interpreter.AddressPath, borrowType *interpreter.ReferenceStaticType, + storedPath Path, ) } @@ -129,10 +131,6 @@ func IssueAccountCapabilities( borrowType = capabilityBorrowType.(*interpreter.ReferenceStaticType) } else { - if _, _, ok := untypedCapabilityMapping.Get(addressPath); ok { - continue - } - // If the borrow type is missing, then borrow it as the type of the value. path := capability.TargetPath.Identifier value := storageMap.ReadValue(nil, interpreter.StringStorageMapKey(path)) @@ -140,7 +138,7 @@ func IssueAccountCapabilities( // However, if there is no value at the target, //it is not possible to migrate this cap. if value == nil { - reporter.MissingBorrowType(address, addressPath) + reporter.MissingBorrowType(address, addressPath, capability.StoredPath) continue } @@ -152,7 +150,12 @@ func IssueAccountCapabilities( valueType, ) - reporter.InferredMissingBorrowType(address, addressPath, borrowType) + reporter.InferredMissingBorrowType( + address, + addressPath, + borrowType, + capability.StoredPath, + ) } capabilityID := stdlib.IssueStorageCapabilityController( From 0f12301ee4a7ee4cb8db24aca684d66a6e17440b Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Mon, 12 Aug 2024 20:33:22 -0700 Subject: [PATCH 2/2] Merge path and address in the report entry --- migrations/capcons/capabilitymigration.go | 3 +- migrations/capcons/migration_test.go | 70 ++++++++++++++--------- migrations/capcons/storagecapmigration.go | 25 +++++--- 3 files changed, 61 insertions(+), 37 deletions(-) diff --git a/migrations/capcons/capabilitymigration.go b/migrations/capcons/capabilitymigration.go index ed7298ce43..f2b2f76f63 100644 --- a/migrations/capcons/capabilitymigration.go +++ b/migrations/capcons/capabilitymigration.go @@ -38,9 +38,8 @@ type CapabilityMigrationReporter interface { addressPath interpreter.AddressPath, ) MissingBorrowType( - accountAddress common.Address, targetPath interpreter.AddressPath, - storedPath Path, + storedPath interpreter.AddressPath, ) } diff --git a/migrations/capcons/migration_test.go b/migrations/capcons/migration_test.go index 14d6c9d9cf..ed35a720c9 100644 --- a/migrations/capcons/migration_test.go +++ b/migrations/capcons/migration_test.go @@ -99,16 +99,14 @@ type testStorageCapConIssued struct { } type testStorageCapConsMissingBorrowType struct { - accountAddress common.Address - targetPath interpreter.AddressPath - storedPath Path + targetPath interpreter.AddressPath + storedPath interpreter.AddressPath } type testStorageCapConsInferredBorrowType struct { - accountAddress common.Address - targetPath interpreter.AddressPath - borrowType *interpreter.ReferenceStaticType - storedPath Path + targetPath interpreter.AddressPath + borrowType *interpreter.ReferenceStaticType + storedPath interpreter.AddressPath } type testMigration struct { @@ -197,33 +195,29 @@ func (t *testMigrationReporter) MissingCapabilityID( } func (t *testMigrationReporter) MissingBorrowType( - accountAddress common.Address, targetPath interpreter.AddressPath, - storedPath Path, + storedPath interpreter.AddressPath, ) { t.missingStorageCapConBorrowTypes = append( t.missingStorageCapConBorrowTypes, testStorageCapConsMissingBorrowType{ - accountAddress: accountAddress, - targetPath: targetPath, - storedPath: storedPath, + targetPath: targetPath, + storedPath: storedPath, }, ) } func (t *testMigrationReporter) InferredMissingBorrowType( - accountAddress common.Address, targetPath interpreter.AddressPath, borrowType *interpreter.ReferenceStaticType, - storedPath Path, + storedPath interpreter.AddressPath, ) { t.inferredStorageCapConBorrowTypes = append( t.inferredStorageCapConBorrowTypes, testStorageCapConsInferredBorrowType{ - accountAddress: accountAddress, - targetPath: targetPath, - borrowType: borrowType, - storedPath: storedPath, + targetPath: targetPath, + borrowType: borrowType, + storedPath: storedPath, }, ) } @@ -3396,7 +3390,23 @@ func TestUntypedStorageCapMigration(t *testing.T) { require.Empty(t, reporter.errors) require.Empty(t, reporter.missingCapabilityIDs) - require.Empty(t, reporter.missingStorageCapConBorrowTypes) + + require.Equal( + t, + []testStorageCapConsMissingBorrowType{ + { + targetPath: testAddressPath, + storedPath: interpreter.AddressPath{ + Address: testAddress, + Path: interpreter.PathValue{ + Domain: common.PathDomainStorage, + Identifier: "cap", + }, + }, + }, + }, + reporter.missingStorageCapConBorrowTypes, + ) require.Equal( t, @@ -3419,16 +3429,18 @@ func TestUntypedStorageCapMigration(t *testing.T) { t, []testStorageCapConsInferredBorrowType{ { - accountAddress: testAddress, - targetPath: testAddressPath, + targetPath: testAddressPath, borrowType: interpreter.NewReferenceStaticType( nil, inferredAuth, interpreter.PrimitiveStaticTypeString, ), - storedPath: Path{ - Domain: "storage", - Path: "cap", + storedPath: interpreter.AddressPath{ + Address: testAddress, + Path: interpreter.PathValue{ + Identifier: "cap", + Domain: common.PathDomainStorage, + }, }, }, }, @@ -3642,14 +3654,16 @@ func TestUntypedStorageCapWithMissingTargetMigration(t *testing.T) { t, []testStorageCapConsMissingBorrowType{ { - accountAddress: addressA, targetPath: interpreter.AddressPath{ Address: addressA, Path: targetPath, }, - storedPath: Path{ - Domain: "storage", - Path: "cap", + storedPath: interpreter.AddressPath{ + Address: testAddress, + Path: interpreter.PathValue{ + Identifier: "cap", + Domain: common.PathDomainStorage, + }, }, }, }, diff --git a/migrations/capcons/storagecapmigration.go b/migrations/capcons/storagecapmigration.go index 2e00c6dd99..ba95c1dd16 100644 --- a/migrations/capcons/storagecapmigration.go +++ b/migrations/capcons/storagecapmigration.go @@ -28,9 +28,8 @@ import ( type StorageCapabilityMigrationReporter interface { MissingBorrowType( - accountAddress common.Address, targetPath interpreter.AddressPath, - storedPath Path, + storedPath interpreter.AddressPath, ) IssuedStorageCapabilityController( accountAddress common.Address, @@ -39,10 +38,9 @@ type StorageCapabilityMigrationReporter interface { capabilityID interpreter.UInt64Value, ) InferredMissingBorrowType( - accountAddress common.Address, targetPath interpreter.AddressPath, borrowType *interpreter.ReferenceStaticType, - storedPath Path, + storedPath interpreter.AddressPath, ) } @@ -131,6 +129,21 @@ func IssueAccountCapabilities( borrowType = capabilityBorrowType.(*interpreter.ReferenceStaticType) } else { + targetPath := interpreter.AddressPath{ + Address: address, + Path: interpreter.PathValue{ + Identifier: capability.StoredPath.Path, + Domain: common.PathDomainFromIdentifier(capability.StoredPath.Domain), + }, + } + + // Report for all caps with missing borrow type. + reporter.MissingBorrowType(addressPath, targetPath) + + if _, _, ok := untypedCapabilityMapping.Get(addressPath); ok { + continue + } + // If the borrow type is missing, then borrow it as the type of the value. path := capability.TargetPath.Identifier value := storageMap.ReadValue(nil, interpreter.StringStorageMapKey(path)) @@ -138,7 +151,6 @@ func IssueAccountCapabilities( // However, if there is no value at the target, //it is not possible to migrate this cap. if value == nil { - reporter.MissingBorrowType(address, addressPath, capability.StoredPath) continue } @@ -151,10 +163,9 @@ func IssueAccountCapabilities( ) reporter.InferredMissingBorrowType( - address, addressPath, borrowType, - capability.StoredPath, + targetPath, ) }