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

Change account linking pragma to run-time configuration of execution #2380

Merged
merged 3 commits into from
Mar 13, 2023

Conversation

turbolent
Copy link
Member

@turbolent turbolent commented Mar 10, 2023

Description

Problem

#2353 introduced a pragma, which determines if the account linking function (AuthAccount.linkAccount) is available.

This is a static check: If the pragma is declared in the same program, the function is available, if the pragma is not declared, the function is not available.

This works well to allow wallets to detect transactions which attempt to use the account linking function, and potentially reject them. However, if the function is used in a contract, the current implementation requires the contract to declare the pragma, and a transaction which calls into the transaction does not need to declare the pragma. This prevents wallets from easily detecting a potential use of the account linking function.

Solution

Change the behaviour of the account linking pragma #allowAccountLinking from just a static check, to both a static check (as before, ensure the pragma is declared in the header of a program), and a dynamic check when the account linking function is called. The dynamic check requires that the pragma was declared.

Changes

  • Still statically check the pragma occurs at the top level of a program, and not nested or after other non-pragma declarations
  • Change the availability of the AuthAccount.linkAccount function, from being only defined when the pragma is defined in the same program, to being always available, independent of the pragma
  • Add configuration option to the interpreter which determines if the account linking function may be called
  • Add a function to the interpreter which configures the interpreter's configuration option based on the pragma declaration
  • Perform the pragma-based configuration of the account linking availability for transactions and scripts

  • 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

@github-actions
Copy link

github-actions bot commented Mar 10, 2023

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 41f1c5b
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.

Collapsed results for better readability

old.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-2115µs ± 0%115µs ± 0%~(p=1.000 n=1+1)
ContractInterfaceFungibleToken-238.2µs ± 0%38.2µs ± 0%~(p=1.000 n=1+1)
ExportType/composite_type-2346ns ± 0%357ns ± 0%~(p=1.000 n=1+1)
ExportType/simple_type-251.8ns ± 0%58.4ns ± 0%~(p=1.000 n=1+1)
InterpretRecursionFib-22.37ms ± 0%2.38ms ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_interpreter-21.11µs ± 0%1.11µs ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_sub-interpreter-2597ns ± 0%595ns ± 0%~(p=1.000 n=1+1)
ParseArray-27.93ms ± 0%8.18ms ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-212.1ms ± 0%11.9ms ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-21.21ms ± 0%1.21ms ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/With_memory_metering-2189µs ± 0%186µs ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/Without_memory_metering-2147µs ± 0%148µs ± 0%~(p=1.000 n=1+1)
ParseInfix-27.32µs ± 0%7.26µs ± 0%~(p=1.000 n=1+1)
QualifiedIdentifierCreation/One_level-22.35ns ± 0%2.35ns ± 0%~(p=1.000 n=1+1)
QualifiedIdentifierCreation/Three_levels-2134ns ± 0%138ns ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-25.43ms ± 0%5.15ms ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-23.81µs ± 0%6.57µs ± 0%~(p=1.000 n=1+1)
SuperTypeInference/arrays-2312ns ± 0%313ns ± 0%~(p=1.000 n=1+1)
SuperTypeInference/composites-2134ns ± 0%134ns ± 0%~(p=1.000 n=1+1)
SuperTypeInference/integers-291.4ns ± 0%89.9ns ± 0%~(p=1.000 n=1+1)
ValueIsSubtypeOfSemaType-292.8ns ± 0%93.4ns ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-248.9kB ± 0%48.9kB ± 0%~(all equal)
ContractInterfaceFungibleToken-223.2kB ± 0%23.2kB ± 0%~(all equal)
ExportType/composite_type-2136B ± 0%136B ± 0%~(all equal)
ExportType/simple_type-20.00B 0.00B ~(all equal)
InterpretRecursionFib-21.00MB ± 0%1.00MB ± 0%~(all equal)
NewInterpreter/new_interpreter-2768B ± 0%768B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-2200B ± 0%200B ± 0%~(all equal)
ParseArray-22.72MB ± 0%2.95MB ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-24.09MB ± 0%4.09MB ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-2214kB ± 0%214kB ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/With_memory_metering-228.9kB ± 0%28.9kB ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/Without_memory_metering-228.9kB ± 0%28.9kB ± 0%~(all equal)
ParseInfix-21.92kB ± 0%1.91kB ± 0%~(p=1.000 n=1+1)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeResourceDictionaryValues-22.29MB ± 0%2.28MB ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-22.70kB ± 0%2.70kB ± 0%~(all equal)
SuperTypeInference/arrays-296.0B ± 0%96.0B ± 0%~(all equal)
SuperTypeInference/composites-20.00B 0.00B ~(all equal)
SuperTypeInference/integers-20.00B 0.00B ~(all equal)
ValueIsSubtypeOfSemaType-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-2806 ± 0%806 ± 0%~(all equal)
ContractInterfaceFungibleToken-2370 ± 0%370 ± 0%~(all equal)
ExportType/composite_type-23.00 ± 0%3.00 ± 0%~(all equal)
ExportType/simple_type-20.00 0.00 ~(all equal)
InterpretRecursionFib-218.9k ± 0%18.9k ± 0%~(all equal)
NewInterpreter/new_interpreter-213.0 ± 0%13.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-24.00 ± 0%4.00 ± 0%~(all equal)
ParseArray-259.6k ± 0%59.6k ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-289.4k ± 0%89.4k ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-263.0 ± 0%63.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-2768 ± 0%768 ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-2768 ± 0%768 ± 0%~(all equal)
ParseInfix-248.0 ± 0%48.0 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
RuntimeResourceDictionaryValues-236.9k ± 0%36.9k ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-243.0 ± 0%43.0 ± 0%~(all equal)
SuperTypeInference/arrays-23.00 ± 0%3.00 ± 0%~(all equal)
SuperTypeInference/composites-20.00 0.00 ~(all equal)
SuperTypeInference/integers-20.00 0.00 ~(all equal)
ValueIsSubtypeOfSemaType-21.00 ± 0%1.00 ± 0%~(all equal)
 

