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

Contract Update Validator #3069

Merged
merged 22 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c626c37
refactor update validator to allow multiple implementations of field …
dsainati1 Jan 30, 2024
c2fcb6a
add some basic tests for the upgrade validator
dsainati1 Jan 30, 2024
c222cf6
upgrade rules for intersection types
dsainati1 Jan 30, 2024
3782d87
properly plumb through arrays, dicts, and capabilities
dsainati1 Jan 30, 2024
01c2da1
in progress entitlements check
dsainati1 Jan 31, 2024
f66371d
verification for adding entitlements to references to composites
dsainati1 Jan 31, 2024
f0960d4
verification for adding entitlements on intersection -> intersection …
dsainati1 Jan 31, 2024
b0e98ce
add support for entitlements of restricted -> composite upgrade
dsainati1 Jan 31, 2024
06b3c31
add todo comment
dsainati1 Jan 31, 2024
532565d
enable removal of conformances in contract update
dsainati1 Feb 2, 2024
4d20226
Merge branch 'master' of github.com:onflow/cadence into sainati/contr…
dsainati1 Feb 2, 2024
4c5ca63
Merge branch 'sainati/port-validator-fix' of github.com:onflow/cadenc…
dsainati1 Feb 7, 2024
08bfe2d
collect imports in upgrade validator
dsainati1 Feb 7, 2024
046f5e4
Merge branch 'sainati/port-validator-fix' of github.com:onflow/cadenc…
dsainati1 Feb 7, 2024
9ec4da0
fix compile
dsainati1 Feb 7, 2024
e5989b5
Merge branch 'sainati/port-validator-fix' of github.com:onflow/cadenc…
dsainati1 Feb 7, 2024
2567340
add tests for local qualified names
dsainati1 Feb 7, 2024
ffba5e1
add tests and fix importing
dsainati1 Feb 7, 2024
ecb5e3c
Refactor
SupunS Feb 13, 2024
67411cb
Revert allowing to remove interface conformance
SupunS Feb 14, 2024
57fe5e0
Merge branch 'master' of https://github.com/onflow/cadence into saina…
SupunS Feb 15, 2024
65faf29
use getElaboration, sort locations, panic when elaboration is not ava…
turbolent Feb 22, 2024
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
3 changes: 3 additions & 0 deletions runtime/contract_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ func TestRuntimeLegacyContractUpdate(t *testing.T) {
OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
return accountCodes[location], nil
},
OnGetAccountContractNames: func(_ Address) ([]string, error) {
return []string{"Foo"}, nil
},
OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
accountCodes[location] = code
return nil
Expand Down
1 change: 0 additions & 1 deletion runtime/contract_update_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,6 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) {
RequireError(t, err)

cause := getSingleContractUpdateErrorCause(t, err, "Test")

assertConformanceMismatchError(t, cause, "Foo")
})

Expand Down
30 changes: 30 additions & 0 deletions runtime/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"math"
"math/big"
"sort"
"strconv"
"time"

Expand Down Expand Up @@ -4577,6 +4578,35 @@ func (interpreter *Interpreter) getElaboration(location common.Location) *sema.E
return subInterpreter.Program.Elaboration
}

func (interpreter *Interpreter) AllElaborations() (elaborations map[common.Location]*sema.Elaboration) {

elaborations = map[common.Location]*sema.Elaboration{}

allInterpreters := interpreter.SharedState.allInterpreters

locations := make([]common.Location, 0, len(allInterpreters))

for location := range allInterpreters { //nolint:maprange
locations = append(locations, location)
}

sort.Slice(locations, func(i, j int) bool {
a := locations[i]
b := locations[j]
return a.ID() < b.ID()
})

for _, location := range locations {
elaboration := interpreter.getElaboration(location)
if elaboration == nil {
panic(errors.NewUnexpectedError("missing elaboration for location %s", location))
}
elaborations[location] = elaboration
}

return
}

// GetContractComposite gets the composite value of the contract at the address location.
func (interpreter *Interpreter) GetContractComposite(contractLocation common.AddressLocation) (*CompositeValue, error) {
contractGlobal := interpreter.Globals.Get(contractLocation.Name)
Expand Down
8 changes: 5 additions & 3 deletions runtime/stdlib/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,8 @@ func changeAccountContracts(

// Validate the contract update

inter := invocation.Interpreter

if isUpdate {
oldCode, err := handler.GetAccountContractCode(location)
handleContractUpdateError(err)
Expand Down Expand Up @@ -1618,11 +1620,13 @@ func changeAccountContracts(

var validator UpdateValidator
if legacyContractUpgrade {
validator = NewLegacyContractUpdateValidator(
validator = NewCadenceV042ToV1ContractUpdateValidator(
location,
contractName,
handler,
oldProgram,
program.Program,
inter.AllElaborations(),
)
} else {
validator = NewContractUpdateValidator(
Expand All @@ -1637,8 +1641,6 @@ func changeAccountContracts(
handleContractUpdateError(err)
}

inter := invocation.Interpreter

err = updateAccountContractCode(
handler,
location,
Expand Down
Loading
Loading