Skip to content

Commit

Permalink
Merge branch 'master' of github.com:onflow/cadence into best-practices
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Mar 21, 2022
2 parents d75b75c + 5238cce commit edd743b
Show file tree
Hide file tree
Showing 64 changed files with 4,562 additions and 521 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Test
run: make test
- name: Upload coverage report
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v2
with:
file: ./coverage.txt
flags: unittests
Expand All @@ -66,6 +66,8 @@ jobs:
run: make lint-github-actions
- name: Check license headers
run: make check-headers
- name: Check capabilities of dependencies
run: make check-capabilities

semgrep:
name: Semgrep
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/sync-flow-go.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Open a PR in flow-go when a PR in cadence is merged
# The PR in flow-go is based on the last opened `auto-cadence-upgrade/*` if it exists, otherwise on the master branch
# The PR in flow-go is based on the last opened `auto-cadence-upgrade/*` if it exists.
# Otherwise, it's based on the feature/secure-cadence branch.
name: Sync flow-go

# Only run on pull requests merged to master
Expand All @@ -19,7 +20,7 @@ on:
jobs:
sync-flow-go:
runs-on: ubuntu-latest
# the PR could have been closed otherwise. Only run if it has actually ben merged
# the PR could have been closed otherwise. Only run if it has actually been merged
if: github.event.pull_request.merged == true
steps:

Expand All @@ -32,11 +33,12 @@ jobs:
repository: onflow/flow-go

# get the latest update branch name to base the PR on that branch
# else, use the "feature/secure-cadence" branch
- name: Get onflow/flow-go base branch name
run: |
git fetch
BRANCH=$(git branch -r -l "*auto-cadence-upgrade/*" --format "%(refname:lstrip=3)" | sort -r | head -n 1)
[ -z $BRANCH ] && BRANCH=master
[ -z $BRANCH ] && BRANCH=feature/secure-cadence
echo "BASE_BRANCH=$BRANCH" >> $GITHUB_ENV
# create new branch name
Expand All @@ -45,6 +47,16 @@ jobs:
NEW_BRANCH=auto-cadence-upgrade/$( date +%s )/${{ github.event.pull_request.head.ref }}
echo "NEW_BRANCH=$NEW_BRANCH" >> $GITHUB_ENV
# create feature branch if needed
- name: Create feature/secure-cadence branch
uses: peterjgrainger/action-create-branch@v2.0.1
if: env.BASE_BRANCH == 'feature/secure-cadence'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: feature/secure-cadence
ref: master

# checkout the correct branch of the remote repo
- name: Checkout onflow/flow-go branch
uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ languageserver/cmd/languageserver/languageserver
languageserver/cmd/languageserver/languageserver.wasm
tools/golangci-lint/golangci-lint
tools/maprangecheck/maprangecheck.so
tools/constructorcheck/constructorcheck.so

5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ issues:
- path: _test\.go
linters:
- maprangecheck
- constructorcheck
max-issues-per-linter: 0
max-same-issues: 0

Expand All @@ -43,5 +44,9 @@ linters-settings:
path: tools/maprangecheck/maprangecheck.so
description: reports range statements over maps
original-url: github.com/onflow/cadence/tools/maprangecheck
constructorcheck:
path: tools/constructorcheck/constructorcheck.so
description: reports range statements over maps
original-url: github.com/onflow/cadence/tools/constructorcheck


22 changes: 19 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ PATH := $(PATH):$(GOPATH)/bin

COVERPKGS := $(shell go list ./... | grep -v /cmd | grep -v /runtime/test | tr "\n" "," | sed 's/,*$$//')


LINTERS :=
ifneq ($(linters),)
LINTERS = -E $(linters)
endif


.PHONY: test
test:
# test all packages
Expand All @@ -45,19 +52,22 @@ lint-github-actions: build-linter

.PHONY: lint
lint: build-linter
tools/golangci-lint/golangci-lint run -v ./...
tools/golangci-lint/golangci-lint run $(LINTERS) -v ./...


