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: Share resource arrays across transactions #5035

Merged
merged 30 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5051793
Initial implementation.
jannotti Jan 18, 2023
97e2269
Re-org availability checks in prep for changes
jannotti Jan 24, 2023
bbaa278
Checkpoint with new approach, needs v9 -> v8 tests
jannotti Jan 26, 2023
857d17e
Adjust names after rebase
jannotti Jan 26, 2023
bc2a5af
Add checks for inner txn resource access
jannotti Feb 1, 2023
726be12
Account for "shared" indexes in EvalDelta
jannotti Feb 2, 2023
a48886e
oas2 fixups
jannotti Feb 2, 2023
28aa602
e2e test for shared resource access
jannotti Feb 3, 2023
86dfb59
Several more tests, and handling created apps/accounts
jannotti Feb 15, 2023
e9dfd02
allocbound
jannotti Feb 16, 2023
bea0c92
coverage
jannotti Feb 16, 2023
ef20192
Test account passing across versions for more coverage
jannotti Feb 16, 2023
8b09e82
Bob CR
jannotti Feb 18, 2023
c70f0b6
Fix suggested by @jasonpaulos
jannotti Feb 21, 2023
b106666
Add (and use) a simpler way to do cross version app testing
jannotti Feb 22, 2023
d60380c
Fix app_opted_in for resource sharing, and initial spec changes
jannotti Feb 22, 2023
bf98ae4
Improvements from CR. Some more tests to come.
jannotti Feb 23, 2023
cf2bfeb
New tests, including v9 calling v8 showing blocked access
jannotti Feb 24, 2023
2bd96e1
Zeph CR typos
jannotti Mar 1, 2023
1ef746b
regenetate
jannotti Mar 20, 2023
8f738fb
Comment clarity
jannotti Mar 22, 2023
41f4f86
Pavel CR
jannotti Mar 23, 2023
56b2b55
Add tests for interpretation of integers as resource or slot
jannotti Mar 30, 2023
b4e63e8
Remove use of slots for app and asset indexes
jannotti Mar 30, 2023
946309e
Remove slot usage for account access opcodes
jannotti Mar 31, 2023
ccdd661
adjust ledger tests for v9
jannotti Apr 2, 2023
2239746
add extra test discussed with Pavel
jannotti Apr 3, 2023
3ad609f
Merge remote-tracking branch 'upstream/master' into avm-group-resources
jannotti Apr 4, 2023
0eb3923
fix long standing typo
jannotti Apr 4, 2023
530c76a
Final (?) cr fixes and an obscure bug fix
jannotti Apr 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 38 additions & 21 deletions data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ pushbytess "1" "2" "1"

const v8Nonsense = v7Nonsense + switchNonsense + frameNonsense + matchNonsense + boxNonsense

const v9Nonsense = v8Nonsense + pairingNonsense
const v9Nonsense = v8Nonsense
const v10Nonsense = v9Nonsense + pairingNonsense

const v6Compiled = "2004010002b7a60c26050242420c68656c6c6f20776f726c6421070123456789abcd208dae2087fbba51304eb02b91f656948397a7946390e8cb70fc9ea4d95f92251d047465737400320032013202320380021234292929292b0431003101310231043105310731083109310a310b310c310d310e310f3111311231133114311533000033000133000233000433000533000733000833000933000a33000b33000c33000d33000e33000f3300113300123300133300143300152d2e01022581f8acd19181cf959a1281f8acd19181cf951a81f8acd19181cf1581f8acd191810f082209240a220b230c240d250e230f2310231123122313231418191a1b1c28171615400003290349483403350222231d4a484848482b50512a632223524100034200004322602261222704634848222862482864286548482228246628226723286828692322700048482371004848361c0037001a0031183119311b311d311e311f312023221e312131223123312431253126312731283129312a312b312c312d312e312f447825225314225427042455220824564c4d4b0222382124391c0081e80780046a6f686e2281d00f23241f880003420001892224902291922494249593a0a1a2a3a4a5a6a7a8a9aaabacadae24af3a00003b003c003d816472064e014f012a57000823810858235b235a2359b03139330039b1b200b322c01a23c1001a2323c21a23c3233e233f8120af06002a494905002a49490700b400b53a03b6b7043cb8033a0c2349c42a9631007300810881088120978101c53a8101c6003a"

Expand All @@ -444,18 +445,20 @@ const matchCompiled = "83030102018e02fff500008203013101320131"

const v8Compiled = v7Compiled + switchCompiled + frameCompiled + matchCompiled + boxCompiled

const v9Compiled = v8Compiled + pairingCompiled
const v9Compiled = v8Compiled
const v10Compiled = v9Compiled + pairingCompiled

var nonsense = map[uint64]string{
1: v1Nonsense,
2: v2Nonsense,
3: v3Nonsense,
4: v4Nonsense,
5: v5Nonsense,
6: v6Nonsense,
7: v7Nonsense,
8: v8Nonsense,
9: v9Nonsense,
1: v1Nonsense,
2: v2Nonsense,
3: v3Nonsense,
4: v4Nonsense,
5: v5Nonsense,
6: v6Nonsense,
7: v7Nonsense,
8: v8Nonsense,
9: v9Nonsense,
10: v9Nonsense,
jannotti marked this conversation as resolved.
Show resolved Hide resolved
}

