rocklabs-io / omnic

Omnic protocol repo
25 stars 7 forks source link

[impl] Proxy canister implementation #11

Closed ccyanxyz closed 2 years ago

ccyanxyz commented 2 years ago

https://github.com/rocklabs-io/omnic/blob/refactor/core/ic/refactor/proxy.rs

Proxy canister is responsible for:

  1. fetch merkle roots from external chains
  2. process messages from relayer canister

@Myse1f

ccyanxyz commented 2 years ago

Code updated @Myse1f

Myse1f commented 2 years ago

https://github.com/rocklabs-io/omnic/blob/9c726f0c152bc576e6eba22adc313110a2d4a29d/core/ic/refactor/proxy.rs#L58

What's the encoding format of the message? How to parse Vec<u8> to struct message.

ccyanxyz commented 2 years ago

Proof format: https://github.com/nomad-xyz/rust/blob/main/accumulator/src/proof.rs#L8 Message format: https://github.com/nomad-xyz/rust/blob/main/nomad-core/src/types/messages.rs#L8 No need to be Vec, can use String and use serde_json to deseralized the params into types

Myse1f commented 2 years ago

Seems Merkle root can be calculated by proof only by proof.merkle_root_from_branch?

Message only determines whether it needs verification? Or we can only pass need_verify to process_message?

ccyanxyz commented 2 years ago

merkle root can be calculated from proof(merkel path) + message hash(leaf node value)

need_verify is changed to wait_optimistic, indicates whether or not to wait for the optimistic verification challenge window.

Myse1f commented 2 years ago

I think message hash is the field leaf of proof?

https://github.com/rocklabs-io/omnic/blob/9c726f0c152bc576e6eba22adc313110a2d4a29d/core/ic/accumulator/src/proof.rs#L11

https://github.com/rocklabs-io/omnic/blob/9c726f0c152bc576e6eba22adc313110a2d4a29d/core/ic/accumulator/src/proof.rs#L53-L58

Or need to assert proof.leaf == message.hash? Or assign proof.leaf = message.hash?

ccyanxyz commented 2 years ago

No need to assign, proxy canister verification logic:

if msg.wait_optimistic == false:
    root = calc_root(proof, msg.hash)
    if root in chain_roots:
        true
    else:
        false
else:
    root = calc_root(proof, msg.hash)
    if root in chain_roots and root_confirm_time < time.now():
        true
    else:
        false