Skip to content
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
18 changes: 17 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@ license-file = "./LICENSE"
readme = "./README.md"
description = "Trident SVM implementation by Ackee Blockchain Security"

[features]
syscalls = ["syscall-v1", "syscall-v2"]

syscall-v1 = [
"trident-syscall-stubs-v1",
"solana_rbpf",
]
syscall-v2 = [
"trident-syscall-stubs-v2",
"solana_rbpf",
]

[dependencies]

# Solana
solana-sdk = "~2.0"
solana-program-runtime = "~2.0"
solana_rbpf = "~0.8"

# Programs
solana-system-program = "~2.0"
Expand All @@ -30,6 +41,9 @@ solana-svm = "~2.0"
solana-compute-budget = "~2.0"
solana-logger = "~2.0"


solana_rbpf = {version = "~0.8", optional = true}

# Misc
serde = { version = "1", default-features = false }
bincode = "1.3"
Expand All @@ -38,6 +52,8 @@ log = "0.4"
# Syscall stubs
[dependencies.trident-syscall-stubs-v1]
version = "0.0.1"
optional = true

[dependencies.trident-syscall-stubs-v2]
version = "0.0.1"
optional = true
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.81.0"
channel = "1.88.0"
3 changes: 1 addition & 2 deletions src/accounts_database/sysvar_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ mod tests {
let diff = (updated_clock.unix_timestamp - initial_timestamp) as u64;
assert!(
(1..=3).contains(&diff),
"Clock update difference should be ~2 seconds, got {}",
diff
"Clock update difference should be ~2 seconds, got {diff}"
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::trident_svm::TridentSVM;
use crate::trident_svm_log::{setup_cli_logging, setup_file_logging, turn_off_solana_logging};
use crate::types::trident_account::TridentAccountSharedData;
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
use crate::types::trident_entrypoint::TridentEntrypoint;
use crate::types::trident_program::TridentProgram;

Expand All @@ -10,6 +11,7 @@ pub struct TridentSVMConfig {
syscalls_v2: bool,
cli_logs: bool, // TODO, add better debbug levels
debug_file_logs: bool,
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
program_entrypoints: Vec<TridentEntrypoint>,
program_binaries: Vec<TridentProgram>,
permanent_accounts: Vec<TridentAccountSharedData>,
Expand Down Expand Up @@ -37,6 +39,7 @@ impl TridentSVMBuilder {
self
}

#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
pub fn with_program_entries(&mut self, entries: Vec<TridentEntrypoint>) -> &Self {
self.config.program_entrypoints = entries;
self
Expand Down Expand Up @@ -65,9 +68,11 @@ impl TridentSVMBuilder {
pub fn build(&self) -> TridentSVM {
let mut svm = TridentSVM::default();

#[cfg(feature = "syscall-v1")]
if self.config.syscalls_v1 {
svm.initialize_syscalls_v1();
}
#[cfg(feature = "syscall-v2")]
if self.config.syscalls_v2 {
svm.initialize_syscalls_v2();
}
Expand All @@ -80,6 +85,7 @@ impl TridentSVMBuilder {
turn_off_solana_logging();
}

#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
for entry in &self.config.program_entrypoints {
svm.deploy_entrypoint_program(entry);
}
Expand Down
11 changes: 6 additions & 5 deletions src/builtin_function.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#![allow(clippy::not_unsafe_ptr_arg_deref)]

use std::collections::HashMap;

use solana_sdk::transaction_context::IndexOfAccount;

use solana_bpf_loader_program::serialization::serialize_parameters;

use solana_program_runtime::invoke_context::InvokeContext;
use solana_sdk::transaction_context::IndexOfAccount;
use std::collections::HashMap;

use solana_rbpf::aligned_memory::AlignedMemory;
use solana_rbpf::ebpf::HOST_ALIGN;

#[cfg(feature = "syscall-v1")]
use trident_syscall_stubs_v1::set_invoke_context as set_invoke_context_v1;
#[cfg(feature = "syscall-v2")]
use trident_syscall_stubs_v2::set_invoke_context as set_invoke_context_v2;

#[macro_export]
Expand Down Expand Up @@ -166,7 +165,9 @@ pub fn pre_invocation(
),
Box<dyn std::error::Error>,
> {
#[cfg(feature = "syscall-v1")]
set_invoke_context_v1(invoke_context);
#[cfg(feature = "syscall-v2")]
set_invoke_context_v2(invoke_context);

let transaction_context = &invoke_context.transaction_context;
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ mod trident_fork_graphs;
pub mod trident_svm_log;
mod utils;

#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
pub mod builtin_function;
pub mod trident_svm;
pub mod types;

pub mod processor {
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
pub use crate::builtin_function::post_invocation;
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
pub use crate::builtin_function::pre_invocation;

pub use solana_program_runtime;
pub use solana_program_runtime::stable_log;
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
pub use solana_rbpf;
pub use solana_sdk::account_info;
pub use solana_sdk::entrypoint::deserialize;
Expand Down
10 changes: 6 additions & 4 deletions src/methods/trident_svm_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use solana_sdk::account::WritableAccount;
use solana_sdk::bpf_loader_upgradeable;
use solana_sdk::bpf_loader_upgradeable::UpgradeableLoaderState;

use solana_sdk::native_loader;
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
use {
crate::types::trident_entrypoint::TridentEntrypoint,
solana_program_runtime::loaded_programs::ProgramCacheEntry, solana_sdk::native_loader,
};

use solana_sdk::rent::Rent;

use solana_program_runtime::loaded_programs::ProgramCacheEntry;

use crate::trident_svm::TridentSVM;
use crate::types::trident_entrypoint::TridentEntrypoint;
use crate::types::trident_program::TridentProgram;

impl TridentSVM {
Expand Down Expand Up @@ -67,6 +68,7 @@ impl TridentSVM {
.set_program(&program_data_account, &account_data);
}

#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
pub fn deploy_entrypoint_program(&mut self, program: &TridentEntrypoint) {
let entry = match program.entry {
Some(entry) => entry,
Expand Down
7 changes: 3 additions & 4 deletions src/methods/trident_svm_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ impl TridentSVM {
details,
..
} => match &details.status {
Ok(()) => match &result.loaded_transactions[0] {
Ok(loaded_transaction) => {
Ok(()) => {
if let Ok(loaded_transaction) = &result.loaded_transactions[0] {
self.settle_accounts(&loaded_transaction.accounts);
}
Err(_) => {}
},
}
Err(_transaction_error) => {
// in case of transaction error, we don't need to do anything
}
Expand Down
5 changes: 5 additions & 0 deletions src/trident_svm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ use solana_sdk::feature_set::FeatureSet;

use solana_svm::transaction_processing_callback::TransactionProcessingCallback;
use solana_svm::transaction_processor::TransactionBatchProcessor;

#[cfg(feature = "syscall-v1")]
use trident_syscall_stubs_v1::set_stubs_v1;
#[cfg(feature = "syscall-v2")]
use trident_syscall_stubs_v2::set_stubs_v2;

use crate::accounts_database::accounts_db::AccountsDB;
Expand All @@ -52,10 +55,12 @@ pub struct TridentSVM {
}

impl TridentSVM {
#[cfg(feature = "syscall-v1")]
pub(crate) fn initialize_syscalls_v1(&mut self) {
set_stubs_v1();
}

#[cfg(feature = "syscall-v2")]
pub(crate) fn initialize_syscalls_v2(&mut self) {
set_stubs_v2();
}
Expand Down
1 change: 1 addition & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod trident_account;
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
pub mod trident_entrypoint;
pub mod trident_program;
Loading