var compiled = map[uint64]string{
Expand All @@ -468,6 +471,8 @@ var compiled = map[uint64]string{
7: "07" + v7Compiled,
8: "08" + v8Compiled,
9: "09" + v9Compiled,

10: "10" + v10Compiled,
}

func pseudoOp(opcode string) bool {
Expand Down Expand Up @@ -1774,7 +1779,7 @@ func TestAssembleDisassembleErrors(t *testing.T) {
require.Contains(t, err.Error(), "invalid opcode")

source = "int 0\nint 0\nasset_holding_get AssetFrozen"
ops, err = AssembleStringWithVersion(source, AssemblerMaxVersion)
ops, err = AssembleStringWithVersion(source, sharedResourcesVersion-1)
require.NoError(t, err)
ops.Program[7] = 0x50 // holding field
_, err = Disassemble(ops.Program)
Expand Down Expand Up @@ -1885,10 +1890,20 @@ func TestAssembleAsset(t *testing.T) {
Expect{1, "asset_holding_get ABC 1 expects 2 stack arguments..."})
testProg(t, "int 1; asset_holding_get ABC 1", v,
Expect{1, "asset_holding_get ABC 1 expects 2 stack arguments..."})
testProg(t, "int 1; int 1; asset_holding_get ABC 1", v,
Expect{1, "asset_holding_get expects 1 immediate argument"})
testProg(t, "int 1; int 1; asset_holding_get ABC", v,
Expect{1, "asset_holding_get unknown field: \"ABC\""})

if v < sharedResourcesVersion {
testProg(t, "int 1; int 1; asset_holding_get ABC 1", v,
Expect{1, "asset_holding_get expects 1 immediate argument"})
testProg(t, "int 1; int 1; asset_holding_get ABC", v,
Expect{1, "asset_holding_get unknown field: \"ABC\""})
} else {
testProg(t, "int 1; int 1; asset_holding_get ABC 1", v,
Expect{1, "asset_holding_get ABC 1 arg 0 wanted type..."})
testProg(t, "txn Sender; int 1; asset_holding_get ABC 1", v,
Expect{1, "asset_holding_get expects 1 immediate argument"})
testProg(t, "txn Sender; int 1; asset_holding_get ABC", v,
Expect{1, "asset_holding_get unknown field: \"ABC\""})
}

testProg(t, "byte 0x1234; asset_params_get ABC 1", v,
Expect{1, "asset_params_get ABC 1 arg 0 wanted type uint64..."})
Expand Down Expand Up @@ -2159,15 +2174,17 @@ func TestHasStatefulOps(t *testing.T) {
require.NoError(t, err)
require.False(t, has)

source = `int 1
int 1
app_opted_in
err
`
source = `txn Sender; int 1; app_opted_in; err`
ops = testProg(t, source, AssemblerMaxVersion)
has, err = HasStatefulOps(ops.Program)
require.NoError(t, err)
require.True(t, has)

source = `int 1; int 1; app_opted_in; err`
ops = testProg(t, source, sharedResourcesVersion-1)
has, err = HasStatefulOps(ops.Program)
require.NoError(t, err)
require.True(t, has)
}

func TestStringLiteralParsing(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/box_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func TestBoxTotals(t *testing.T) {

ledger.NewApp(txn.Sender, 888, basics.AppParams{})
// The SENDER certainly has no boxes (but does exist)
logic.TestApp(t, `int 0; acct_params_get AcctTotalBoxes; pop; !`, ep)
logic.TestApp(t, `txn Sender; acct_params_get AcctTotalBoxes; pop; !`, ep)
bbroder-algo marked this conversation as resolved.
Show resolved Hide resolved
// Nor does the app account, to start
logic.TestApp(t, `int 888; app_params_get AppAddress; assert;
acct_params_get AcctTotalBoxes; pop; !; `, ep)
Expand Down
24 changes: 7 additions & 17 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -4015,9 +4015,11 @@ func (cx *EvalContext) assignAccount(sv stackValue) (basics.Address, error) {
// not, based on version.

func (cx *EvalContext) accountReference(account stackValue) (basics.Address, uint64, error) {
if account.argType() == StackUint64 {
addr, err := cx.txn.Txn.AddressByIndex(account.Uint, cx.txn.Txn.Sender)
return addr, account.Uint, err
if cx.version < sharedResourcesVersion {
if account.argType() == StackUint64 {
addr, err := cx.txn.Txn.AddressByIndex(account.Uint, cx.txn.Txn.Sender)
return addr, account.Uint, err
}
}
addr, err := account.address()
if err != nil {
Expand Down Expand Up @@ -4479,13 +4481,7 @@ func (cx *EvalContext) appReference(ref uint64, foreign bool) (basics.AppIndex,
func (cx *EvalContext) localsReference(account stackValue, ref uint64) (basics.Address, basics.AppIndex, uint64, error) {
if cx.version >= sharedResourcesVersion {
unused := uint64(0) // see function comment
var addr basics.Address
var err error
if account.Bytes != nil {
addr, err = account.address()
} else {
addr, err = cx.txn.Txn.AddressByIndex(account.Uint, cx.txn.Txn.Sender)
}
addr, err := account.address()
if err != nil {
return basics.Address{}, 0, 0, err
}
Expand Down Expand Up @@ -4562,13 +4558,7 @@ func (cx *EvalContext) assetReference(ref uint64, foreign bool) (basics.AssetInd

func (cx *EvalContext) holdingReference(account stackValue, ref uint64) (basics.Address, basics.AssetIndex, error) {
if cx.version >= sharedResourcesVersion {
var addr basics.Address
var err error
if account.Bytes != nil {
addr, err = account.address()
} else {
addr, err = cx.txn.Txn.AddressByIndex(account.Uint, cx.txn.Txn.Sender)
}
addr, err := account.address()
if err != nil {
return basics.Address{}, 0, err
}
Expand Down