rooch-network / rooch

VApp Container with Move Language
https://rooch.network
Apache License 2.0
128 stars 54 forks source link

[Framework] Random Number on-chain solution #759

Open jolestar opened 8 months ago

jolestar commented 8 months ago
pause125 commented 8 months ago

How about generating random seed in Rust and stored in TxContext, and then read it in contract?

jolestar commented 8 months ago

How about generating random seed in Rust and stored in TxContext, and then read it in contract?

It is unverifiable

pause125 commented 8 months ago

How about generating random seed in Rust and stored in TxContext, and then read it in contract?

It is unverifiable

May the verifiable feature is not required unless we have consensus mechanism? We can emit an event every query a random number.

jolestar commented 8 months ago

May the verifiable feature is not required unless we have consensus mechanism?

The transaction needs to be synced to another executor or proposer node, so the execution result must be determinate. Maybe we can put the sequencer's transaction witness data in the TxContext, and sync the transaction and witness data together. #771

MaggieNgWu commented 6 months ago

ZK-VRF please refer:

https://github.com/zkvrf/zkvrf https://github.com/jae-cuz/zk-draw

jolestar commented 6 months ago

A simple solution:

  1. Let the sequencer generate a random seed and add it to TransactionSequenceInfo.
  2. Include the seed in the data of the sequencer signature.
  3. In the future, we can improve the random seed by zkVRF.
pub struct TransactionSequenceInfo {
    /// The tx order
    pub tx_order: u128,
    /// The tx order signature, it is the signature of the sequencer to commit the tx order.
    pub tx_order_signature: Authenticator,
    /// The tx accumulator root after the tx is append to the accumulator.
    pub tx_accumulator_root: H256,
}

Or can we directly use the tx_order_signature as the random seed?