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

Check transfer and use of transfered or destroyed resources at runtime #1461

Merged
merged 9 commits into from
Mar 1, 2022

Conversation

turbolent
Copy link
Member

Work towards dapperlabs/cadence-private-issues#19

Description

Add a defensive check for resources: When a resource is transferred (moved), create a new instance (Go struct), instead of reusing the existing one. Also, mark the transferred resource as invalidated, and detect uses after invalidation.

We already had an existing check for uses of referenced resources after their destruction.

Combined, this allows checking the use (transfer or access) of invalidated (transferred or destroyed) resources.


  • 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 Mar 1, 2022
@github-actions
Copy link

github-actions bot commented Mar 1, 2022

Cadence Benchstat comparison

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

Results

old.txtnew.txt
time/opdelta
RuntimeFungibleTokenTransfer-21.69ms ±26%1.66ms ±20%~(p=0.902 n=7+7)
RuntimeResourceDictionaryValues-217.8ms ± 3%18.2ms ± 6%~(p=0.366 n=6+7)
ParseDeploy/byte_array-226.1ms ± 6%25.7ms ±11%~(p=0.383 n=7+7)
ParseDeploy/decode_hex-21.53ms ± 3%1.51ms ± 3%~(p=0.366 n=7+6)
ParseArray-216.1ms ± 3%16.4ms ± 4%~(p=0.138 n=6+7)
ParseInfix-210.4µs ± 3%11.1µs ± 9%~(p=0.101 n=6+7)
ParseFungibleToken-2245µs ±11%247µs ± 3%~(p=0.366 n=7+6)
QualifiedIdentifierCreation/One_level-23.49ns ± 3%3.48ns ± 5%~(p=0.535 n=7+7)
QualifiedIdentifierCreation/Three_levels-2179ns ± 4%179ns ± 4%~(p=1.000 n=7+7)
ContractInterfaceFungibleToken-250.7µs ± 1%51.1µs ± 4%~(p=0.908 n=6+7)
NewInterpreter/new_interpreter-21.37µs ± 5%1.39µs ± 3%~(p=0.165 n=7+7)
NewInterpreter/new_sub-interpreter-22.73µs ± 9%2.67µs ± 5%~(p=0.620 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2186µs ± 5%181µs ± 1%−2.79%(p=0.035 n=7+6)
InterpretRecursionFib-23.03ms ± 3%2.93ms ± 2%−3.20%(p=0.035 n=7+6)
 
alloc/opdelta
RuntimeFungibleTokenTransfer-2271kB ± 0%272kB ± 0%+0.32%(p=0.001 n=7+7)
RuntimeResourceDictionaryValues-24.05MB ± 0%4.05MB ± 0%~(p=0.165 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-266.2kB ± 0%66.2kB ± 0%~(all equal)
ContractInterfaceFungibleToken-226.6kB ± 0%26.6kB ± 0%~(p=0.286 n=7+7)
NewInterpreter/new_interpreter-2768B ± 0%768B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.24kB ± 0%1.24kB ± 0%~(all equal)
InterpretRecursionFib-21.24MB ± 0%1.24MB ± 0%~(p=0.434 n=7+6)
 
allocs/opdelta
RuntimeFungibleTokenTransfer-24.51k ± 0%4.52k ± 0%+0.30%(p=0.001 n=7+7)
RuntimeResourceDictionaryValues-2102k ± 0%102k ± 0%+0.00%(p=0.001 n=7+7)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
ContractInterfaceFungibleToken-2458 ± 0%458 ± 0%~(all equal)
NewInterpreter/new_interpreter-212.0 ± 0%12.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-238.0 ± 0%38.0 ± 0%~(all equal)
InterpretRecursionFib-225.0k ± 0%25.0k ± 0%~(all equal)
 

Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants