Skip to content

Instantly share code, notes, and snippets.

@tgrecojs
Last active February 3, 2024 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgrecojs/71ed5f69356eef848a9b0e0328cffb79 to your computer and use it in GitHub Desktop.
Save tgrecojs/71ed5f69356eef848a9b0e0328cffb79 to your computer and use it in GitHub Desktop.
confusion around `endo send`, evaluating code as an `EndoGuest` - a @tgrecojs reproduction

Fun with endo featuring send, inbox, inbox -a <pet-name> -a <pet-name> and more! 🤠🤠

  1. Make the clock plug-in using endo make --UNCONFINED
~/ ==> git clone https://gist.github.com/tgrecojs/71ed5f69356eef848a9b0e0328cffb79 && cd $_
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo make --UNSAFE src/clock.js -n clock 
Object [Alleged: Clock] {}
  1. Test that it is working properly.
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo eval 'E(c).time()' c:clock
1706998435806
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo eval 'E(c).time()' c:clock
1706998444083
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo eval 'E(c).time()' c:clock
1706998445359
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo eval 'E(c).time()' c:clock
1706998445896
  1. make a guest object meant to mimic an outside party who woud like to make use of your pet-store's Clock.
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo mkguest alice
Object [Alleged: EndoGuest] {}
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo send alice @clock
  1. Inspect alice's inbox and adopt the Clock remotable
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo inbox -a alice
0. "HOST" sent "@clock" at "2024-02-03T22:07:27.189Z"
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo adopt 0 clock -a alice
  1. Confirm that alice has succesfully added the Clock to her pet-store.
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo list -a alice
clock
  1. While acting as alice, attempt to use the clock in the same manner shown in step #2 and watch as execuation fails.
    • Question
      • Is it right to assume the an EndoGuest will never have the powers necessary to call endo eval despite having been explicitly given a reference (and despite this reference being present in their pet-store)?
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo eval "E(c).time()" c:clock -a alice
CapTP cli exception: (RemoteTypeError(error:captp:Endo#20001)#1)
RemoteTypeError(error:captp:Endo#20001)#1: target has no method "evaluate", has ["__getMethodNames__","adopt","dismiss","followEntries","followMessages","followNames","has","list","listEntries","listMessages","lookup","reject","remove","rename","request","resolve","reverseLookup","send"]

  at decodeErrorCommon (packages/marshal/src/marshal.js:281:28)
  at decodeErrorFromCapData (packages/marshal/src/marshal.js:297:14)
  at decodeFromCapData (packages/marshal/src/encodeToCapData.js:384:27)
  at fromCapData (packages/marshal/src/marshal.js:359:23)
  at CTP_RETURN (packages/captp/src/captp.js:696:24)
  at dispatch (packages/captp/src/captp.js:775:7)
  at packages/daemon/src/connection.js:34:7

(RemoteTypeError(error:captp:Endo#20001)#1)
  1. Carry out the following actions:
    • Create an EndoHost,
    • sending the Clock to the EndoHost.
    • adopt the Clock while acting as the EndoHost
    • evaluate the Clock's time method while acting as this host
    • Watch as it works as expected
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo mkhost host-alice
Object [Alleged: EndoHost] {}
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo send host-alice @clock
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo adopt 0 clock -a host-alice
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo eval "E(c).time()" c:clock -a host-alice
1706998558036

Send Clock owned by a specific EndoHost

  1. create a new host and create a new clock as this agent.
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo mkhost timemaster
Object [Alleged: EndoHost] {}
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo make -a timemaster ./clock.js -n master-clock
Object [Alleged: Clock] {}
  1. inspect the EndoHost pet-store for master-clock before removing clock from host-alice's pet-store
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo list -a timemaster
master-clock
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo list -a host-alice
clock
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo remove -a host-alice clock
  1. send host-alice a reference to Clock while acting as timemaster and watch as error ensues....
    • Question
      • Is this failing because the EndoHost timemaster does not have host-alice in its pet-store?
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo send host-alice @clock -a timemaster
CapTP cli exception: (RemoteError(error:captp:Endo#20001)#1)
RemoteError(error:captp:Endo#20001)#1: Unknown pet name for party: host-alice

  at decodeErrorCommon (packages/marshal/src/marshal.js:281:28)
  at decodeErrorFromCapData (packages/marshal/src/marshal.js:297:14)
  at decodeFromCapData (packages/marshal/src/encodeToCapData.js:384:27)
  at fromCapData (packages/marshal/src/marshal.js:359:23)
  at CTP_RETURN (packages/captp/src/captp.js:696:24)
  at dispatch (packages/captp/src/captp.js:775:7)
  at packages/daemon/src/connection.js:34:7

(RemoteError(error:captp:Endo#20001)#1)
  1. Attempt to resolve this issue by:
    • creating a new host while acting as timemaster.
    • sending the new host a reference to timemaster's Clock reference.
~/71ed5f69356eef848a9b0e0328cffb79 ==> endo mkhost -a timemaster timemaster-alice
Object [Alleged: EndoHost] {}
~/71ed5f69356eef848a9b0e0328cffb79 ==>  endo send -a timemaster timemaster-alice @master-clock
  1. Check the inbox of timemaster-alice (which exists within the pet-store of timemaster
    • Question
      • Why does this error out?
      • Although this errors, running endo inbox -a timemaster
~/71ed5f69356eef848a9b0e0328cffb79 ==>  endo inbox -a timemaster -a timemaster-alice
TypeError#1: Cannot destructure property 'number' of 'message' as it is undefined.

  at packages/cli/src/commands/inbox.js:22:15
  at async packages/cli/src/context.js:72:7
  at async packages/cli/src/context.js:55:7
  at async packages/cli/src/context.js:43:5
  at async withInterrupt (packages/cli/src/context.js:14:5)
  at async Promise.all (index 0)
  at async main (packages/cli/src/endo.js:642:5)
  at async packages/cli/bin/endo.cjs:4:3
  1. Inspect the timemaster's inbox and see the request
    • Question
      • Is this the correct behavior? I expected for the nested endo inbox commands to show any messages that were sent to the last inbox referenced when executing the command.
endo inbox -a timemaster
0. "SELF" sent "@master-clock" at "2024-02-03T22:38:18.884Z"

Additional Notes

  • At this point, my daemon was turned upside down. For example, executing endo send host-alice @clock followed by endo inbox -a host-alice did not show any messages in the inbox. Oddly enough, endo adopt <message-number> -a host-alice resulted in clock appearing in host-alice's pet-store.
  • This was verified by calling endo inbox -a host-alice only to see a new clock reference. Note: the initial clock held by host-alice was removed prior to this, so it is not the same clock.
{
"name": "endo-send-issue",
"version": "1.0.0",
"main": "time.js",
"type": "module",
"author": "Thomas Greco <tg18509@pm.me>",
"dependencies": {
"@endo/far": "^1.0.2"
}
}
/** needs --UNCONFINED for access to Date.now() */
import { Far } from '@endo/far';
export const make = () =>
Far('Clock', {
time: () => Date.now(),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment