Skip to content

Commit

Permalink
Merge pull request #3000 from autonomys/generic-x86-64-pot
Browse files Browse the repository at this point in the history
Make PoT on x86-64 not require specific CPU target for efficient proving
  • Loading branch information
nazar-pc authored Sep 3, 2024
2 parents 35e8b37 + 2f2d2fa commit 098abac
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions crates/subspace-proof-of-time/src/aes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! AES related functionality.

// TODO: Similarly optimized version for aarch64
#[cfg(all(target_arch = "x86_64", target_feature = "aes"))]
#[cfg(target_arch = "x86_64")]
mod x86_64;

#[cfg(not(feature = "std"))]
Expand All @@ -15,16 +15,14 @@ use subspace_core_primitives::{PotCheckpoints, PotKey, PotOutput, PotSeed};
/// Creates the AES based proof.
#[inline(always)]
pub(crate) fn create(seed: PotSeed, key: PotKey, checkpoint_iterations: u32) -> PotCheckpoints {
#[cfg(all(target_arch = "x86_64", target_feature = "aes"))]
{
unsafe { x86_64::create(seed.as_ref(), key.as_ref(), checkpoint_iterations) }
#[cfg(target_arch = "x86_64")]
if std::is_x86_feature_detected!("aes") {
return unsafe { x86_64::create(seed.as_ref(), key.as_ref(), checkpoint_iterations) };
}
#[cfg(not(all(target_arch = "x86_64", target_feature = "aes")))]

create_generic(seed, key, checkpoint_iterations)
}

#[cfg(any(not(all(target_arch = "x86_64", target_feature = "aes")), test))]
#[inline(always)]
fn create_generic(seed: PotSeed, key: PotKey, checkpoint_iterations: u32) -> PotCheckpoints {
let key = Array::from(*key);
let cipher = Aes128::new(&key);
Expand Down Expand Up @@ -105,7 +103,6 @@ mod tests {

// Can encrypt/decrypt.
let checkpoints = create(seed, key, checkpoint_iterations);
#[cfg(target_arch = "x86_64")]
{
let generic_checkpoints = create_generic(seed, key, checkpoint_iterations);
assert_eq!(checkpoints, generic_checkpoints);
Expand Down

0 comments on commit 098abac

Please sign in to comment.