gottstech / gotts

A blockchain for non-collateralized stable-coins, follow MimbleWimble protocol but with explicit amount.
https://gotts.tech
Apache License 2.0
48 stars 4 forks source link

refact: share the SecuredPath structure for OutputLocker #40

Closed garyyu closed 4 years ago

garyyu commented 4 years ago

Refactoring the OutputLocker structure.

The original structure:

struct OutputLocker {
    /// The Hash of 'Pay-to-Public-Key-Hash'.
    p2pkh: Hash,
    /// The 'R' for ephemeral key: `q = Hash(secured_w || p*R)`.
    pub_nonce: PublicKey,
    /// The secured version of 'w' for the Pedersen commitment: `C = q*G + w*H`,
    /// the real 'w' can be calculated by: `w = secured_w XOR q[0..8]`.
    secured_w: u64,
    /// The relative lock height, after which the output can be spent.
    relative_lock_height: u32,
}

The new structure:

pub struct OutputLocker {
    /// The Blake2b hash of 'Pay-to-Public-Key-Hash'.
    pub p2pkh: Hash,
    /// The 'R' for ephemeral key: `q = Hash(secured_w || p*R)`.
    pub pub_nonce: PublicKey,
    /// A secured path message which hide the key derivation path and the random w of commitment.
    pub spath: SecuredPath,
}

The PathMessage structure:

pub struct PathMessage {
    /// The random 'w' of Pedersen commitment `r*G + w*H`
    pub w: i64,
    /// The last path index of the key identifier
    pub key_id_last_path: u32,
}

Regarding the relative_lock_height:

This refactoring is making the code more simple and better readable, and the new key_id_last_path will be helpful for wallet to check/restore all non-interactive outputs under one wallet account.