From e8df502bcfedfcca8870884c218b14d84bffb26b Mon Sep 17 00:00:00 2001 From: Milosz Muszynski Date: Tue, 21 May 2024 12:06:21 +0200 Subject: [PATCH] charlie-contract: removed subsidy types crate --- contracts/charlie/Cargo.toml | 4 +++- contracts/charlie/src/state.rs | 35 +++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/contracts/charlie/Cargo.toml b/contracts/charlie/Cargo.toml index 6901d8ef9..3495ea8b2 100644 --- a/contracts/charlie/Cargo.toml +++ b/contracts/charlie/Cargo.toml @@ -8,8 +8,10 @@ resolver = "2" crate-type = ["cdylib", "rlib"] [dependencies] +rkyv = { version = "0.7", default-features = false, features = ["size_32"] } +bytecheck = { version = "0.6", default-features = false } +bls12_381-bls = { version = "0.2", default-features = false, features = ["rkyv-impl"] } phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] } rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", features = ["dlmalloc"] } dusk-bytes = "0.1" transfer-contract-types = { version = "0.1.0", path = "../transfer-types", default-features = false } -subsidy-types = { version = "0.0.1", path = "../subsidy-types", default-features = false } diff --git a/contracts/charlie/src/state.rs b/contracts/charlie/src/state.rs index 5f12929e1..4e7001553 100644 --- a/contracts/charlie/src/state.rs +++ b/contracts/charlie/src/state.rs @@ -4,13 +4,46 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use alloc::vec::Vec; +use bls12_381_bls::{PublicKey, Signature}; +use dusk_bytes::Serializable; +use rkyv::{Archive, Deserialize, Serialize}; use rusk_abi::TRANSFER_CONTRACT; -use subsidy_types::*; use transfer_contract_types::Stct; #[derive(Debug, Clone)] pub struct Charlie; +/// Subsidy a contract with a value. +#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)] +#[archive_attr(derive(bytecheck::CheckBytes))] +pub struct Subsidy { + /// Public key to which the subsidy will belong. + pub public_key: PublicKey, + /// Signature belonging to the given public key. + pub signature: Signature, + /// Value of the subsidy. + pub value: u64, + /// Proof of the `STCT` circuit. + pub proof: Vec, +} + +const SUBSIDY_MESSAGE_SIZE: usize = u64::SIZE + u64::SIZE; + +/// Return the digest to be signed in the `subsidize` function of a contract. +#[must_use] +pub fn subsidy_signature_message( + counter: u64, + value: u64, +) -> [u8; SUBSIDY_MESSAGE_SIZE] { + let mut bytes = [0u8; SUBSIDY_MESSAGE_SIZE]; + + bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes()); + bytes[u64::SIZE..].copy_from_slice(&value.to_bytes()); + + bytes +} + impl Charlie { fn gas_price() -> u64 { rusk_abi::call::<(), u64>(TRANSFER_CONTRACT, "gas_price", &())