Skip to content

AVM: Allow access to boxes for apps made in the same group without explicit boxrefs#6309

Merged
jannotti merged 10 commits intoalgorand:masterfrom
jannotti:create-unnamed-boxes
Aug 15, 2025
Merged

AVM: Allow access to boxes for apps made in the same group without explicit boxrefs#6309
jannotti merged 10 commits intoalgorand:masterfrom
jannotti:create-unnamed-boxes

Conversation

@jannotti
Copy link
Copy Markdown
Contributor

@jannotti jannotti commented Apr 23, 2025

Summary

We have heard many requests to allow for the creation of boxes in newly created apps. That appears to already be allowed, since 0 signals "current app" in a BoxRef. But that doesn't work for inner apps, since BoxRefs only appear at the top-level and they are "resolved" there, to the app id at the top-level.

This seems like a naming issue, "How can we name these inner create boxes"? That seems hard. But, we are in luck, because there's really no reason to be so stingy with access to boxes for newly created apps. Those boxes can't exist, because the app is new, so we can short circuit the lookup on disk.

We know they are empty, so we need not worry about exceeded read quota. We will still treat them as dirty, so standard write quota checks will handle that side.

We bound the number of boxes that can be accessed this way by the number of empty box refs. This means that the number of boxes written is bounded, not just the sum of the lengths.

Test Plan

Added new tests in boxtxn_test.go that exercises the new capabilities (and ensure they are no usable in old versions)

We know they are empty, so we need not worry about exceeded read
quota.  We will still treat them as dirty, so we need not worry about
exceed write quota.

We bound the number of boxes that can be accessed this way by the
number of empty box refs.  This means that the _number_ of boxes
written is bounded, not just the sum of the lengths.
@jannotti jannotti changed the title Allow access of boxes for apps in made in the same group AVM: Allow unnamed access of boxes for apps in made in the same group Apr 23, 2025
@jannotti jannotti self-assigned this Apr 23, 2025
@jannotti jannotti requested a review from Copilot April 23, 2025 20:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements support for unnamed box access in newly created apps within the same group. It updates transaction and box logic to allow a one‑time empty box reference access, and adds comprehensive tests to verify the new behavior.

  • Added tests in boxtxn_test.go to cover various unnamed box creation cases.
  • Updated resources and box handling in the logic package to account for unnamed access.
  • Modified consensus parameters in config/consensus.go to enable the new feature.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
ledger/boxtxn_test.go New tests for unnamed box access and minor documentation updates
data/transactions/logic/resources.go Added tracking for unnamedAccess in box resources
data/transactions/logic/box.go Updated availableBox to permit unnamed box access in new apps
config/consensus.go Added the EnableUnnamedBoxAccessInNewApps consensus parameter and set it in vFuture
Files not reviewed (1)
  • Makefile: Language not supported

Comment thread ledger/boxtxn_test.go Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 23, 2025

Codecov Report

Attention: Patch coverage is 68.54839% with 39 lines in your changes missing coverage. Please review.

Project coverage is 51.59%. Comparing base (5c49e9a) to head (4ab48f2).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
daemon/algod/api/server/v2/utils.go 0.00% 14 Missing ⚠️
ledger/simulation/resources.go 84.84% 4 Missing and 6 partials ⚠️
data/transactions/logic/box.go 66.66% 6 Missing and 2 partials ⚠️
data/basics/overflow.go 75.00% 1 Missing and 1 partial ⚠️
data/transactions/logic/eval.go 75.00% 1 Missing and 1 partial ⚠️
data/transactions/logic/resources.go 0.00% 1 Missing and 1 partial ⚠️
daemon/algod/api/server/v2/handlers.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6309      +/-   ##
==========================================
- Coverage   51.60%   51.59%   -0.01%     
==========================================
  Files         649      649              
  Lines       87013    87070      +57     
==========================================
+ Hits        44903    44925      +22     
- Misses      39244    39273      +29     
- Partials     2866     2872       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SilentRhetoric
Copy link
Copy Markdown

[Nit] Consider amending the title to the following for clarity:

Allow access to boxes for apps of unknown ID made in the same group

@jannotti jannotti changed the title AVM: Allow unnamed access of boxes for apps in made in the same group AVM: Allow access to boxes for apps made in the same group without explicit boxrefs Apr 24, 2025
@jannotti
Copy link
Copy Markdown
Contributor Author

[Nit] Consider amending the title to the following for clarity:

Allow access to boxes for apps of unknown ID made in the same group

I hope the current title is clearer.

@jannotti
Copy link
Copy Markdown
Contributor Author

jannotti commented Apr 24, 2025

The following concern is noted:

One thing that comes to mind is making sure simulate will see this. We need to make sure that a client that uses simulate to populate references is able to get data to know that it needs an empty reference for the create attempt.

That's a good call-out. I'm not sure exactly how to handle it, but we should certainly do something. I'm not exactly sure what the state of auto resource population is. But yes, we certainly don't want to tell callers: You need a box ref for {28734, "hello"} just because the app created during simulation happened to be 28734. We need to report that adding {0,""} would make the call work.

