Skip to content
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

Motoko interpreter determines caller incorrectly #4485

Open
reginleif888 opened this issue Apr 4, 2024 · 3 comments
Open

Motoko interpreter determines caller incorrectly #4485

reginleif888 opened this issue Apr 4, 2024 · 3 comments

Comments

@reginleif888
Copy link

reginleif888 commented Apr 4, 2024

Problem statement: The interpreter determines the caller incorrectly if the call is made not from the actor directly, but inside the object that the actor uses. In a call made from an object, the caller is always ID:0

Command used: moc -r

Motoko version: 0.11.1

Code:

import Debug "mo:base/Debug";
import Principal "mo:base/Principal";
import Text "mo:base/Text";

actor exampleActor {
  public shared (msg) func printCaller() : async () {
    Debug.print("caller: " # debug_show Text.decodeUtf8(Principal.toBlob(msg.caller)));
  };
};

class ExampleClass() {
  public func exampleMethod() : async* () {
    await exampleActor.printCaller();
  };
};

actor agent = {
  public func test() : async () {
    let example : ExampleClass = ExampleClass();

    let agentPrincipal = Principal.fromActor(agent);

    Debug.print("agent: " # debug_show Text.decodeUtf8(Principal.toBlob(agentPrincipal)));

    await exampleActor.printCaller();

    await* example.exampleMethod();
  };
};

await agent.test();

Actual output:

agent: ?"ID:2"
caller: ?"ID:2"
caller: ?"ID:0"

Expected output:

agent: ?"ID:2"
caller: ?"ID:2"
caller: ?"ID:2"
@timohanke
Copy link
Contributor

If we move the definition of ExampleClass inside the agent actor then it works (not surprising).

Would be nice to get this fixed in the interpreter.

@crusso
Copy link
Contributor

crusso commented Apr 5, 2024

Yeah, that looks like a bug. Thanks for reporting it! I would regard this as low priority, since the IC doesn't support multiple actors in the same canister.

How important is the fix to you?

@reginleif888
Copy link
Author

It's low priority. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants