ref-fvm icon indicating copy to clipboard operation
ref-fvm copied to clipboard

Add a syscall to obtain the originator of a call

Open raulk opened this issue 3 years ago • 5 comments

The msg_caller syscall returns the immediate caller, i.e. the actor that called the current actor. This is all that built-in actors have needed up until now.

However, it's useful for expose the originator of the call (i.e. the account actor whose transaction initiated the call stack) for many use cases, e.g. escrow, loans, DeFi-like cases, staking, pledging, etc.

As a sidenote: Ethereum has two distinct opcodes for this: CALLER and ORIGIN, so at minimum we will need this capability for EVM compatibility.

raulk avatar Jan 26 '22 14:01 raulk

NOTE: We'll likely need a case where the origin is "system".

Stebalien avatar Jan 26 '22 21:01 Stebalien

hi~ is this ok for the issue?

btw, is a ActorID(0) enough for the origin "system", or we should define it separately like

pub enum Originator {
    System,
    Actor(ActorID),
}

dtynn avatar Jan 30 '22 14:01 dtynn

I think this is safer and more efficient than an exporting a static constant for the system address, and assuming than the user will perform a comparison.

raulk avatar Jan 30 '22 14:01 raulk

then there would be a

pub strcut Originator {
    pub is_system: bool,
    pub actor_id: u64,
}

or something like that in the fvm_shared::sys ?

dtynn avatar Jan 30 '22 15:01 dtynn

I think ActorId(0) is actually sufficient. That's the "from" address we're using for implicit calls.

Stebalien avatar Feb 16 '22 00:02 Stebalien