Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to [email protected] #1195

Merged
merged 8 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion contract-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

#![feature(lang_items)]
#![no_std]

extern crate alloc;
Expand Down
4 changes: 2 additions & 2 deletions contracts/governance/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl GovernanceState {
// If the broker was already set we need to recoup the memory, otherwise
// we will leak memory.
if last_broker != ptr::null_mut() {
unsafe { Box::from_raw(last_broker) };
let _ = unsafe { Box::from_raw(last_broker) };
}
}

Expand All @@ -162,7 +162,7 @@ impl GovernanceState {
// If the authority was already set we need to recoup the memory,
// otherwise we will leak memory.
if last_authority != ptr::null_mut() {
unsafe { Box::from_raw(last_authority) };
let _ = unsafe { Box::from_raw(last_authority) };
}
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/stake/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use poseidon_merkle::Opening as PoseidonOpening;
use rand::rngs::StdRng;
use rand::{CryptoRng, RngCore, SeedableRng};
use rusk_abi::dusk::{dusk, LUX};
use rusk_abi::{ContractData, ContractError, Error, RawResult, Session, VM};
use rusk_abi::{ContractData, ContractError, Error, Session, VM};
use rusk_abi::{STAKE_CONTRACT, TRANSFER_CONTRACT};
use transfer_circuits::{
CircuitInput, CircuitInputSignature, ExecuteCircuitOneTwo,
Expand Down Expand Up @@ -164,14 +164,14 @@ fn filter_notes_owned_by<I: IntoIterator<Item = Note>>(

/// Executes a transaction, returning the gas spent.
fn execute(session: &mut Session, tx: Transaction) -> Result<u64> {
let receipt = session.call::<_, Result<RawResult, ContractError>>(
let receipt = session.call::<_, Result<Vec<u8>, ContractError>>(
TRANSFER_CONTRACT,
"spend_and_execute",
&tx,
tx.fee.gas_limit,
)?;

let gas_spent = receipt.points_spent;
let gas_spent = receipt.gas_spent;

session
.call::<_, ()>(
Expand Down
10 changes: 5 additions & 5 deletions contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ use phoenix_core::transaction::*;
use phoenix_core::{Crossover, Fee, Message, Note};
use poseidon_merkle::Opening as PoseidonOpening;
use rusk_abi::{
ContractError, ContractId, PaymentInfo, PublicInput, RawCall, RawResult,
STAKE_CONTRACT,
ContractError, ContractId, PaymentInfo, PublicInput, STAKE_CONTRACT,
};

/// Arity of the transfer tree.
Expand Down Expand Up @@ -292,7 +291,7 @@ impl TransferState {
pub fn spend_and_execute(
&mut self,
tx: Transaction,
) -> Result<RawResult, ContractError> {
) -> Result<Vec<u8>, ContractError> {
// 1. α ∈ R
if !self.root_exists(&tx.anchor) {
panic!("Anchor not found in the state!");
Expand Down Expand Up @@ -326,12 +325,13 @@ impl TransferState {
self.var_crossover = tx.crossover;
self.var_crossover_addr.replace(*tx.fee.stealth_address());

let mut result = Ok(RawResult::new(&[]));
let mut result = Ok(Vec::new());

if let Some((contract_id, fn_name, fn_args)) = tx.call {
result = rusk_abi::call_raw(
ContractId::from_bytes(contract_id),
&RawCall::from_parts(&fn_name, fn_args),
&fn_name,
&fn_args,
);
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/transfer/tests/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use rand::rngs::StdRng;
use rand::{CryptoRng, RngCore, SeedableRng};
use rusk_abi::dusk::{dusk, LUX};
use rusk_abi::{
ContractData, ContractError, ContractId, Error, RawResult, Session,
TRANSFER_CONTRACT, VM,
ContractData, ContractError, ContractId, Error, Session, TRANSFER_CONTRACT,
VM,
};
use transfer_circuits::{
CircuitInput, CircuitInputSignature, DeriveKey, ExecuteCircuitOneTwo,
Expand Down Expand Up @@ -211,14 +211,14 @@ fn filter_notes_owned_by<I: IntoIterator<Item = Note>>(

/// Executes a transaction, returning the gas spent.
fn execute(session: &mut Session, tx: Transaction) -> Result<u64> {
let receipt = session.call::<_, Result<RawResult, ContractError>>(
let receipt = session.call::<_, Result<Vec<u8>, ContractError>>(
TRANSFER_CONTRACT,
"spend_and_execute",
&tx,
u64::MAX,
)?;

let gas_spent = receipt.points_spent;
let gas_spent = receipt.gas_spent;

session
.call::<_, ()>(
Expand Down
2 changes: 1 addition & 1 deletion rusk-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dusk-bytes = "0.1"
bytecheck = { version = "0.6", default-features = false }
dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] }

piecrust-uplink = "0.8"
piecrust-uplink = "0.9.0-rc"
piecrust = { version = "0.14.0-rc", optional = true }

# These are patches since these crates don't seem to like semver.
Expand Down
12 changes: 6 additions & 6 deletions rusk-abi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ use rkyv::{Archive, Deserialize, Serialize};
pub(crate) enum Query {}

impl Query {
pub const HASH: &str = "hash";
pub const POSEIDON_HASH: &str = "poseidon_hash";
pub const VERIFY_PROOF: &str = "verify_proof";
pub const VERIFY_SCHNORR: &str = "verify_schnorr";
pub const VERIFY_BLS: &str = "verify_bls";
pub const HASH: &'static str = "hash";
pub const POSEIDON_HASH: &'static str = "poseidon_hash";
pub const VERIFY_PROOF: &'static str = "verify_proof";
pub const VERIFY_SCHNORR: &'static str = "verify_schnorr";
pub const VERIFY_BLS: &'static str = "verify_bls";
}

pub(crate) enum Metadata {}

impl Metadata {
pub const BLOCK_HEIGHT: &str = "block_height";
pub const BLOCK_HEIGHT: &'static str = "block_height";
}

/// Enum representing all possible payment configurations.
Expand Down
2 changes: 1 addition & 1 deletion rusk-abi/tests/contracts/host_fn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

#![no_std]
#![feature(core_intrinsics, lang_items, alloc_error_handler)]
#![feature(core_intrinsics, alloc_error_handler)]
#![deny(clippy::all)]

extern crate alloc;
Expand Down
19 changes: 9 additions & 10 deletions rusk/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ use rkyv::{Archive, Deserialize, Infallible, Serialize};
use rusk_abi::dusk::{dusk, Dusk};
use rusk_abi::{
CallReceipt, ContractError, ContractId, Error as PiecrustError, Event,
RawResult, Session, StandardBufSerializer, STAKE_CONTRACT,
TRANSFER_CONTRACT, VM,
Session, StandardBufSerializer, STAKE_CONTRACT, TRANSFER_CONTRACT, VM,
};
use rusk_profile::to_rusk_state_id_path;
use sha3::{Digest, Sha3_256};
Expand Down Expand Up @@ -134,7 +133,7 @@ impl Rusk {
let tx = unspent_tx.inner.clone();
match execute(&mut session, &tx) {
Ok(receipt) => {
let gas_spent = receipt.points_spent;
let gas_spent = receipt.gas_spent;

// If the transaction went over the block gas limit we
// re-execute all spent transactions. We don't discard the
Expand Down Expand Up @@ -169,7 +168,7 @@ impl Rusk {
block_height,
// We're currently ignoring the result of successful
// calls
err: receipt.data.err().map(|e| format!("{e:?}")),
err: receipt.data.err().map(|e| format!("{e}")),
});
}
Err(_) => {
Expand Down Expand Up @@ -631,7 +630,7 @@ fn accept(
for event in receipt.events {
update_hasher(&mut event_hasher, event);
}
let gas_spent = receipt.points_spent;
let gas_spent = receipt.gas_spent;

dusk_spent += gas_spent * tx.fee.gas_price;
block_gas_left = block_gas_left
Expand All @@ -643,7 +642,7 @@ fn accept(
gas_spent,
block_height,
// We're currently ignoring the result of successful calls
err: receipt.data.err().map(|e| format!("{e:?}")),
err: receipt.data.err().map(|e| format!("{e}")),
});
}

Expand Down Expand Up @@ -675,10 +674,10 @@ fn accept(
fn execute(
session: &mut Session,
tx: &PhoenixTransaction,
) -> Result<CallReceipt<Result<RawResult, ContractError>>, PiecrustError> {
) -> Result<CallReceipt<Result<Vec<u8>, ContractError>>, PiecrustError> {
// Spend the inputs and execute the call. If this errors the transaction is
// unspendable.
let mut receipt = session.call::<_, Result<RawResult, ContractError>>(
let mut receipt = session.call::<_, Result<Vec<u8>, ContractError>>(
TRANSFER_CONTRACT,
"spend_and_execute",
tx,
Expand All @@ -687,7 +686,7 @@ fn execute(

// Ensure all gas is consumed if there's an error in the contract call
if receipt.data.is_err() {
receipt.points_spent = receipt.points_limit;
receipt.gas_spent = receipt.gas_limit;
}

// Refund the appropriate amount to the transaction. This call is guaranteed
Expand All @@ -697,7 +696,7 @@ fn execute(
.call::<_, ()>(
TRANSFER_CONTRACT,
"refund",
&(tx.fee, receipt.points_spent),
&(tx.fee, receipt.gas_spent),
u64::MAX,
)
.expect("Refunding must succeed");
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/services/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn wallet_reward(
let tx = wallet
.execute(
&mut rng,
rusk_abi::STAKE_CONTRACT,
rusk_abi::STAKE_CONTRACT.to_bytes().into(),
String::from("reward"),
reward_calldata,
0,
Expand Down