Skip to content
Open
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,593 changes: 916 additions & 677 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ audit-rs:
$(CARGO) audit \
--ignore RUSTSEC-2025-0055 \
--ignore RUSTSEC-2026-0194 \
--ignore RUSTSEC-2026-0195
--ignore RUSTSEC-2026-0195 \
--ignore RUSTSEC-2026-0258 \
--ignore RUSTSEC-2026-0233 \
--ignore RUSTSEC-2026-0235 \
--ignore RUSTSEC-2026-0220 \
--ignore RUSTSEC-2026-0186 \
--ignore RUSTSEC-2026-0234

.PHONY: audit
audit: audit-rs
Expand Down
16 changes: 8 additions & 8 deletions binary_port/src/error_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ pub enum ErrorCode {
/// The transaction sent to the network had an insufficient transfer amount
#[error("the transaction sent to the network had an insufficient transfer amount")]
InvalidTransactionInsufficientTransferAmount = 47,
/// The transaction sent to the network had a custom entry point when it should have a non
/// custom entry point.
/// The transaction sent to the network had a custom entry point when it should have a
/// non-custom entry point.
#[error("the native transaction sent to the network should not have a custom entry point")]
InvalidTransactionEntryPointCannotBeCustom = 48,
/// The transaction sent to the network had a standard entry point when it must be custom.
Expand Down Expand Up @@ -298,7 +298,7 @@ pub enum ErrorCode {
#[error("not enough bytes to read version of the binary request header")]
TooLittleBytesForRequestHeaderVersion = 92,
/// Malformed command header version
#[error("malformed commnd header version")]
#[error("malformed command header version")]
MalformedCommandHeaderVersion = 93,
/// Malformed header
#[error("malformed command header")]
Expand Down Expand Up @@ -327,9 +327,9 @@ pub enum ErrorCode {
/// Missing seed field in transaction
#[error("Missing seed field in transaction")]
InvalidTransactionMissingSeed = 102,
/// Pricing mode not supported
#[error("Pricing mode not supported")]
PricingModeNotSupported = 103,
/// Pricing mode error
#[error("Pricing mode error")]
PricingModeError = 103,
/// Gas limit not supported
#[error("Gas limit not supported")]
InvalidDeployGasLimitNotSupported = 104,
Expand Down Expand Up @@ -465,7 +465,7 @@ impl From<InvalidDeploy> for ErrorCode {
ErrorCode::InvalidDeployExceededWasmLaneGasLimit
}
InvalidDeploy::InvalidPaymentAmount => ErrorCode::InvalidDeployInvalidPaymentAmount,
InvalidDeploy::PricingModeNotSupported => ErrorCode::PricingModeNotSupported,
InvalidDeploy::PricingModeNotSupported => ErrorCode::PricingModeError,
_ => ErrorCode::InvalidDeployUnspecified,
}
}
Expand Down Expand Up @@ -527,6 +527,7 @@ impl From<InvalidTransactionV1> for ErrorCode {
InvalidTransactionV1::InvalidPricingMode { .. } => {
ErrorCode::InvalidTransactionPricingMode
}
InvalidTransactionV1::PricingModeError { .. } => ErrorCode::PricingModeError,
InvalidTransactionV1::EntryPointCannotBeCall => {
ErrorCode::InvalidTransactionEntryPointCannotBeCall
}
Expand Down Expand Up @@ -557,7 +558,6 @@ impl From<InvalidTransactionV1> for ErrorCode {
ErrorCode::InvalidTransactionExpectedBytesArguments
}
InvalidTransactionV1::MissingSeed => ErrorCode::InvalidTransactionMissingSeed,
InvalidTransactionV1::PricingModeNotSupported => ErrorCode::PricingModeNotSupported,
InvalidTransactionV1::InsufficientBurnAmount { .. } => {
ErrorCode::InvalidTransactionInsufficientBurnAmount
}
Expand Down
141 changes: 72 additions & 69 deletions execution_engine/src/engine_state/wasm_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ use crate::engine_state::Error as EngineError;
const DEFAULT_ENTRY_POINT: &str = "call";

/// Structure that needs to be filled with data so the engine can assemble wasm for deploy.
pub struct SessionDataDeploy<'a> {
deploy_hash: &'a DeployHash,
session: &'a ExecutableDeployItem,
initiator_addr: &'a InitiatorAddr,
#[derive(Clone, Debug)]
pub struct SessionDataDeploy {
deploy_hash: DeployHash,
session: ExecutableDeployItem,
initiator_addr: InitiatorAddr,
signers: BTreeSet<AccountHash>,
is_standard_payment: bool,
}

impl<'a> SessionDataDeploy<'a> {
impl SessionDataDeploy {
/// Constructor
pub fn new(
deploy_hash: &'a DeployHash,
session: &'a ExecutableDeployItem,
initiator_addr: &'a InitiatorAddr,
deploy_hash: DeployHash,
session: ExecutableDeployItem,
initiator_addr: InitiatorAddr,
signers: BTreeSet<AccountHash>,
is_standard_payment: bool,
) -> Self {
Expand All @@ -46,18 +47,18 @@ impl<'a> SessionDataDeploy<'a> {
}

/// Deploy hash of the deploy
pub fn deploy_hash(&self) -> &DeployHash {
pub fn deploy_hash(&self) -> DeployHash {
self.deploy_hash
}

/// executable item of the deploy
pub fn session(&self) -> &ExecutableDeployItem {
self.session
pub fn session(&self) -> ExecutableDeployItem {
self.session.clone()
}

/// initiator address of the deploy
pub fn initiator_addr(&self) -> &InitiatorAddr {
self.initiator_addr
pub fn initiator_addr(&self) -> InitiatorAddr {
self.initiator_addr.clone()
}

/// signers of the deploy
Expand All @@ -67,29 +68,30 @@ impl<'a> SessionDataDeploy<'a> {
}

/// Structure that needs to be filled with data so the engine can assemble wasm for v1.
pub struct SessionDataV1<'a> {
args: &'a RuntimeArgs,
target: &'a TransactionTarget,
entry_point: &'a TransactionEntryPoint,
#[derive(Clone, Debug)]
pub struct SessionDataV1 {
args: RuntimeArgs,
target: TransactionTarget,
entry_point: TransactionEntryPoint,
is_install_upgrade: bool,
hash: &'a TransactionV1Hash,
pricing_mode: &'a PricingMode,
initiator_addr: &'a InitiatorAddr,
hash: TransactionV1Hash,
pricing_mode: PricingMode,
initiator_addr: InitiatorAddr,
signers: BTreeSet<AccountHash>,
is_standard_payment: bool,
}

impl<'a> SessionDataV1<'a> {
impl SessionDataV1 {
#[allow(clippy::too_many_arguments)]
/// Constructor
pub fn new(
args: &'a RuntimeArgs,
target: &'a TransactionTarget,
entry_point: &'a TransactionEntryPoint,
args: RuntimeArgs,
target: TransactionTarget,
entry_point: TransactionEntryPoint,
is_install_upgrade: bool,
hash: &'a TransactionV1Hash,
pricing_mode: &'a PricingMode,
initiator_addr: &'a InitiatorAddr,
hash: TransactionV1Hash,
pricing_mode: PricingMode,
initiator_addr: InitiatorAddr,
signers: BTreeSet<AccountHash>,
is_standard_payment: bool,
) -> Self {
Expand All @@ -107,18 +109,18 @@ impl<'a> SessionDataV1<'a> {
}

/// Runtime args passed with the transaction.
pub fn args(&self) -> &RuntimeArgs {
self.args
pub fn args(&self) -> RuntimeArgs {
self.args.clone()
}

/// Target of the transaction.
pub fn target(&self) -> &TransactionTarget {
self.target
pub fn target(&self) -> TransactionTarget {
self.target.clone()
}

/// Entry point of the transaction
pub fn entry_point(&self) -> &TransactionEntryPoint {
self.entry_point
pub fn entry_point(&self) -> TransactionEntryPoint {
self.entry_point.clone()
}

/// Should session be allowed to perform install/upgrade operations
Expand All @@ -127,13 +129,13 @@ impl<'a> SessionDataV1<'a> {
}

/// Hash of the transaction
pub fn hash(&self) -> &TransactionV1Hash {
pub fn hash(&self) -> TransactionV1Hash {
self.hash
}

/// initiator address of the transaction
pub fn initiator_addr(&self) -> &InitiatorAddr {
self.initiator_addr
pub fn initiator_addr(&self) -> InitiatorAddr {
self.initiator_addr.clone()
}

/// signers of the transaction
Expand All @@ -142,38 +144,39 @@ impl<'a> SessionDataV1<'a> {
}

/// Pricing mode of the transaction
pub fn pricing_mode(&self) -> &PricingMode {
self.pricing_mode
pub fn pricing_mode(&self) -> PricingMode {
self.pricing_mode.clone()
}
}

/// Wrapper enum abstracting data for assmbling WasmV1Requests
pub enum SessionInputData<'a> {
#[derive(Clone, Debug)]
pub enum SessionInputData {
/// Variant for sessions created from deploy transactions
DeploySessionData {
/// Deploy session data
data: SessionDataDeploy<'a>,
data: SessionDataDeploy,
},
/// Variant for sessions created from v1 transactions
SessionDataV1 {
/// v1 session data
data: SessionDataV1<'a>,
data: SessionDataV1,
},
}

impl SessionInputData<'_> {
impl SessionInputData {
/// Transaction hash for the session
pub fn transaction_hash(&self) -> TransactionHash {
match self {
SessionInputData::DeploySessionData { data } => {
TransactionHash::Deploy(*data.deploy_hash())
TransactionHash::Deploy(data.deploy_hash())
}
SessionInputData::SessionDataV1 { data } => TransactionHash::V1(*data.hash()),
SessionInputData::SessionDataV1 { data } => TransactionHash::V1(data.hash()),
}
}

/// Initiator address for the session
pub fn initiator_addr(&self) -> &InitiatorAddr {
pub fn initiator_addr(&self) -> InitiatorAddr {
match self {
SessionInputData::DeploySessionData { data } => data.initiator_addr(),
SessionInputData::SessionDataV1 { data } => data.initiator_addr(),
Expand Down Expand Up @@ -617,7 +620,7 @@ impl WasmV1Result {
pub fn from_transfer_result(transfer_result: TransferResult, consumed: Gas) -> Option<Self> {
// NOTE: for native / wasmless operations limit and consumed are always equal, and
// we can get away with simplifying to one or the other here.
// this is NOT true of wasm based operations however.
// this is NOT true of wasm based operations, however.
match transfer_result {
TransferResult::RootNotFound => None,
TransferResult::Success {
Expand Down Expand Up @@ -701,7 +704,7 @@ impl Executable for SessionInfo {
}
}

impl TryFrom<&SessionInputData<'_>> for PaymentInfo {
impl TryFrom<&SessionInputData> for PaymentInfo {
type Error = InvalidRequest;

fn try_from(input_data: &SessionInputData) -> Result<Self, Self::Error> {
Expand All @@ -712,7 +715,7 @@ impl TryFrom<&SessionInputData<'_>> for PaymentInfo {
}
}

impl TryFrom<&SessionInputData<'_>> for SessionInfo {
impl TryFrom<&SessionInputData> for SessionInfo {
type Error = InvalidRequest;

fn try_from(input_data: &SessionInputData) -> Result<Self, Self::Error> {
Expand All @@ -723,13 +726,12 @@ impl TryFrom<&SessionInputData<'_>> for SessionInfo {
}
}

impl TryFrom<&SessionDataDeploy<'_>> for SessionInfo {
impl TryFrom<&SessionDataDeploy> for SessionInfo {
type Error = InvalidRequest;

fn try_from(deploy_data: &SessionDataDeploy) -> Result<Self, Self::Error> {
let transaction_hash = TransactionHash::Deploy(*deploy_data.deploy_hash());
let session_item = deploy_data.session();
build_session_info_for_executable_item(session_item, transaction_hash)
let transaction_hash = TransactionHash::Deploy(deploy_data.deploy_hash());
build_session_info_for_executable_item(&deploy_data.session(), transaction_hash)
}
}

Expand Down Expand Up @@ -811,11 +813,11 @@ fn build_session_info_for_executable_item(
}))
}

impl TryFrom<&SessionDataV1<'_>> for SessionInfo {
impl TryFrom<&SessionDataV1> for SessionInfo {
type Error = InvalidRequest;

fn try_from(v1_txn: &SessionDataV1) -> Result<Self, Self::Error> {
let transaction_hash = TransactionHash::V1(*v1_txn.hash());
let transaction_hash = TransactionHash::V1(v1_txn.hash());
let args = v1_txn.args().clone();
let session = match v1_txn.target() {
TransactionTarget::Native => {
Expand All @@ -839,7 +841,7 @@ impl TryFrom<&SessionDataV1<'_>> for SessionInfo {
}
}
TransactionTarget::Session { module_bytes, .. } => {
if *v1_txn.entry_point() != TransactionEntryPoint::Call {
if v1_txn.entry_point() != TransactionEntryPoint::Call {
return Err(InvalidRequest::InvalidEntryPoint(
transaction_hash,
v1_txn.entry_point().to_string(),
Expand Down Expand Up @@ -886,13 +888,12 @@ impl Executable for PaymentInfo {
}
}

impl TryFrom<&SessionDataDeploy<'_>> for PaymentInfo {
impl TryFrom<&SessionDataDeploy> for PaymentInfo {
type Error = InvalidRequest;

fn try_from(deploy_data: &SessionDataDeploy) -> Result<Self, Self::Error> {
let payment_item = deploy_data.session();
let transaction_hash = TransactionHash::Deploy(*deploy_data.deploy_hash());
build_payment_info_for_executable_item(payment_item, transaction_hash)
let transaction_hash = TransactionHash::Deploy(deploy_data.deploy_hash());
build_payment_info_for_executable_item(&deploy_data.session(), transaction_hash)
}
}

Expand Down Expand Up @@ -969,33 +970,35 @@ fn build_payment_info_for_executable_item(
}
}

impl TryFrom<&SessionDataV1<'_>> for PaymentInfo {
impl TryFrom<&SessionDataV1> for PaymentInfo {
type Error = InvalidRequest;

fn try_from(v1_txn: &SessionDataV1) -> Result<Self, Self::Error> {
let transaction_hash = TransactionHash::V1(*v1_txn.hash());
match v1_txn.pricing_mode() {
mode @ PricingMode::PaymentLimited {
let transaction_hash = TransactionHash::V1(v1_txn.hash());

let pricing_mode = v1_txn.pricing_mode();
match pricing_mode {
PricingMode::PaymentLimited {
standard_payment, ..
} => {
if *standard_payment {
if standard_payment {
return Err(InvalidRequest::UnsupportedMode(
transaction_hash,
mode.to_string(),
pricing_mode.to_string(),
));
}
}
mode @ PricingMode::Fixed { .. } | mode @ PricingMode::Prepaid { .. } => {
PricingMode::Fixed { .. } | PricingMode::Prepaid { .. } => {
return Err(InvalidRequest::UnsupportedMode(
transaction_hash,
mode.to_string(),
pricing_mode.to_string(),
));
}
};
}

let payment = match v1_txn.target() {
TransactionTarget::Session { module_bytes, .. } => {
if *v1_txn.entry_point() != TransactionEntryPoint::Call {
if v1_txn.entry_point() != TransactionEntryPoint::Call {
return Err(InvalidRequest::InvalidEntryPoint(
transaction_hash,
v1_txn.entry_point().to_string(),
Expand Down
Loading