.PHONY: fix-lint
fix-lint: build-linter
tools/golangci-lint/golangci-lint run -v --fix ./...
tools/golangci-lint/golangci-lint run -v --fix $(LINTERS) ./...

.PHONY: build-linter
build-linter: tools/golangci-lint/golangci-lint tools/maprangecheck/maprangecheck.so
build-linter: tools/golangci-lint/golangci-lint tools/maprangecheck/maprangecheck.so tools/constructorcheck/constructorcheck.so

tools/maprangecheck/maprangecheck.so:
(cd tools/maprangecheck && $(MAKE) plugin)

tools/constructorcheck/constructorcheck.so:
(cd tools/constructorcheck && $(MAKE) plugin)

tools/golangci-lint/golangci-lint:
(cd tools/golangci-lint && $(MAKE))

Expand All @@ -81,3 +91,9 @@ release:
npm-packages/cadence-parser/package.json \
npm-packages/cadence-docgen/package.json" \
./bump-version.sh $(bump))

.PHONY: check-capabilities
check-capabilities:
go install github.com/cugu/gocap@v0.1.0
go mod download
gocap check .
10 changes: 10 additions & 0 deletions go.cap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/onflow/cadence ()

github.com/davecgh/go-spew/spew (file)
github.com/onflow/cadence/runtime/interpreter (runtime)
github.com/onflow/cadence/runtime/parser2 (file)
github.com/onflow/cadence/runtime/pretty (runtime)
github.com/opentracing/opentracing-go (network)
github.com/stretchr/testify/assert (runtime, file, network)
github.com/zeebo/blake3/internal/consts (file)
golang.org/x/sys/cpu (runtime, file)
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require (
github.com/bytecodealliance/wasmtime-go v0.22.0
github.com/c-bata/go-prompt v0.2.5
github.com/cheekybits/genny v1.0.0
github.com/fxamacker/cbor/v2 v2.3.1-0.20211029162100-5d5d7c3edd41
github.com/fxamacker/cbor/v2 v2.4.1-0.20220314011055-12f5cb4b5eb0
github.com/go-test/deep v1.0.5
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381
github.com/onflow/atree v0.1.2-0.20220215140047-82a5e53e8248
github.com/onflow/atree v0.3.0
github.com/opentracing/opentracing-go v1.2.0
github.com/rivo/uniseg v0.2.1-0.20211004051800-57c86be7915a
github.com/schollz/progressbar/v3 v3.8.3
Expand Down
24 changes: 14 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wX
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fxamacker/cbor/v2 v2.3.1-0.20211029162100-5d5d7c3edd41 h1:adk2SdM72B9LVdNPVgLDO+UBdGW5JmDIJEdzlI2ZYC8=
github.com/fxamacker/cbor/v2 v2.3.1-0.20211029162100-5d5d7c3edd41/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/fxamacker/circlehash v0.1.0 h1:wXK52nkcBzGM+FyYc3wFYshm+0523BfX7h1XsUJLl70=
github.com/fxamacker/circlehash v0.1.0/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM=
github.com/fxamacker/cbor/v2 v2.4.1-0.20220314011055-12f5cb4b5eb0 h1:4i+hJzGuDJs2qYo2rFjNrEYyzQdzjJOzNUR9p20VHyo=
github.com/fxamacker/cbor/v2 v2.4.1-0.20220314011055-12f5cb4b5eb0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/fxamacker/circlehash v0.3.0 h1:XKdvTtIJV9t7DDUtsf0RIpC1OcxZtPbmgIH7ekx28WA=
github.com/fxamacker/circlehash v0.3.0/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM=
github.com/go-test/deep v1.0.5 h1:AKODKU3pDH1RzZzm6YZu77YWtEAq6uh1rLIAQlay2qc=
github.com/go-test/deep v1.0.5/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -37,8 +39,8 @@ github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI=
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/onflow/atree v0.1.2-0.20220215140047-82a5e53e8248 h1:2KgkjxXZS1NG5VHaoGK32rUazdGyj2EexY5fyHc3FbA=
github.com/onflow/atree v0.1.2-0.20220215140047-82a5e53e8248/go.mod h1:95SqSEPgfijF1ZkLKbVgYVrfQzvP0fhayh555v1oLbs=
github.com/onflow/atree v0.3.0 h1:sdximsqKSZwDbF2PX3DlMFfbs+kPY7Rn9oN9x+AzGYE=
github.com/onflow/atree v0.3.0/go.mod h1:tSPKjdmbNOQyVrSvcxKZG8+EDL4jdjoJBGAjNVk8zkA=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk=
Expand All @@ -64,10 +66,10 @@ github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcY
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zeebo/assert v1.1.0 h1:hU1L1vLTHsnO8x8c9KAR5GmM5QscxHg5RNU5z5qbUWY=
github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/blake3 v0.2.0 h1:1SGx3IvKWFUU/xl+/7kjdcjjMcvVSm+3dMo/N42afC8=
github.com/zeebo/blake3 v0.2.0/go.mod h1:G9pM4qQwjRzF1/v7+vabMj/c5mWpGZ2Wzo3Eb4z0pb4=
github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0=
github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
github.com/zeebo/blake3 v0.2.2 h1:ddH9fUIlef5r+pqvJShGgSXFd6c7k54eQXZ48hNjotQ=
github.com/zeebo/blake3 v0.2.2/go.mod h1:TSQ0KjMH+pht+bRyvVooJ1rBpvvngSGaPISafq9MxJk=
github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -131,3 +133,5 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=
2 changes: 1 addition & 1 deletion npm-packages/cadence-docgen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onflow/cadence-docgen",
"version": "0.21.1",
"version": "0.21.2",
"description": "The Cadence Dcoument Generator",
"homepage": "https://github.com/onflow/cadence",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion npm-packages/cadence-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onflow/cadence-parser",
"version": "0.21.1",
"version": "0.21.2",
"description": "The Cadence parser",
"homepage": "https://github.com/onflow/cadence",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion runtime/cmd/decode-state-values/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func loadStorageKey(

if composite, ok := v.(*interpreter.CompositeValue); ok &&
composite.Kind == common.CompositeKindResource &&
composite.ResourceUUID() == nil {
composite.ResourceUUID(inter, interpreter.ReturnEmptyLocationRange) == nil {

log.Printf(
"Failed to get UUID for resource @ 0x%x %s",
Expand Down
145 changes: 145 additions & 0 deletions runtime/common/computationkind.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Cadence - The resource-oriented smart contract programming language
*
* Copyright 2022 Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package common

//go:generate go run golang.org/x/tools/cmd/stringer -type=ComputationKind -trimprefix=ComputationKind

// ComputationKind captures kind of computation that would be used for metring computation
type ComputationKind uint

// [1000,2000) is reserved for Cadence interpreter and runtime
const ComputationKindRangeStart = 1000

const (
ComputationKindUnknown ComputationKind = 0
// interpreter - base
ComputationKindStatement ComputationKind = ComputationKindRangeStart + iota
ComputationKindLoop
ComputationKindFunctionInvocation
_
_
_
_
_
_
// interpreter value operations
ComputationKindCreateCompositeValue
ComputationKindTransferCompositeValue
ComputationKindDestroyCompositeValue
_
_
_
_
_
_
_
_
_
_
_
_
ComputationKindCreateArrayValue
ComputationKindTransferArrayValue
ComputationKindDestroyArrayValue
_
_
_
_
_
_
_
_
_
_
_
_
ComputationKindCreateDictionaryValue
ComputationKindTransferDictionaryValue
ComputationKindDestroyDictionaryValue
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
// stdlibs computation kinds
//
ComputationKindSTDLIBPanic
ComputationKindSTDLIBAssert
ComputationKindSTDLIBUnsafeRandom
_
_
_
_
_
// RLP
ComputationKindSTDLIBRLPDecodeString
ComputationKindSTDLIBRLPDecodeList
)
Loading

0 comments on commit edd743b

Please sign in to comment.