diff --git a/src/fcmp/fcmp_rust/src/lib.rs b/src/fcmp/fcmp_rust/src/lib.rs index 78aa50eda..6e48ed5e6 100644 --- a/src/fcmp/fcmp_rust/src/lib.rs +++ b/src/fcmp/fcmp_rust/src/lib.rs @@ -176,7 +176,7 @@ pub extern "C" fn hash_trim_helios( offset: usize, children: HeliosScalarSlice, child_to_grow_back: HeliosScalar, -) -> CResult { +) -> CResult { let hash = hash_trim( helios_generators(), existing_hash, @@ -188,10 +188,7 @@ pub extern "C" fn hash_trim_helios( if let Some(hash) = hash { CResult::ok(hash) } else { - CResult::err( - HeliosPoint::identity(), - io::Error::new(io::ErrorKind::Other, "failed to trim hash"), - ) + CResult::err(()) } } @@ -223,7 +220,7 @@ pub extern "C" fn hash_trim_selene( offset: usize, children: SeleneScalarSlice, child_to_grow_back: SeleneScalar, -) -> CResult { +) -> CResult { let hash = hash_trim( selene_generators(), existing_hash, @@ -235,10 +232,7 @@ pub extern "C" fn hash_trim_selene( if let Some(hash) = hash { CResult::ok(hash) } else { - CResult::err( - SelenePoint::identity(), - io::Error::new(io::ErrorKind::Other, "failed to trim hash"), - ) + CResult::err(()) } } diff --git a/src/fcmp/tower_cycle.cpp b/src/fcmp/tower_cycle.cpp index 5679a310d..e1ce3f6f9 100644 --- a/src/fcmp/tower_cycle.cpp +++ b/src/fcmp/tower_cycle.cpp @@ -64,7 +64,7 @@ Helios::Point Helios::hash_grow( } typename Helios::Point res; - memcpy(&res, result.value, sizeof(typename Selene::Point)); + memcpy(&res, result.value, sizeof(typename Helios::Point)); free(result.value); return res; } @@ -75,15 +75,22 @@ Helios::Point Helios::hash_trim( const Helios::Chunk &children, const Helios::Scalar &child_to_grow_back) const { - fcmp_rust::CResult res = fcmp_rust::hash_trim_helios( + auto result = fcmp_rust::hash_trim_helios( existing_hash, offset, children, child_to_grow_back); - if (res.err != 0) { - throw std::runtime_error("failed to hash trim"); + + if (result.err != nullptr) + { + free(result.err); + throw std::runtime_error("failed to hash trim"); } - return res.value; + + typename Helios::Point res; + memcpy(&res, result.value, sizeof(typename Helios::Point)); + free(result.value); + return res; } //---------------------------------------------------------------------------------------------------------------------- Selene::Point Selene::hash_grow( @@ -116,15 +123,22 @@ Selene::Point Selene::hash_trim( const Selene::Chunk &children, const Selene::Scalar &child_to_grow_back) const { - fcmp_rust::CResult res = fcmp_rust::hash_trim_selene( + auto result = fcmp_rust::hash_trim_selene( existing_hash, offset, children, child_to_grow_back); - if (res.err != 0) { - throw std::runtime_error("failed to hash trim"); + + if (result.err != nullptr) + { + free(result.err); + throw std::runtime_error("failed to hash trim"); } - return res.value; + + typename Selene::Point res; + memcpy(&res, result.value, sizeof(typename Selene::Point)); + free(result.value); + return res; } //---------------------------------------------------------------------------------------------------------------------- Helios::Scalar Helios::zero_scalar() const