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
1,435 changes: 727 additions & 708 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ unexpected_cfgs = { level = "warn", check-cfg = [
[workspace.dependencies]
curve25519-dalek = "4.1.3"
ed25519-dalek = "2.1.1"
mollusk-svm = "0.13.1"
mollusk-svm = "0.17.1"
pinocchio = "0.11.2"
serde = { version = "1.0.228", default-features = false }
serde_derive = "1.0.228"
solana-account = "3.4.0"
solana-account = "5.0.0"
solana-curve25519 = "4.0.1"
solana-define-syscall = "5.2.0"
solana-ed25519-verify = { path = "ed25519-verify", version = "0.1.0", default-features = false }
solana-instruction = "3.3.0"
solana-program-error = "3.0.1"
solana-program-runtime = { version = "4.0.0", features = ["agave-unstable-api"] }
solana-address = "2.7.0"
solana-sha512-hasher = { version = "1.0.1", features = ["sha2"] }
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RUST_TOOLCHAIN_NIGHTLY = nightly-2026-01-22
RUST_TOOLCHAIN_NIGHTLY = nightly-2026-07-16
SOLANA_CLI_VERSION = v4.1.2
SBF_ARCH = v3

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ succeeded.
| `sol_curve_validate_point` | Selected malformed-input checks |
| `sol_curve_multiscalar_mul` | Fixed two-term wrapper for individual verification |

The benchmark's published Mollusk/Agave runtime does not register `sol_sha512`,
so the tests install a metered shim using `solana-sha512-hasher`. Deployment
requires a VM that enables the SHA-512 syscall.
Deployment requires a VM that enables the SHA-512 syscall (SIMD-0512). Mollusk
enables it by default, so the tests use the runtime's own `sol_sha512`.

## Instruction format

Expand Down
7 changes: 6 additions & 1 deletion ed25519-verify/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ mod tests {
// than the shift loop in `to_le_limbs`, so the two directions are not
// the same code checked against itself.
let mut bytes = [0u8; 32];
for (chunk, limb) in bytes.chunks_exact_mut(8).zip(BASEPOINT_ORDER_LIMBS) {
for (chunk, limb) in bytes
.as_chunks_mut::<8>()
.0
.iter_mut()
.zip(BASEPOINT_ORDER_LIMBS)
{
chunk.copy_from_slice(&limb.to_le_bytes());
}

Expand Down
8 changes: 5 additions & 3 deletions ed25519-verify/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ pub(crate) fn reduce_wide_into(wide: &[u8; 64], reduced: &mut [u8; 32]) {
fn add_order_and_store(r0: u64, r1: u64, r2: u64, r3: u64, reduced: &mut [u8; 32]) {
let mut carry = 0u64;
for ((chunk, limb), order) in reduced
.chunks_exact_mut(8)
.as_chunks_mut::<8>()
.0
.iter_mut()
.zip([r0, r1, r2, r3])
.zip(BASEPOINT_ORDER_LIMBS)
{
Expand All @@ -145,7 +147,7 @@ pub(crate) fn reduce_wide_into(wide: &[u8; 64], reduced: &mut [u8; 32]) {
return;
}

for (chunk, limb) in reduced.chunks_exact_mut(8).zip(remainder) {
for (chunk, limb) in reduced.as_chunks_mut::<8>().0.iter_mut().zip(remainder) {
chunk.copy_from_slice(&limb.to_le_bytes());
}
}
Expand Down Expand Up @@ -309,7 +311,7 @@ mod tests {
let mut state = 0x9e37_79b9_7f4a_7c15u64;
for _ in 0..4096 {
let mut wide = [0u8; 64];
for chunk in wide.chunks_exact_mut(8) {
for chunk in wide.as_chunks_mut::<8>().0 {
state ^= state << 13;
state ^= state >> 7;
state ^= state << 17;
Expand Down
2 changes: 0 additions & 2 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ solana-ed25519-verify = { workspace = true, default-features = false, features =
"instruction",
] }
solana-instruction = { workspace = true }
solana-program-runtime = { workspace = true }
solana-sha512-hasher = { workspace = true }

[lints]
workspace = true
103 changes: 1 addition & 102 deletions program/tests/mollusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ use {
verify,
},
solana_instruction::{AccountMeta, Instruction},
solana_program_runtime::{
invoke_context::InvokeContext,
solana_sbpf::{
declare_builtin_function,
error::ProgramResult as SbpfProgramResult,
memory_region::{AccessType, MemoryMapping},
},
},
std::{env, error::Error, io, mem::size_of, path::PathBuf, slice},
std::{env, path::PathBuf},
};

const PROGRAM_SO_STEM: &str = "solana_ed25519_program";
Expand All @@ -34,94 +26,6 @@ const SMALL_ORDER_PUBLIC_KEY_COMPRESSED: [u8; PUBKEY_SERIALIZED_SIZE] = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
];

#[repr(C)]
#[derive(Clone, Copy)]
struct VmSlice {
ptr: u64,
len: u64,
}

declare_builtin_function!(
/// Local SHA-512 syscall shim for runtimes that have not published `sol_sha512` yet.
///
/// Remove this shim and the manual registration below once `sol_sha512` is
/// live on mainnet and available in the local Agave/Mollusk runtime.
SyscallSha512,
fn rust(
invoke_context: &mut InvokeContext,
vals_addr: u64,
vals_len: u64,
result_addr: u64,
_arg4: u64,
_arg5: u64,
memory_mapping: &mut MemoryMapping,
) -> Result<u64, Box<dyn Error>> {
let compute_cost = *invoke_context.get_execution_cost();
invoke_context.consume_checked(compute_cost.sha256_base_cost)?;

let vals =
translate_slice::<VmSlice>(memory_mapping, vals_addr, vals_len, AccessType::Load)?
.to_vec();
let mut hasher = solana_sha512_hasher::Hasher::default();
for val in &vals {
let bytes = translate_slice::<u8>(memory_mapping, val.ptr, val.len, AccessType::Load)?;
let byte_cost = compute_cost
.sha256_byte_cost
.saturating_mul(val.len / 2);
invoke_context.consume_checked(compute_cost.mem_op_base_cost.max(byte_cost))?;
hasher.hash(bytes);
}

let output = translate_slice_mut::<u8>(memory_mapping, result_addr, 64)?;
output.copy_from_slice(hasher.result().as_ref());
Ok(0)
}
);

fn translate_slice<T>(
memory_mapping: &mut MemoryMapping,
vm_addr: u64,
len: u64,
access_type: AccessType,
) -> Result<&[T], Box<dyn Error>> {
let byte_len = mapped_byte_len::<T>(len)?;
let host_addr = map(memory_mapping, access_type, vm_addr, byte_len)?;
let len = usize::try_from(len).map_err(|_| length_error())?;
Ok(unsafe { slice::from_raw_parts(host_addr as *const T, len) })
}

fn translate_slice_mut<T>(
memory_mapping: &mut MemoryMapping,
vm_addr: u64,
len: u64,
) -> Result<&mut [T], Box<dyn Error>> {
let byte_len = mapped_byte_len::<T>(len)?;
let host_addr = map(memory_mapping, AccessType::Store, vm_addr, byte_len)?;
let len = usize::try_from(len).map_err(|_| length_error())?;
Ok(unsafe { slice::from_raw_parts_mut(host_addr as *mut T, len) })
}

fn mapped_byte_len<T>(len: u64) -> Result<u64, Box<dyn Error>> {
len.checked_mul(size_of::<T>() as u64)
.ok_or_else(|| length_error().into())
}

fn map(
memory_mapping: &mut MemoryMapping,
access_type: AccessType,
vm_addr: u64,
len: u64,
) -> Result<u64, Box<dyn Error>> {
match memory_mapping.map_with_access_violation_handler(access_type, vm_addr, len) {
SbpfProgramResult::Ok(host_addr) => Ok(host_addr),
SbpfProgramResult::Err(err) => Err(err.into()),
}
}

fn length_error() -> io::Error {
io::Error::new(io::ErrorKind::InvalidInput, "invalid VM slice length")
}

fn sbf_program_path() -> Option<String> {
if let Some(out_dir) = env::var_os("SBF_OUT_DIR") {
let path = PathBuf::from(out_dir).join(PROGRAM_SO_STEM);
Expand All @@ -142,11 +46,6 @@ fn make_mollusk() -> Option<(Mollusk, Address)> {
let program_path = sbf_program_path()?;
let program_id = Address::new_unique();
let mut mollusk = Mollusk::default();
mollusk
.program_cache
.program_runtime_environment
.register_function("sol_sha512", SyscallSha512::vm)
.expect("register sol_sha512 test syscall");
mollusk.add_program(&program_id, &program_path);
Some((mollusk, program_id))
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.93.1"
channel = "1.98.1"

Loading