This includes some additional bugs fixes.  Previously, `simulate`
would report a boxref that included a newly created app's ID when used
with AllowUnnamedResources.  That is, in some sense, correct, but
useless, since a follow-on transaction that used such a box ref would
surely have the wrong app id, and would still fail.

Now, such a box ref will be converted to an empty ref if
EnableUnnamedBoxAccessInNewApps is true.

I considered always converting, but there are corner cases in which a
very clever user of simulate could correctly use the old result.
After the change, the new result is always strictly easier to use.
@jannotti jannotti force-pushed the create-unnamed-boxes branch from 71519d6 to 4ab48f2 Compare April 29, 2025 19:31
@jannotti
Copy link
Copy Markdown
Contributor Author

The following concern is noted:

One thing that comes to mind is making sure simulate will see this. We need to make sure that a client that uses simulate to populate references is able to get data to know that it needs an empty reference for the create attempt.

That's a good call-out. I'm not sure exactly how to handle it, but we should certainly do something. I'm not exactly sure what the state of auto resource population is. But yes, we certainly don't want to tell callers: You need a box ref for {28734, "hello"} just because the app created during simulation happened to be 28734. We need to report that adding {0,""} would make the call work.

It will now properly report that, say, 3 empty refs are needed, if you touch 3 boxes in a newly created app.

Previously, the simulate endpoint would simply report the app,name combo for any app touched, even if the app was a new ID. If a caller used that information blindly, it would certainly fail because the appID would be different when submitted. You might be able to construct torturous uses that would work, if the caller paid enough attention to the result to note that the appID returned matches the appID created in a later top-level transaction. So we left the old behaviour until a consensus change that enables this feature.

@jannotti jannotti marked this pull request as ready for review April 30, 2025 13:39
Comment thread daemon/algod/api/server/v2/utils.go
Comment thread data/transactions/logic/box.go
Comment thread data/transactions/logic/box.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jannotti jannotti requested a review from Copilot August 11, 2025 14:30

This comment was marked as outdated.

Comment thread daemon/algod/api/server/v2/handlers.go
Comment thread data/basics/overflow.go
Comment thread data/transactions/logic/eval.go
Comment thread Makefile
Comment thread data/transactions/logic/resources.go
@gmalouf gmalouf requested a review from Copilot August 12, 2025 18:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a feature that allows newly created apps within a transaction group to access boxes without explicit box references. The change enables more flexible box creation patterns for inner apps and eliminates the need to predict app IDs for box references in certain scenarios.

Key changes:

  • Adds EnableUnnamedBoxAccessInNewApps consensus parameter to enable the feature
  • Introduces empty box references that can be "consumed" to allow box access in newly created apps
  • Updates simulation and resource tracking to handle the new access pattern

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
config/consensus.go Adds new consensus parameter EnableUnnamedBoxAccessInNewApps
data/transactions/logic/resources.go Implements tracking of unnamed access slots from empty box refs
data/transactions/logic/eval.go Updates evaluation to handle new app box access and surplus budget calculation
data/transactions/logic/box.go Core logic for allowing box access in newly created apps without explicit refs
ledger/simulation/resources.go Updates resource tracking to support new box access patterns and I/O surplus handling
ledger/boxtxn_test.go Comprehensive tests for the new box access capabilities
Multiple test files Updates to handle new BoxStat structure and simplified resource tracking

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread ledger/simulation/testing/utils.go
Comment thread ledger/simulation/simulation_eval_test.go
Comment thread data/transactions/logic/resources.go
Comment thread data/transactions/logic/box.go
Comment thread ledger/boxtxn_test.go Outdated
Comment thread data/transactions/logic/eval.go
Comment thread data/transactions/logic/eval.go
Comment thread ledger/simulation/simulation_eval_test.go Outdated
Copy link
Copy Markdown
Contributor

@gmalouf gmalouf left a comment

Choose a reason for hiding this comment

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

Left a few questions/comments

algorandskiy
algorandskiy previously approved these changes Aug 13, 2025
Co-authored-by: Gary Malouf <982483+gmalouf@users.noreply.github.com>
Comment thread ledger/simulation/resources.go Outdated
Comment thread ledger/simulation/resources.go
gmalouf
gmalouf previously approved these changes Aug 13, 2025
@gmalouf gmalouf requested a review from algorandskiy August 13, 2025 18:07
algorandskiy
algorandskiy previously approved these changes Aug 13, 2025
@jannotti jannotti dismissed stale reviews from algorandskiy and gmalouf via 5f3ae27 August 14, 2025 16:01
Comment thread ledger/boxtxn_test.go
const boxQuotaBumpVersion = 41
const (
boxVersion = 36
accessVersion = 38
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what happened in v38?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That v9 of AVM, and tx.Access is not allowed until then. (It's when resource sharing happened, so I couldn't easily make tx.Access work for earlier versions.)

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.

7 participants