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

Limit depth of expressions and types #1664

Merged
merged 3 commits into from
May 20, 2022

Conversation

turbolent
Copy link
Member

Description

Don't allow expressions and types to be arbitrarily nested. Limit to sensible values.

I verified the limits currently do not affect existing contracts on Mainnet.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@turbolent turbolent self-assigned this May 19, 2022
@github-actions
Copy link

github-actions bot commented May 19, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 66eac2a
The command for i in {1..N}; do go test ./... -run=XXX -bench=. -benchmem -shuffle=on; done was used.
Bench tests were run a total of 7 times on each branch.

Results

old.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-2154µs ± 2%152µs ± 1%~(p=0.101 n=7+6)
ContractInterfaceFungibleToken-247.1µs ± 3%46.5µs ± 3%~(p=0.165 n=7+7)
InterpretRecursionFib-23.21ms ± 2%3.16ms ± 3%~(p=0.073 n=6+7)
NewInterpreter/new_interpreter-21.31µs ± 2%1.29µs ± 1%−1.82%(p=0.013 n=7+6)
NewInterpreter/new_sub-interpreter-22.69µs ± 2%2.64µs ± 3%−2.10%(p=0.038 n=7+7)
ParseArray-210.2ms ± 2%9.8ms ± 2%−3.42%(p=0.002 n=7+7)
ParseDeploy/byte_array-215.3ms ± 2%14.6ms ± 4%−4.05%(p=0.002 n=7+7)
ParseDeploy/decode_hex-21.39ms ± 1%1.36ms ± 3%−1.92%(p=0.035 n=6+7)
ParseFungibleToken/With_memory_metering-2247µs ± 4%240µs ± 4%~(p=0.053 n=7+7)
ParseFungibleToken/Without_memory_metering-2187µs ± 2%185µs ± 3%~(p=0.209 n=7+7)
ParseInfix-28.92µs ± 0%8.50µs ± 2%−4.78%(p=0.001 n=6+7)
QualifiedIdentifierCreation/One_level-23.16ns ± 2%3.11ns ± 2%~(p=0.053 n=7+7)
QualifiedIdentifierCreation/Three_levels-2162ns ± 2%166ns ± 3%+2.33%(p=0.020 n=6+7)
RuntimeFungibleTokenTransfer-21.40ms ±20%1.25ms ±27%~(p=0.259 n=7+7)
RuntimeResourceDictionaryValues-27.48ms ± 5%7.48ms ± 4%~(p=0.902 n=7+7)
Transfer-2104ns ± 2%102ns ± 3%−2.20%(p=0.038 n=7+7)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-266.3kB ± 0%66.3kB ± 0%~(p=0.245 n=6+7)
ContractInterfaceFungibleToken-226.7kB ± 0%26.7kB ± 0%~(all equal)
InterpretRecursionFib-21.25MB ± 0%1.25MB ± 0%~(all equal)
NewInterpreter/new_interpreter-2872B ± 0%872B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.38kB ± 0%1.38kB ± 0%~(all equal)
ParseArray-22.93MB ± 2%2.96MB ± 2%~(p=0.318 n=7+7)
ParseDeploy/byte_array-24.26MB ± 4%4.32MB ± 3%~(p=0.365 n=7+7)
ParseDeploy/decode_hex-2213kB ± 0%213kB ± 0%~(p=0.690 n=7+7)
ParseFungibleToken/With_memory_metering-236.3kB ± 0%36.3kB ± 0%+0.05%(p=0.047 n=7+7)
ParseFungibleToken/Without_memory_metering-236.3kB ± 0%36.3kB ± 0%+0.06%(p=0.025 n=7+7)
ParseInfix-22.14kB ± 0%2.15kB ± 0%+0.72%(p=0.001 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2237kB ± 0%237kB ± 1%~(p=0.272 n=7+7)
RuntimeResourceDictionaryValues-22.24MB ± 0%2.24MB ± 0%~(p=0.259 n=7+7)
Transfer-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
ContractInterfaceFungibleToken-2460 ± 0%460 ± 0%~(all equal)
InterpretRecursionFib-223.8k ± 0%23.8k ± 0%~(all equal)
NewInterpreter/new_interpreter-212.0 ± 0%12.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-240.0 ± 0%40.0 ± 0%~(all equal)
ParseArray-270.0k ± 0%70.0k ± 0%~(p=0.592 n=7+7)
ParseDeploy/byte_array-2105k ± 0%105k ± 0%~(p=0.592 n=7+7)
ParseDeploy/decode_hex-279.0 ± 0%79.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-21.06k ± 0%1.06k ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-21.06k ± 0%1.06k ± 0%~(all equal)
ParseInfix-266.0 ± 0%66.0 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
RuntimeFungibleTokenTransfer-24.58k ± 0%4.58k ± 0%~(p=0.286 n=7+7)
RuntimeResourceDictionaryValues-237.6k ± 0%37.6k ± 0%−0.01%(p=0.001 n=7+7)
Transfer-21.00 ± 0%1.00 ± 0%~(all equal)
 

@codecov
Copy link

codecov bot commented May 20, 2022

Codecov Report

Merging #1664 (489e6d1) into master (66eac2a) will decrease coverage by 0.03%.
The diff coverage is 41.93%.

@@            Coverage Diff             @@
##           master    #1664      +/-   ##
==========================================
- Coverage   76.50%   76.47%   -0.04%     
==========================================
  Files         291      291              
  Lines       60995    61011      +16     
==========================================
- Hits        46666    46658       -8     
- Misses      12719    12741      +22     
- Partials     1610     1612       +2     
Flag Coverage Δ
unittests 76.47% <41.93%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
runtime/parser2/errors.go 20.89% <0.00%> (-7.68%) ⬇️
runtime/parser2/parser.go 91.39% <ø> (+0.11%) ⬆️
runtime/parser2/expression.go 92.97% <100.00%> (+0.06%) ⬆️
runtime/parser2/type.go 89.46% <100.00%> (+0.13%) ⬆️
runtime/parser2/lexer/lexer.go 97.59% <0.00%> (-1.03%) ⬇️
runtime/common/metering.go 91.30% <0.00%> (-0.55%) ⬇️
runtime/sema/checker.go 90.33% <0.00%> (-0.12%) ⬇️
runtime/sema/type.go 88.94% <0.00%> (-0.08%) ⬇️
values.go 65.82% <0.00%> (-0.08%) ⬇️
runtime/interpreter/statictype.go 81.88% <0.00%> (-0.05%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 66eac2a...489e6d1. Read the comment docs.

@turbolent turbolent merged commit c354eef into master May 20, 2022
@turbolent turbolent deleted the bastian/limit-parser-expression-and-type-depth branch May 20, 2022 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants