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

Update to [email protected] #2065

Merged
merged 6 commits into from
Aug 1, 2024
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
5 changes: 0 additions & 5 deletions contracts/alice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ mod wasm {
use super::*;
use state::Alice;

use rusk_abi::ContractId;

#[no_mangle]
static SELF_ID: ContractId = ContractId::uninitialized();

static mut STATE: Alice = state::Alice;

#[no_mangle]
Expand Down
4 changes: 0 additions & 4 deletions contracts/host_fn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ use execution_core::{
BlsPublicKey, BlsScalar, BlsSignature, PublicKey, SchnorrPublicKey,
SchnorrSignature,
};
use rusk_abi::ContractId;

#[no_mangle]
static SELF_ID: ContractId = ContractId::uninitialized();

static mut STATE: HostFnTest = HostFnTest;

Expand Down
4 changes: 0 additions & 4 deletions contracts/license/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ pub const fn verifier_data_license_circuit() -> &'static [u8] {
mod wasm {
use super::*;

use rusk_abi::ContractId;
use state::LicenseContractState;

#[no_mangle]
static SELF_ID: ContractId = ContractId::uninitialized();

static mut STATE: LicenseContractState = LicenseContractState::new();

#[no_mangle]
Expand Down
12 changes: 4 additions & 8 deletions contracts/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ use state::StakeState;
/// The minimum amount of Dusk one can stake.
pub const MINIMUM_STAKE: Dusk = dusk(1_000.0);

use rusk_abi::ContractId;

#[no_mangle]
static SELF_ID: ContractId = ContractId::uninitialized();

static mut STATE: StakeState = StakeState::new();

// Transactions
Expand Down Expand Up @@ -135,8 +130,9 @@ unsafe fn set_burnt_amount(arg_len: u32) -> u32 {
/// # Panics
/// When the `caller` is not [`rusk_abi::TRANSFER_CONTRACT`].
fn assert_transfer_caller() {
if rusk_abi::caller() != rusk_abi::TRANSFER_CONTRACT {
panic!("Can only be called from the transfer contract");
const PANIC_MSG: &str = "Can only be called from the transfer contract";
if rusk_abi::caller().expect(PANIC_MSG) != rusk_abi::TRANSFER_CONTRACT {
panic!("{PANIC_MSG}");
}
}

Expand All @@ -146,7 +142,7 @@ fn assert_transfer_caller() {
/// # Panics
/// When the `caller` is not "uninitialized".
fn assert_external_caller() {
if !rusk_abi::caller().is_uninitialized() {
if rusk_abi::caller().is_some() {
panic!("Can only be called from the outside the VM");
}
}
18 changes: 10 additions & 8 deletions contracts/transfer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ mod transitory;
mod tree;
mod verifier_data;

use rusk_abi::{ContractId, STAKE_CONTRACT};
use rusk_abi::STAKE_CONTRACT;
use state::TransferState;

#[no_mangle]
static SELF_ID: ContractId = ContractId::uninitialized();

static mut STATE: TransferState = TransferState::new();

// Transactions
Expand Down Expand Up @@ -153,22 +150,27 @@ unsafe fn add_contract_balance(arg_len: u32) -> u32 {
#[no_mangle]
unsafe fn sub_contract_balance(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |(module, value)| {
if rusk_abi::caller() != STAKE_CONTRACT {
panic!("Can only be called by the stake contract!")
}
assert_stake_caller();
STATE
.sub_contract_balance(&module, value)
.expect("Cannot subtract balance")
})
}

fn assert_stake_caller() {
const PANIC_MSG: &str = "Can only be called by the stake contract";
if rusk_abi::caller().expect(PANIC_MSG) != STAKE_CONTRACT {
panic!("{PANIC_MSG}");
}
}

/// Asserts the call is made "from the outside", meaning that it's not an
/// inter-contract call.
///
/// # Panics
/// When the `caller` is not "uninitialized".
fn assert_external_caller() {
if !rusk_abi::caller().is_uninitialized() {
if rusk_abi::caller().is_some() {
panic!("Can only be called from the outside the VM");
}
}
20 changes: 11 additions & 9 deletions contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ impl TransferState {
/// We assume on trust that the value sent by the stake contract is
/// according to consensus rules.
pub fn mint(&mut self, mint: Withdraw) {
if rusk_abi::caller() != STAKE_CONTRACT {
panic!("Can only be called by the stake contract!")
const PANIC_MSG: &str = "Can only be called by the stake contract";
if rusk_abi::caller().expect(PANIC_MSG) != STAKE_CONTRACT {
panic!("{PANIC_MSG}")
}

let contract = mint.contract();
Expand All @@ -185,7 +186,9 @@ impl TransferState {
pub fn withdraw(&mut self, withdraw: Withdraw) {
let contract = ContractId::from_bytes(*withdraw.contract());

if contract != rusk_abi::caller() {
let caller = rusk_abi::caller()
.expect("A withdrawal must happen in the context of a transaction");
if contract != caller {
panic!("The \"withdraw\" function can only be called by the contract specified in the payload");
}

Expand Down Expand Up @@ -215,7 +218,9 @@ impl TransferState {
pub fn convert(&mut self, convert: Withdraw) {
// since each transaction only has, at maximum, a single contract call,
// this check impliest that this is the first contract call.
if rusk_abi::caller() != TRANSFER_CONTRACT {
let caller = rusk_abi::caller()
.expect("A conversion must happen in the context of a transaction");
if caller != TRANSFER_CONTRACT {
panic!("Only the first contract call can be a conversion");
}

Expand Down Expand Up @@ -263,11 +268,8 @@ impl TransferState {
/// This function will panic if there is no deposit on the state or the
/// caller-id doesn't match the contract-id stored for the deposit.
pub fn deposit(&mut self, value: u64) {
// check is the request comes from a contract
let caller = rusk_abi::caller();
if caller.is_uninitialized() {
panic!("Only a contract is authorized to claim a deposit.")
}
let caller = rusk_abi::caller()
.expect("A deposit must happen in the context of a transaction");

let deposit = transitory::deposit_info_mut();
match deposit {
Expand Down
4 changes: 2 additions & 2 deletions rusk-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dusk-bytes = "0.1"
bytecheck = { version = "0.6", default-features = false }
dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] }

piecrust-uplink = { version = "0.15" }
piecrust = { version = "0.22", optional = true }
piecrust-uplink = { version = "0.16" }
piecrust = { version = "0.23", optional = true }

execution-core = { version = "0.1.0", path = "../execution-core" }

Expand Down
Loading