@codecov
Copy link

codecov bot commented Mar 10, 2023

Codecov Report

Merging #2380 (c5a4e71) into master (fb505f3) will increase coverage by 0.00%.
The diff coverage is 93.10%.

@@           Coverage Diff           @@
##           master    #2380   +/-   ##
=======================================
  Coverage   78.50%   78.51%           
=======================================
  Files         316      316           
  Lines       68471    68492   +21     
=======================================
+ Hits        53755    53774   +19     
- Misses      12918    12920    +2     
  Partials     1798     1798           
Flag Coverage Δ
unittests 78.51% <93.10%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
runtime/interpreter/errors.go 56.07% <0.00%> (-0.41%) ⬇️
runtime/interpreter/interpreter.go 89.78% <100.00%> (+0.05%) ⬆️
runtime/runtime.go 85.16% <100.00%> (ø)
runtime/script_executor.go 87.83% <100.00%> (+0.16%) ⬆️
runtime/sema/checker.go 92.60% <100.00%> (-0.02%) ⬇️
runtime/transaction_executor.go 88.88% <100.00%> (+0.13%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@turbolent turbolent requested a review from SupunS March 13, 2023 22:17
@turbolent turbolent merged commit 0f2b14c into master Mar 13, 2023
@turbolent turbolent deleted the bastian/improve-allow-account-linking-pragma branch March 13, 2023 22:37
bors bot added a commit to onflow/flow-go that referenced this pull request Mar 14, 2023
4042: Update to Cadence v0.31.5-account-linking-improved-pragma r=turbolent a=turbolent

See onflow/cadence#2380

Co-authored-by: Bastian Müller <bastian@axiomzen.co>
bors bot added a commit to onflow/flow-go that referenced this pull request Mar 14, 2023
4042: Update to Cadence v0.31.5-account-linking-improved-pragma r=turbolent a=turbolent

See onflow/cadence#2380

Co-authored-by: Bastian Müller <bastian@axiomzen.co>
bors bot added a commit to onflow/flow-go that referenced this pull request Mar 14, 2023
4042: Update to Cadence v0.31.5-account-linking-improved-pragma r=turbolent a=turbolent

See onflow/cadence#2380

Co-authored-by: Bastian Müller <bastian@axiomzen.co>
bors bot added a commit to onflow/flow-go that referenced this pull request Mar 14, 2023
4042: Update to Cadence v0.31.5-account-linking-improved-pragma r=turbolent a=turbolent

See onflow/cadence#2380

Co-authored-by: Bastian Müller <bastian@axiomzen.co>
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