Skip to content

Commit 9bbd4db

Browse files
authored
Merge pull request #513 from onflow/improvement/secure-cadence
Secure Cadence
2 parents 7254ac1 + 0e5be68 commit 9bbd4db

File tree

12 files changed

+218
-76
lines changed

12 files changed

+218
-76
lines changed

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ require (
99
github.com/gosuri/uilive v0.0.4
1010
github.com/joho/godotenv v1.4.0
1111
github.com/manifoldco/promptui v0.9.0
12-
github.com/onflow/cadence v0.23.3
13-
github.com/onflow/cadence/languageserver v0.18.3-0.20220202133308-207188a51831
12+
github.com/onflow/cadence v0.21.3-0.20220601002855-8b113c539a2c
13+
github.com/onflow/cadence/languageserver v0.23.5-0.20220520080030-2a9ba4e0aae7
1414
github.com/onflow/fcl-dev-wallet v0.4.2
15-
github.com/onflow/flow-core-contracts/lib/go/templates v0.11.0
16-
github.com/onflow/flow-emulator v0.31.1
17-
github.com/onflow/flow-go v0.25.6
18-
github.com/onflow/flow-go-sdk v0.24.0
15+
github.com/onflow/flow-core-contracts/lib/go/templates v0.11.2-0.20220513155751-c4c1f8d59f83
16+
github.com/onflow/flow-emulator v0.32.0
17+
github.com/onflow/flow-go v0.26.2
18+
github.com/onflow/flow-go-sdk v0.24.1-0.20220513205729-d1f58d47c4e3
1919
github.com/psiemens/sconfig v0.1.0
20-
github.com/sirupsen/logrus v1.6.0 // indirect
20+
github.com/sirupsen/logrus v1.8.1
2121
github.com/spf13/afero v1.8.2
2222
github.com/spf13/cobra v1.4.0
2323
github.com/stretchr/testify v1.7.1

go.sum

Lines changed: 196 additions & 54 deletions
Large diffs are not rendered by default.

internal/cadence/cadence.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var Cmd = &cobra.Command{
3030
Short: "Execute Cadence code",
3131
Run: func(cmd *cobra.Command, args []string) {
3232
if len(args) > 0 {
33-
execute.Execute(args)
33+
execute.Execute(args, nil)
3434
} else {
3535
execute.RunREPL()
3636
}

pkg/flowkit/arguments.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (v CadenceArgument) MarshalJSON() ([]byte, error) {
4242
}
4343

4444
func (v *CadenceArgument) UnmarshalJSON(b []byte) (err error) {
45-
v.Value, err = jsoncdc.Decode(b)
45+
v.Value, err = jsoncdc.Decode(nil, b)
4646
if err != nil {
4747
return err
4848
}
@@ -173,7 +173,7 @@ func ParseArgumentsWithoutType(fileName string, code []byte, args []string) (scr
173173

174174
}
175175

176-
var value, err = runtime.ParseLiteral(argumentString, semaType)
176+
var value, err = runtime.ParseLiteral(argumentString, semaType, nil)
177177
if err != nil {
178178
return nil, fmt.Errorf("argument `%s` is not expected type `%s`", parameterList[index].Identifier, semaType)
179179
}

pkg/flowkit/config/json/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (j jsonDeployments) transformToConfig() (config.Deployments, error) {
6262
return nil, err
6363
}
6464

65-
cadenceArg, err := jsoncdc.Decode(b)
65+
cadenceArg, err := jsoncdc.Decode(nil, b)
6666
if err != nil {
6767
return nil, err
6868
}

pkg/flowkit/contracts/contracts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func newContract(
5656
accountName string,
5757
args []cadence.Value,
5858
) (*Contract, error) {
59-
program, err := parser2.ParseProgram(contractCode)
59+
program, err := parser2.ParseProgram(contractCode, nil)
6060
if err != nil {
6161
return nil, err
6262
}

pkg/flowkit/contracts/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Resolver struct {
3939

4040
// NewResolver creates a new resolver.
4141
func NewResolver(code []byte) (*Resolver, error) {
42-
program, err := parser2.ParseProgram(string(code))
42+
program, err := parser2.ParseProgram(string(code), nil)
4343
if err != nil {
4444
return nil, err
4545
}

pkg/flowkit/services/accounts_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ func TestAccounts(t *testing.T) {
121121
tx := args.Get(0).(*flowkit.Transaction)
122122
assert.Equal(t, tx.FlowTransaction().Authorizers[0], serviceAddress)
123123
assert.Equal(t, tx.Signer().Address(), serviceAddress)
124-
assert.True(t, strings.Contains(string(tx.FlowTransaction().Script), "acct.contracts.add"))
125-
124+
assert.True(t, strings.Contains(string(tx.FlowTransaction().Script), "account.contracts.add"))
126125
gw.SendSignedTransaction.Return(tests.NewTransaction(), nil)
127126
})
128127

pkg/flowkit/services/blocks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestBlocksGet_Integration(t *testing.T) {
104104
assert.Nil(t, blockEvents)
105105
assert.Equal(t, collection, []*flow.Collection{})
106106
assert.Equal(t, block.Height, uint64(0))
107-
assert.Equal(t, block.ID.String(), "7bc42fe85d32ca513769a74f97f7e1a7bad6c9407f0d934c2aa645ef9cf613c7")
107+
assert.Equal(t, block.ID.String(), "13c7ff23bb65feb5757cc65fdd75cd243506518c126385fae530ddebdad10b17")
108108

109109
// create an event
110110
_, _ = s.Accounts.Create(srvAcc, tests.PubKeys(), nil, tests.SigAlgos(), tests.HashAlgos(), nil)

pkg/flowkit/transaction.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ func NewCreateAccountTransaction(
145145
keys []*flow.AccountKey,
146146
contracts []templates.Contract,
147147
) (*Transaction, error) {
148+
template, err := templates.CreateAccount(keys, contracts, signer.Address())
149+
if err != nil {
150+
return nil, err
151+
}
148152

149-
return newTransactionFromTemplate(
150-
templates.CreateAccount(keys, contracts, signer.Address()),
151-
signer,
152-
)
153+
return newTransactionFromTemplate(template, signer)
153154
}
154155

155156
func newTransactionFromTemplate(templateTx *flow.Transaction, signer *Account) (*Transaction, error) {

0 commit comments

Comments
 (0)