Skip to content

Commit c9db8c7

Browse files
authored
Merge pull request #3653 from onflow/bastian/port-security-fixes
2 parents ea09836 + bc01ae1 commit c9db8c7

19 files changed

+482
-484
lines changed

go.mod

+7-6
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ require (
2222
github.com/turbolent/prettier v0.0.0-20220320183459-661cc755135d
2323
go.opentelemetry.io/otel v1.8.0
2424
go.uber.org/goleak v1.1.10
25-
golang.org/x/crypto v0.1.0
26-
golang.org/x/mod v0.14.0
27-
golang.org/x/text v0.4.0
28-
golang.org/x/tools v0.16.0
25+
golang.org/x/crypto v0.28.0
26+
golang.org/x/mod v0.17.0
27+
golang.org/x/text v0.19.0
28+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
2929
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
3030
)
3131

@@ -56,8 +56,9 @@ require (
5656
github.com/zeebo/assert v1.3.0 // indirect
5757
github.com/zeebo/blake3 v0.2.3 // indirect
5858
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
59-
golang.org/x/sys v0.15.0 // indirect
60-
golang.org/x/term v0.6.0 // indirect
59+
golang.org/x/sync v0.8.0 // indirect
60+
golang.org/x/sys v0.26.0 // indirect
61+
golang.org/x/term v0.25.0 // indirect
6162
gonum.org/v1/gonum v0.6.1 // indirect
6263
gopkg.in/yaml.v3 v3.0.1 // indirect
6364
)

go.sum

+16-15
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c/go.mod h1:TA1x
2323
github.com/fxamacker/circlehash v0.3.0 h1:XKdvTtIJV9t7DDUtsf0RIpC1OcxZtPbmgIH7ekx28WA=
2424
github.com/fxamacker/circlehash v0.3.0/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM=
2525
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
26-
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
27-
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
26+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
27+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
2828
github.com/itchyny/gojq v0.12.14 h1:6k8vVtsrhQSYgSGg827AD+PVVaB1NLXEdX+dda2oZCc=
2929
github.com/itchyny/gojq v0.12.14/go.mod h1:y1G7oO7XkcR1LPZO59KyoCRy08T3j9vDYRV0GgYSS+s=
3030
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
@@ -121,8 +121,8 @@ go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
121121
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
122122
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
123123
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
124-
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
125-
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
124+
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
125+
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
126126
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
127127
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
128128
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -133,8 +133,8 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl
133133
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
134134
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
135135
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
136-
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
137-
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
136+
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
137+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
138138
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
139139
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
140140
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@@ -143,8 +143,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
143143
golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
144144
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
145145
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
146-
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
147-
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
146+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
147+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
148148
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
149149
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
150150
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -157,20 +157,21 @@ golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7w
157157
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
158158
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
159159
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
160-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
161-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
162-
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
160+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
161+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
163162
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
163+
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
164+
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
164165
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
165-
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
166-
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
166+
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
167+
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
167168
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
168169
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
169170
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
170171
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
171172
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
172-
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
173-
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
173+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
174+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
174175
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
175176
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
176177
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=

runtime/ast/expression.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ func FunctionDocument(
14161416
}
14171417

14181418
// NOTE: not all functions have a parameter list,
1419-
// e.g. the `destroy` special function
1419+
// e.g. the `init` (initializer, special function)
14201420
if parameterList != nil {
14211421

14221422
signatureDoc = append(

runtime/contract_update_validation_test.go

+66-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func newContractRemovalTransaction(contractName string) string {
8383
}
8484

8585
func newContractDeploymentTransactor(t *testing.T, config Config) func(code string) error {
86+
return newContractDeploymentTransactorWithVersion(t, config, "")
87+
}
88+
89+
func newContractDeploymentTransactorWithVersion(t *testing.T, config Config, version string) func(code string) error {
8690

8791
rt := NewTestInterpreterRuntimeWithConfig(config)
8892

@@ -112,6 +116,9 @@ func newContractDeploymentTransactor(t *testing.T, config Config) func(code stri
112116
events = append(events, event)
113117
return nil
114118
},
119+
OnMinimumRequiredVersion: func() (string, error) {
120+
return version, nil
121+
},
115122
}
116123

117124
nextTransactionLocation := NewTransactionLocationGenerator()
@@ -132,7 +139,18 @@ func newContractDeploymentTransactor(t *testing.T, config Config) func(code stri
132139
// testDeployAndUpdate deploys a contract in one transaction,
133140
// then updates the contract in another transaction
134141
func testDeployAndUpdate(t *testing.T, name string, oldCode string, newCode string, config Config) error {
135-
executeTransaction := newContractDeploymentTransactor(t, config)
142+
return testDeployAndUpdateWithVersion(t, name, oldCode, newCode, config, "")
143+
}
144+
145+
func testDeployAndUpdateWithVersion(
146+
t *testing.T,
147+
name string,
148+
oldCode string,
149+
newCode string,
150+
config Config,
151+
version string,
152+
) error {
153+
executeTransaction := newContractDeploymentTransactorWithVersion(t, config, version)
136154
err := executeTransaction(newContractAddTransaction(name, oldCode))
137155
require.NoError(t, err)
138156

@@ -3666,3 +3684,50 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
36663684
},
36673685
)
36683686
}
3687+
3688+
func TestAttachmentsUpdates(t *testing.T) {
3689+
t.Parallel()
3690+
3691+
testWithValidators(t,
3692+
"Keep base type",
3693+
func(t *testing.T, config Config) {
3694+
3695+
const oldCode = `
3696+
access(all) contract Test {
3697+
access(all) attachment A for AnyResource {}
3698+
}
3699+
`
3700+
3701+
const newCode = `
3702+
access(all) contract Test {
3703+
access(all) attachment A for AnyResource {}
3704+
}
3705+
`
3706+
3707+
err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)
3708+
require.NoError(t, err)
3709+
},
3710+
)
3711+
3712+
testWithValidators(t,
3713+
"Change base type",
3714+
func(t *testing.T, config Config) {
3715+
3716+
const oldCode = `
3717+
access(all) contract Test {
3718+
access(all) attachment A for AnyResource {}
3719+
}
3720+
`
3721+
3722+
const newCode = `
3723+
access(all) contract Test {
3724+
access(all) attachment A for AnyStruct {}
3725+
}
3726+
`
3727+
3728+
err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)
3729+
3730+
var expectedErr *stdlib.TypeMismatchError
3731+
require.ErrorAs(t, err, &expectedErr)
3732+
})
3733+
}

