I believe the rationale for not counting push-bytes to the alt stack is that alt stack data can’t be directly referenced by other ops. Per @bitjson:
Because stack-pushed bytes become inputs to other operations, limiting the overall density of pushed bytes is the most comprehensive method of limiting all sub-linear and linear-time operations…
https://github.com/bitjson/bch-vm-limits/blob/master/rationale.md#limitation-of-pushed-bytes
It seems like the above rationale for not counting push-bytes for OP_TOALTSTACK also could apply to OP_DEFINE. Both have the number of “slots” limited by MAX_STACK_SIZE. But if you view push-bytes as the “bytes copy cost” then it makes sense to apply it for OP_DEFINE. Would be good to hear @bitjson’s view on this.
The tests do push non-zero byte functions to the function table. However, the expected cost totals don’t include the OP_DEFINE push-bytes cost. Am I using old tests? I get the test vectors from:
https://github.com/bitauth/vmb_tests (08133da2 / Sep 5, 2025)
MD5 checksums for the relevant ‘chip.functions’ files:
a7f334255e49646bbddc43e18ef76416 test/libauth/bch_2026_standard/chip.functions.vmb_tests.json
d2cb7aee7f62c537ceae15c0d102f27b test/libauth/bch_2026_standard/chip.functions.standard_limits.json
The ‘vmb_tests’ file above contains the tests and the ‘standard_limits’ file the expected costs. I can see that the BCHN repo (89a591f7) contains the same ‘vmb_tests’ file (same checksum) but I can’t find the ‘standard_limits’ file. Where do you get the expected cost from?
Now, take test “maamwz” as an example. The test executes this code:
<<OP_2> OP_1 OP_DEFINE OP_1> <\"\"> OP_DEFINE <\"\"> OP_INVOKE OP_INVOKE <2> OP_EQUAL
If I disable OP_DEFINE push-bytes accounting in AlbaVm, then the cost of the above code is 1311 which agrees with the number in the ‘standard_limits’ file. If I enable OP_DEFINE push-bytes accounting, then the cost comes to 1317. The extra 6 in cost is due to the push-bytes cost for the two function bodies that get defined (5 and 1 bytes in size respectively).