-
Notifications
You must be signed in to change notification settings - Fork 519
Txn: move/add asset txn validation into their own wellFormed methods #6396
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
Conversation
acfg - moved: + AssetName must not be longer than MaxAssetNameBytes. This was moved from `data/transactions/transaction.go:Transaction.WellFormed()`. + UnitName must not be longer than MaxAssetUnitNameBytes. This was moved from `data/transactions/transaction.go:Transaction.WellFormed()`. + URL must not be longer than MaxAssetURLBytes. This was moved from `data/transactions/transaction.go:Transaction.WellFormed()`. + Decimals must not be greater than MaxAssetDecimals. This was moved from `data/transactions/transaction.go:Transaction.WellFormed()`. axfer - new: + XferAsset must not be zero (missing). This was previously caught by `ledger/apply/asset.go` as "asset 0 does not exist or has been deleted". + AssetSender and AssetCloseTo cannot both be set. This was previously caught by `ledger/apply/asset.go` as "cannot close asset by clawback". afrz - new: + FreezeAsset must not be zero (missing). This was previously caught by `ledger/apply/asset.go` as "asset 0 does not exist or has been deleted". + FreezeAccount must not be zero (missing). This was previously caught by `ledger/apply/asset.go` as "asset not found in account".
|
|
I think this is great. I totally missed that we were doing some of these checks later in Transaction.WellFormed when I added the new wellFormed methods on the different kinds of fields. I suppose one could debate whether the zero-address check on afrz is appropriate for wellFormed. I am ok with it, but one could make the argument that there's a logicsig out there somewhere that hashes to the zeroaddress, and maybe it can opt into an asset some day. I think we're allowed to discount that possibility. I lean away from introducing all these: They're not exported (which is a goof thing, IMO), so it's not like there could be an equality check on them. I'm fine with putting the To my mind, creating the variable advertises: "Callers can count on this thing, and compare errors to it." I hate that thinking because maybe we want to change them (maybe people complain the message should contain the big asset name, or the length, or whatever.) |
|
There are probably unit tests that ought to be moved to |
|
On the question of checking for the zeroAddress on EDIT: So yes, I think we reasonably have the check against zeroAddress in afrz - there's no way it can opt in. |
|
Uh oh, a 0 transfer of the 0 asset is legal! So, we can't make it illegal. It's legal because we don't look up the asset params for axfer (which is where the 0 asset would previously be detected). And we don't check opt-in for a 0 transfer. |
Currently, it is possible to send a 0 asset amount to a receiver who has not opted into the asset. I think we should not change this. |
@nullun, just a note: when we discussed a possible retro-compatible way to implement an ASA global freeze, the |
I think that option would remain, even with this change. Obviously we would then allow it with that new meaning, but for now it's illegal, and this just changes where we detect it. |
|
FYI, this test failure: is an example where we are doing a 0 axfer to the 0 address in a test. (We're not explicitly testing that here, we're just relying on it to make writing this other test easy. So this failure is a true positive - it should keep working. |
For 0 amounts, I wonder if updating the if-statement to |
This extra check should be fine. The 0 axfer of the 0 asset or, in fact any asset number even if the asset doesn't exist, is legal today and surely someone has done it. Neither the sender nor receiver needs to be opted in. So we can't exclude 0 unless the amount is nonzero. PS. |
Co-authored-by: John Jannotti <jannotti@gmail.com>
|
They were already true, though they errored in `apply` rather than in well
formed. So I believe this is safe.
…On Wed, Aug 6, 2025, 3:45 PM Pavel Zbitskiy ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In data/transactions/asset.go
<#6396 (comment)>
:
> + if ax.XferAsset == 0 && ax.AssetAmount != 0 {
+ return errors.New("asset ID cannot be zero")
+ }
+
+ if !ax.AssetSender.IsZero() && !ax.AssetCloseTo.IsZero() {
+ return errors.New("cannot close asset by clawback")
+ }
+
sounds like these new restrictions should be consensus gated
—
Reply to this email directly, view it on GitHub
<#6396 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADL7TZENEOXM2QV65ZPUYL3MJLL7AVCNFSM6AAAAACCWOENCSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTAOJTHE4DKNBZGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I believe this change would also support sending an axfer of 0 amount to yourself (opt in) whilst also including a close-out to yourself (close out) in a single axfer
I think your change is correct, because it now errors if trying to opt-in to a non-existent asset. But you said it was "incorrectly failing a transaction". Wasn't the probably that it was incorrectly allowing the transaction (of opt-in of missing asset)? |
|
While I like the tests you added to |
Sorry, I meant it was failing the new test I added. The existing tests weren't incorrectly failing anything. Essentially the new test I added in that commit was attempting to send 0 amount of an asset. Neither the sender nor receiver were opted in. But the error being returned was saying
That's fair. I was originally just updating the tests to check for the correct error message, but got a bit carried away and thought I'd include a test for the two new wellFormed errors. Is it OK to leave them there for now, and once I'm back (going away for a week) I'll create separate a separate WellFormed test outside of the inner transaction tests. |
Whilst going through the specs I've been doubling checking what's there and how go-algorand is doing it. For asset transactions it felt like there should be more than we currently had. So I've created this PR to see if it's worth relocating the existing acfg checks and introducing some new axfer/afrz wellFormed checks which I feel make sense.
acfg - moved:
data/transactions/transaction.go:Transaction.WellFormed().data/transactions/transaction.go:Transaction.WellFormed().data/transactions/transaction.go:Transaction.WellFormed().data/transactions/transaction.go:Transaction.WellFormed().axfer - new:
ledger/apply/asset.goas "asset 0 does not exist or has been deleted".ledger/apply/asset.goas "cannot close asset by clawback".afrz - new:
ledger/apply/asset.goas "asset 0 does not exist or has been deleted".ledger/apply/asset.goas "asset not found in account".