runtime/empty.go

+4
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,7 @@ func (EmptyRuntimeInterface) ValidateAccountCapabilitiesPublish(
260260
) (bool, error) {
261261
panic("unexpected call to ValidateAccountCapabilitiesPublish")
262262
}
263+
264+
func (EmptyRuntimeInterface) MinimumRequiredVersion() (string, error) {
265+
return "0.0.0", nil
266+
}

runtime/environment.go

+18
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ func (e *interpreterEnvironment) Configure(
241241
e.InterpreterConfig.Storage = storage
242242
e.coverageReport = coverageReport
243243
e.stackDepthLimiter.depth = 0
244+
245+
e.configureVersionedFeatures()
244246
}
245247

246248
func (e *interpreterEnvironment) DeclareValue(valueDeclaration stdlib.StandardLibraryValue, location common.Location) {
@@ -1458,3 +1460,19 @@ func (e *interpreterEnvironment) newValidateAccountCapabilitiesPublishHandler()
14581460
return ok, err
14591461
}
14601462
}
1463+
1464+
func (e *interpreterEnvironment) configureVersionedFeatures() {
1465+
var (
1466+
minimumRequiredVersion string
1467+
err error
1468+
)
1469+
errors.WrapPanic(func() {
1470+
minimumRequiredVersion, err = e.runtimeInterface.MinimumRequiredVersion()
1471+
})
1472+
if err != nil {
1473+
panic(err)
1474+
}
1475+
1476+
// No feature flags yet
1477+
_ = minimumRequiredVersion
1478+
}

runtime/interface.go

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ type Interface interface {
161161
path interpreter.PathValue,
162162
capabilityBorrowType *interpreter.ReferenceStaticType,
163163
) (bool, error)
164+
165+
MinimumRequiredVersion() (string, error)
164166
}
165167

166168
type MeterInterface interface {

runtime/runtime_test.go

+68
Original file line numberDiff line numberDiff line change
@@ -11480,3 +11480,71 @@ func TestRuntimeStorageEnumAsDictionaryKey(t *testing.T) {
1148011480
loggedMessages,
1148111481
)
1148211482
}
11483+
11484+
func TestRuntimeBuiltInFunctionConfusion(t *testing.T) {
11485+
11486+
t.Parallel()
11487+
11488+
const contract = `
11489+
access(all) contract Foo {
11490+
access(all) resource getType {}
11491+
11492+
init() {
11493+
Foo.getType()
11494+
}
11495+
}
11496+
`
11497+
11498+
address := common.MustBytesToAddress([]byte{0x1})
11499+
11500+
newRuntimeInterface := func() Interface {
11501+
11502+
accountCodes := map[common.AddressLocation][]byte{}
11503+
var events []cadence.Event
11504+
var loggedMessages []string
11505+
11506+
return &TestRuntimeInterface{
11507+
Storage: NewTestLedger(nil, nil),
11508+
OnGetSigningAccounts: func() ([]common.Address, error) {
11509+
return []common.Address{address}, nil
11510+
},
11511+
OnResolveLocation: NewSingleIdentifierLocationResolver(t),
11512+
OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
11513+
accountCodes[location] = code
11514+
return nil
11515+
},
11516+
OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
11517+
code = accountCodes[location]
11518+
return code, nil
11519+
},
11520+
OnEmitEvent: func(event cadence.Event) error {
11521+
events = append(events, event)
11522+
return nil
11523+
},
11524+
OnProgramLog: func(message string) {
11525+
loggedMessages = append(loggedMessages, message)
11526+
},
11527+
}
11528+
}
11529+
11530+
runtime := NewTestInterpreterRuntime()
11531+
11532+
nextTransactionLocation := NewTransactionLocationGenerator()
11533+
11534+
err := runtime.ExecuteTransaction(
11535+
Script{
11536+
Source: DeploymentTransaction(
11537+
"Foo",
11538+
[]byte(contract),
11539+
),
11540+
},
11541+
Context{
11542+
Interface: newRuntimeInterface(),
11543+
Location: nextTransactionLocation(),
11544+
},
11545+
)
11546+
RequireError(t, err)
11547+
11548+
var redeclarationError *sema.RedeclarationError
11549+
require.ErrorAs(t, err, &redeclarationError)
11550+
}

0 commit comments

Comments
 (0)