Return Value Strangenesses #127
Comments
Isn't this because account can have multiple calls? |
@unparalleled-js How does this differ from responses you get from alpha-goerli? |
This comment was marked as outdated.
This comment was marked as outdated.
@unparalleled-js have you been able to compare with output from alpha-goerli? |
I finally got a comparison with alpha-goerli. Returned data are identical to the devnet (tx): $ starknet get_transaction_receipt --hash '0x552334e3dfb31d87d62eb9c1483551c30f03c91e5aa7af376df030646c21123' --network 'alpha-goerli' | jq '.events[0].data' [
"0x552334e3dfb31d87d62eb9c1483551c30f03c91e5aa7af376df030646c21123",
"0x4",
"0x3",
"0x1",
"0x2",
"0x3"
]
|
I adapted the test contract to generate an array with 10 elements. tx details: $ starknet get_transaction_receipt --hash 0x67411b96d1b4cca009c7ae16cad46be17aa21000de8c4431b6f5c227f6e7aae --network alpha-goerli | jq '.events[0].data' [
"0x67411b96d1b4cca009c7ae16cad46be17aa21000de8c4431b6f5c227f6e7aae",
"0xb",
"0xa",
"0x1",
"0x2",
"0x3",
"0x4",
"0x5",
"0x6",
"0x7",
"0x8",
"0x9",
"0x0"
] |
In a diff of the same contract compiled with Cairo 0.8.2.1, and 0.9.0, I can see such changes: "__wrappers__.get_array.Return": {
- "full_name": "__wrappers__.get_array.Return",
- "members": {
- "pedersen_ptr": {
- "cairo_type": "starkware.cairo.common.cairo_builtins.HashBuiltin*",
- "offset": 1
- },
- "range_check_ptr": {
- "cairo_type": "felt",
- "offset": 2
- },
- "retdata": {
- "cairo_type": "felt*",
- "offset": 4
- },
- "size": {
- "cairo_type": "felt",
- "offset": 3
- },
- "syscall_ptr": {
- "cairo_type": "felt*",
- "offset": 0
- }
- },
- "size": 5,
- "type": "struct"
+ "cairo_type": "(syscall_ptr : felt*, pedersen_ptr : starkware.cairo.common.cairo_builtins.HashBuiltin*, range_check_ptr : felt, size : felt, retdata : felt*)",
+ "type": "type_definition"
}, - "ret_struct": {
- "cairo_type": "__main__.get_array.Return",
+ "ret_value": {
+ "cairo_type": "(arr_len : felt, arr : felt*)", "__wrappers__.get_array_encode_return.Return": {
- "full_name": "__wrappers__.get_array_encode_return.Return",
- "members": {
- "data": {
- "cairo_type": "felt*",
- "offset": 2
- },
- "data_len": {
- "cairo_type": "felt",
- "offset": 1
- },
- "range_check_ptr": {
- "cairo_type": "felt",
- "offset": 0
- }
- },
- "size": 3,
- "type": "struct"
+ "cairo_type": "(range_check_ptr : felt, data_len : felt, data : felt*)",
+ "type": "type_definition"
}, The return type changes from |
FTR I tested a modified version of the contract that does not touch to the storage var, just to isolate more the behavior. It changes nothing, results are the same. Here is the epured contract: %lang starknet
from starkware.cairo.common.alloc import alloc
@external
func get_array() -> (arr_len : felt, arr : felt*):
alloc_locals
let (local arr : felt*) = alloc()
assert arr[0] = 1
assert arr[1] = 2
assert arr[2] = 3
return (arr_len=3, arr=arr)
end |
I was wondering if the return type changes when returning a simple integer: it still return an additional value: Contract (you can play with it here): %lang starknet
from starkware.cairo.common.alloc import alloc
@external
func get_array() -> (arr_len : felt, arr : felt*):
alloc_locals
let (local arr : felt*) = alloc()
assert arr[0] = 1
assert arr[1] = 2
assert arr[2] = 3
return (arr_len=3, arr=arr)
end
@external
func get_int() -> (res : felt):
return (res=42)
end |
If calling through an account, it is expected behavior to have the first returned value be the length of the return sequence (might depend on account implementation, but I believe they all work that way). Doesn't look like unwanted behavior, I'll be closing this. Tell me if you think it should be reopened. |
I am noticing some odd behaviors with return values as of recently where the length of return arguments is included. Here are the scenarios I have tried:
The text was updated successfully, but these errors were encountered: