stake_contract_types/
lib.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7//! Types used for transactions with Dusk's stake contract.
8
9#![no_std]
10#![deny(missing_docs)]
11#![deny(clippy::pedantic)]
12
13extern crate alloc;
14use alloc::vec::Vec;
15
16mod sig;
17mod stake;
18
19pub use sig::{
20    stake_signature_message, unstake_signature_message,
21    withdraw_signature_message,
22};
23pub use stake::{next_epoch, BlockHeight, StakeData, EPOCH};
24
25use bls12_381_bls::{PublicKey as StakePublicKey, Signature as StakeSignature};
26use dusk_bls12_381::BlsScalar;
27use phoenix_core::StealthAddress;
28
29use bytecheck::CheckBytes;
30use rkyv::{Archive, Deserialize, Serialize};
31
32/// Stake a value on the stake contract.
33#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
34#[archive_attr(derive(bytecheck::CheckBytes))]
35pub struct Stake {
36    /// Public key to which the stake will belong.
37    pub public_key: StakePublicKey,
38    /// Signature belonging to the given public key.
39    pub signature: StakeSignature,
40    /// Value to stake.
41    pub value: u64,
42    /// Proof of the `STCT` circuit.
43    pub proof: Vec<u8>,
44}
45
46/// Unstake a value from the stake contract.
47#[derive(Debug, Clone, PartialEq, Eq, Archive, Deserialize, Serialize)]
48#[archive_attr(derive(CheckBytes))]
49pub struct Unstake {
50    /// Public key to unstake.
51    pub public_key: StakePublicKey,
52    /// Signature belonging to the given public key.
53    pub signature: StakeSignature,
54    /// Note to withdraw to.
55    pub note: Vec<u8>, // todo: not sure it will stay as Vec
56    /// A proof of the `WFCT` circuit.
57    pub proof: Vec<u8>,
58}
59
60/// Withdraw the accumulated reward.
61#[derive(Debug, Clone, Archive, Deserialize, Serialize)]
62#[archive_attr(derive(CheckBytes))]
63pub struct Withdraw {
64    /// Public key to withdraw the rewards.
65    pub public_key: StakePublicKey,
66    /// Signature belonging to the given public key.
67    pub signature: StakeSignature,
68    /// The address to mint to.
69    pub address: StealthAddress,
70    /// A nonce to prevent replay.
71    pub nonce: BlsScalar,
72}
73
74///
75/// Events
76
77/// Event emitted after a stake contract operation is performed.
78#[derive(Debug, Clone, Archive, Deserialize, Serialize)]
79#[archive_attr(derive(CheckBytes))]
80pub struct StakingEvent {
81    /// Public key which is relevant to the event.
82    pub public_key: StakePublicKey,
83    /// Value of the relevant operation, be it stake, unstake, withdrawal,
84    /// reward, or slash.
85    pub value: u64,
86}