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

AVM: Allow immutable access to foreign app accounts #3994

Merged
merged 11 commits into from
May 23, 2022

Conversation

algoidurovic
Copy link
Contributor

Summary

The AVM allows access to a few different categories of accounts: the current app's, those belonging to apps created previously in the tx group, and those provided by the accounts tx field. The PR expands this set to include the accounts belonging to the apps provided by the foreign_apps tx field.

Test Plan

The standard unit tests for eval.go don't have access to a sufficiently featured ledger so the tests were added to ledger/internal instead.

@algoidurovic algoidurovic requested a review from jannotti May 17, 2022 17:23
Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

The different flag is a needed change. And testing before and after seems important, but doesn't have to be done using testConsensusRange (but you'll thank me, it's easier)

data/transactions/logic/eval.go Outdated Show resolved Hide resolved
ledger/internal/apptxn_test.go Outdated Show resolved Hide resolved
ledger/internal/apptxn_test.go Show resolved Hide resolved
@jannotti
Copy link
Contributor

Could you also update the Resource availability section in README_in.md (and regenerate specs) to document the change? It should just be a new bullet about v7.

@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #3994 (2166891) into master (aae5ef2) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3994      +/-   ##
==========================================
- Coverage   54.49%   54.43%   -0.07%     
==========================================
  Files         390      390              
  Lines       48500    48504       +4     
==========================================
- Hits        26430    26402      -28     
- Misses      19843    19876      +33     
+ Partials     2227     2226       -1     
Impacted Files Coverage Δ
data/transactions/logic/opcodes.go 84.86% <ø> (ø)
data/transactions/logic/eval.go 89.56% <100.00%> (+0.01%) ⬆️
ledger/roundlru.go 90.56% <0.00%> (-5.67%) ⬇️
network/wsPeer.go 65.83% <0.00%> (-3.06%) ⬇️
crypto/merkletrie/trie.go 66.42% <0.00%> (-2.19%) ⬇️
crypto/merkletrie/node.go 91.62% <0.00%> (-1.87%) ⬇️
node/node.go 23.19% <0.00%> (-1.85%) ⬇️
ledger/acctupdates.go 68.77% <0.00%> (-0.80%) ⬇️
data/transactions/verify/txn.go 45.02% <0.00%> (+0.86%) ⬆️
data/abi/abi_type.go 88.62% <0.00%> (+0.94%) ⬆️
... and 1 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 aae5ef2...2166891. Read the comment docs.

Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

Only the typo in the spec really needs to change, and that's trivial.

The others are a little paranoia, and tidying.

Looks good, I like the attempt to actually use the account in an inner pay.

@@ -180,6 +180,9 @@ _available_.
associated account of a contract that was created earlier in the
group is _available_.

* Since v7, the account associated with any contract present in the
`txn.ForeignApplications` is _available_.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`txn.ForeignApplications` is _available_.
`txn.ForeignApplications` field is _available_.

Comment on lines 2916 to 2919
tx.ForeignApps = []basics.AppIndex{basics.AppIndex(2)}

// This app looks itself up in the ledger, so we need to put it in there.
ledger.NewApp(tx.Sender, 2, basics.AppParams{
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change this 2 to a higher number? I'm just being a little paranoid because I want it to be obvious that the 2 is the appID of the app, and not a slot number in ForeignApps.

Also I think that comment is a cut-n-paste. The app isn't looking itself up. The app being tested looks up this app.

Comment on lines 3096 to 3098
dl.beginBlock()
dl.txgroup("", &appA, &appB)
vb := dl.endBlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
dl.beginBlock()
dl.txgroup("", &appA, &appB)
vb := dl.endBlock()
vb := dl.fullBlock(&appA, &appB)

unless they actually need to be in a txgroup, rather than just run sequentially.

}
fund0 := fund1
fund0.Receiver = index0.Address()
fund1.Receiver = index1.Address()
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to rewriting the same value, as fund1 hasn't changed, right?

}
fund0 := fund1
fund0.Receiver = index0.Address()
fund1.Receiver = index1.Address()
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Comment on lines 3273 to 3275
dl.beginBlock()
dl.txgroup("", &fund0, &fund1, &callA, &callB)
vb = dl.endBlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
dl.beginBlock()
dl.txgroup("", &fund0, &fund1, &callA, &callB)
vb = dl.endBlock()
vb = dl.fullBlock(&fund0, &fund1, &callA, &callB))

unless they actually need to be in a txgroup, rather than just run sequentially.

Comment on lines 3242 to 3244
dl.beginBlock()
dl.txgroup("", &appA, &appB)
vb := dl.endBlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
dl.beginBlock()
dl.txgroup("", &appA, &appB)
vb := dl.endBlock()
vb := dl.fullBlock(&appA, &appB)

unless they actually need to be in a txgroup, rather than just run sequentially.

Comment on lines 3073 to 3078
ApprovalProgram: main(`
int 3
int 3
==
assert
`),
Copy link
Contributor

Choose a reason for hiding this comment

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

You can actually leave this out and txntest.Txn will supply a passing ApprovalProgram.

Comment on lines 3140 to 3142
genBalances, addrs, _ := ledgertesting.NewTestGenesis()
l := newTestLedger(t, genBalances)
defer l.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if this was also testConsensusRange so that it tests all the versions, starting with the first that works, through vFuture as we add more and more versions.

Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for those consensusRange changes. They make me feel much more confident as we change things in the future.

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

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

Looks good to me

@MetaB0y
Copy link

MetaB0y commented Aug 14, 2022

This is great! Thank you for implementing!

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.

Smart contracts should be given access to accounts for apps specified in the foreign apps array
4 participants