-
Notifications
You must be signed in to change notification settings - Fork 540
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
bug: get_caller_address()
returns 0x0
when called inside an external view function
#6959
Comments
I should note I'm using cairo v2.8.4 because that's the current supported cairo version by dojo at the time of writing, maybe this is fixed in newer releases but I didn't get a chance to check and didn't see any issues reported prior so I'm assuming it may still be a bug. I suspect it may have something to do with snapshots and how they interact with |
get_caller_address()
returns 0x0 when called inside an external view functionget_caller_address()
returns 0x0
when called inside an external view function
There's no such thing as a "call transaction" - either it's a transaction (or invoke transaction) or an RPC call. If you're talking about an RPC call, the result is expected to be 0. The RPC call is not made from an address. I think in EVM worlds the RPC lets you set who the |
Makes sense, thanks for the clarification!
In this case, my only concern/confusion would be if there's anything else that's not set in the sequencer when doing such calls, as opposed to transactions? Because it just seems inconsistent that the same function will work correctly when invoked within a contract, but not when done from outside (with a call). Also, if I understand correctly, invoke transactions cannot return values when called externally? |
Bug Report
Cairo version:
v2.8.4
Current behavior:
Calling
get_caller_address()
within an external view function returns the0x0
contract address. This was discovered when using starket.js within a svelte application and additionally reproduced in both sozo call and starkli call within dojo contracts and cairo contracts respectively.Oddly enough, calling the same view function from within another external write function (aka a function that takes
ContractState
by reference and can modify state) does not have this issue and retrieves the correct contract address for use within the function (example provided below).Expected behavior:
Calling
get_caller_address()
should return the caller's contract address (which should never be0x0
)Steps to reproduce:
scarb new <some_project>
@ContractState
and returnsContractAddress
.get_caller_address()
Related code:
Other information:
In the code snippet above,
view_caller_function()
incorrectly returns the0x0
contract address when called inside a call transaction, whether it be from starknet.js, sozo, or starkli inside either a dojo or vanilla cairo contract.set_caller_address_from_view_function
does not have this problem when called inside an invoke transaction, as it correctly reads the user's contract address and modifies thecaller_address
field in the contract's storage, even though it also callsview_caller_function()
within itself.The text was updated successfully, but these errors were encountered: