From 2174241d51bbccfa30bb65c8f52f8343ccb4b83b Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Mon, 24 Aug 2026 22:41:03 -0400 Subject: [PATCH] feat: Remove float_root --- crates/xrpl-host-functions/src/lib.rs | 5 --- .../tests/generated_abi.rs | 10 ------ crates/xrpl-wasm-vm-ffi/src/lib.rs | 8 ----- crates/xrpl-wasm-vm/src/abi.rs | 3 -- crates/xrpl-wasm-vm/src/register.rs | 20 ------------ crates/xrpl-wasm-vm/tests/budgets.rs | 5 --- crates/xrpl-wasm-vm/tests/host_calls.rs | 17 ---------- crates/xrpl-wasm-vm/tests/preflight.rs | 1 - crates/xrpl-wasm-vm/tests/support/mod.rs | 14 ++------ include/xrpl/tx/wasm/HostContext.h | 7 ---- include/xrpl/tx/wasm/HostFunc.h | 9 ------ include/xrpl/tx/wasm/HostFuncImpl.h | 3 -- src/libxrpl/tx/wasm/HostContext.cpp | 13 -------- src/libxrpl/tx/wasm/HostFuncImplFloat.cpp | 32 ------------------- 14 files changed, 2 insertions(+), 145 deletions(-) diff --git a/crates/xrpl-host-functions/src/lib.rs b/crates/xrpl-host-functions/src/lib.rs index 9cb5a1d8b0..74d6e38abf 100644 --- a/crates/xrpl-host-functions/src/lib.rs +++ b/crates/xrpl-host-functions/src/lib.rs @@ -496,11 +496,6 @@ host_functions! { #[wasm_name = "float_div"] fn float_divide(&self, x: &[u8], y: &[u8], mode: i32, out: &mut [u8]) -> HostResult; - /// The `n`-th root of the float `x` under rounding `mode`. - #[gas = 5500] - #[wasm_name = "float_root"] - fn float_root(&self, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> HostResult; - /// The float `x` raised to the power `n` under rounding `mode`. #[gas = 5500] #[wasm_name = "float_pow"] diff --git a/crates/xrpl-host-functions/tests/generated_abi.rs b/crates/xrpl-host-functions/tests/generated_abi.rs index f2358195cb..b4ea770bb3 100644 --- a/crates/xrpl-host-functions/tests/generated_abi.rs +++ b/crates/xrpl-host-functions/tests/generated_abi.rs @@ -560,14 +560,6 @@ impl HostFunctions for FakeHost { put(out, &[x[0]]) } - /// A one-float-and-integer operator; `InvalidParams` on an empty operand. - fn float_root(&self, x: &[u8], _n: i32, _mode: i32, out: &mut [u8]) -> HostResult { - if x.is_empty() { - return Err(HostError::InvalidParams); - } - put(out, &[x[0]]) - } - /// The same shape, for exponentiation. fn float_power(&self, x: &[u8], _n: i32, _mode: i32, out: &mut [u8]) -> HostResult { if x.is_empty() { @@ -824,7 +816,6 @@ fn the_trait_is_implementable() { assert_eq!(host.float_subtract(&[3; 8], &[4; 8], 0, &mut out), Ok(1)); assert_eq!(host.float_multiply(&[3; 8], &[4; 8], 0, &mut out), Ok(1)); assert_eq!(host.float_divide(&[3; 8], &[4; 8], 0, &mut out), Ok(1)); - assert_eq!(host.float_root(&[3; 8], 2, 0, &mut out), Ok(1)); assert_eq!(host.float_power(&[3; 8], 2, 0, &mut out), Ok(1)); assert_eq!(*host.traced.borrow(), ["hello/AsHex/2"]); @@ -951,7 +942,6 @@ fn the_spec_table_matches_the_declarations() { ("float_sub", 160), ("float_mult", 300), ("float_div", 300), - ("float_root", 5500), ("float_pow", 5500), ] ); diff --git a/crates/xrpl-wasm-vm-ffi/src/lib.rs b/crates/xrpl-wasm-vm-ffi/src/lib.rs index 0b2b965472..f0bfa8e833 100644 --- a/crates/xrpl-wasm-vm-ffi/src/lib.rs +++ b/crates/xrpl-wasm-vm-ffi/src/lib.rs @@ -514,10 +514,6 @@ mod ffi { #[cxx_name = "floatDivide"] fn float_divide(self: &HostContext, x: &[u8], y: &[u8], mode: i32, out: &mut [u8]) -> i32; - #[namespace = "xrpl"] - #[cxx_name = "floatRoot"] - fn float_root(self: &HostContext, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> i32; - #[namespace = "xrpl"] #[cxx_name = "floatPower"] fn float_power(self: &HostContext, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> i32; @@ -880,10 +876,6 @@ impl HostFunctions for CxxHost<'_> { bytes_written(self.ctx.float_divide(x, y, mode, out)) } - fn float_root(&self, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> HostResult { - bytes_written(self.ctx.float_root(x, n, mode, out)) - } - fn float_power(&self, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> HostResult { bytes_written(self.ctx.float_power(x, n, mode, out)) } diff --git a/crates/xrpl-wasm-vm/src/abi.rs b/crates/xrpl-wasm-vm/src/abi.rs index da7108d2c4..1ce2f978fb 100644 --- a/crates/xrpl-wasm-vm/src/abi.rs +++ b/crates/xrpl-wasm-vm/src/abi.rs @@ -657,9 +657,6 @@ mod tests { ) -> HostResult { unreachable!("no unit test in this module calls the host") } - fn float_root(&self, _x: &[u8], _n: i32, _mode: i32, _out: &mut [u8]) -> HostResult { - unreachable!("no unit test in this module calls the host") - } fn float_power( &self, _x: &[u8], diff --git a/crates/xrpl-wasm-vm/src/register.rs b/crates/xrpl-wasm-vm/src/register.rs index 7a31a34b9c..e69981055f 100644 --- a/crates/xrpl-wasm-vm/src/register.rs +++ b/crates/xrpl-wasm-vm/src/register.rs @@ -1169,26 +1169,6 @@ pub(crate) fn register_host_functions( }) }, ), - HostFunctionSpec::FloatRoot => linker.func_wrap( - HOST_MODULE, - op.wasm_name(), - |mut caller: Caller<'_, VmState<'_>>, - in_ptr: i32, - in_len: i32, - n: i32, - out_ptr: i32, - out_len: i32, - mode: i32| - -> Result { - charged(&mut caller, HostFunctionSpec::FloatRoot, |c| { - let out = Region::new(out_ptr, out_len); - let x = Region::new(in_ptr, in_len); - write_buffered(c, out, |host, data, buf| { - host.float_root(x.read(data)?, n, mode, buf) - }) - }) - }, - ), HostFunctionSpec::FloatPower => linker.func_wrap( HOST_MODULE, op.wasm_name(), diff --git a/crates/xrpl-wasm-vm/tests/budgets.rs b/crates/xrpl-wasm-vm/tests/budgets.rs index 2e9e1f86c6..ffc4947004 100644 --- a/crates/xrpl-wasm-vm/tests/budgets.rs +++ b/crates/xrpl-wasm-vm/tests/budgets.rs @@ -382,11 +382,6 @@ fn call_for(op: HostFunctionSpec) -> Call { "(call $float_div (i32.const 0) (i32.const 8) (i32.const 8) (i32.const 8) (i32.const 16) (i32.const 8) (i32.const 0))", 7, ), - HostFunctionSpec::FloatRoot => ( - import::FLOAT_ROOT, - "(call $float_root (i32.const 0) (i32.const 8) (i32.const 2) (i32.const 8) (i32.const 8) (i32.const 0))", - 6, - ), HostFunctionSpec::FloatPower => ( import::FLOAT_POW, "(call $float_pow (i32.const 0) (i32.const 8) (i32.const 2) (i32.const 8) (i32.const 8) (i32.const 0))", diff --git a/crates/xrpl-wasm-vm/tests/host_calls.rs b/crates/xrpl-wasm-vm/tests/host_calls.rs index 6f2b4010ec..f5dd801c84 100644 --- a/crates/xrpl-wasm-vm/tests/host_calls.rs +++ b/crates/xrpl-wasm-vm/tests/host_calls.rs @@ -1011,23 +1011,6 @@ fn float_add_reads_both_operands_and_the_mode() { ); } -/// A unary operator that reads one float region, an integer, and a mode: all three -/// reach the host, tagged by operator. -#[test] -fn float_root_reads_the_float_the_degree_and_the_mode() { - let host = FakeHost::new().answering_float(support::Answer::filler(8)); - - let wat = module( - &[import::FLOAT_ROOT, ONE_PAGE], - "(call $float_root (i32.const 0) (i32.const 8) (i32.const 3) (i32.const 64) (i32.const 8) (i32.const 1))", - ); - assert_eq!(status(&wat, &host), 8, "the result length"); - assert_eq!( - *host.float_unary_ops_asked.borrow(), - vec![("root", vec![0u8; 8], 3, 1)] - ); -} - /// A leading scalar parameter reaches the host as declared. #[test] fn home_le_field_passes_the_field_selector_through() { diff --git a/crates/xrpl-wasm-vm/tests/preflight.rs b/crates/xrpl-wasm-vm/tests/preflight.rs index 4746237916..074759995a 100644 --- a/crates/xrpl-wasm-vm/tests/preflight.rs +++ b/crates/xrpl-wasm-vm/tests/preflight.rs @@ -158,7 +158,6 @@ const ALL_IMPORTS: [&str; 61] = [ import::FLOAT_SUB, import::FLOAT_MULT, import::FLOAT_DIV, - import::FLOAT_ROOT, import::FLOAT_POW, ]; diff --git a/crates/xrpl-wasm-vm/tests/support/mod.rs b/crates/xrpl-wasm-vm/tests/support/mod.rs index 2d0ea923e6..ab52f80c43 100644 --- a/crates/xrpl-wasm-vm/tests/support/mod.rs +++ b/crates/xrpl-wasm-vm/tests/support/mod.rs @@ -122,8 +122,7 @@ pub type PaychannelKey = (Vec, Vec, i32); /// `float_multiply`, `float_divide` — as `(operator, x, y, mode)`. pub type FloatBinaryCall = (&'static str, Vec, Vec, i32); -/// One call to a float operator over a float and an integer — `float_root`, -/// `float_power` — as `(operator, x, n, mode)`. +/// One call to a float operator over a float and an integer — `float_power` — as `(operator, x, n, mode)`. pub type FloatUnaryCall = (&'static str, Vec, i32, i32); /// A `HostFunctions` implementation that answers from what the test put in it and @@ -371,8 +370,7 @@ pub struct FakeHost { /// Every `(x, y, mode)` the four binary float operators were asked for, tagged by /// operator name. pub float_binary_ops_asked: RefCell>, - /// Every `(x, n, mode)` `float_root` and `float_power` were asked for, tagged by - /// operator name. + /// Every `(x, n, mode)` `float_power` was asked for, tagged by operator name. pub float_unary_ops_asked: RefCell>, } @@ -1389,13 +1387,6 @@ impl HostFunctions for FakeHost { self.float_answer.fill(out) } - fn float_root(&self, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> HostResult { - self.float_unary_ops_asked - .borrow_mut() - .push(("root", x.to_vec(), n, mode)); - self.float_answer.fill(out) - } - fn float_power(&self, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> HostResult { self.float_unary_ops_asked .borrow_mut() @@ -1488,7 +1479,6 @@ pub mod import { pub const FLOAT_SUB: &str = r#"(import "host_lib" "float_sub" (func $float_sub (param i32 i32 i32 i32 i32 i32 i32) (result i32)))"#; pub const FLOAT_MULT: &str = r#"(import "host_lib" "float_mult" (func $float_mult (param i32 i32 i32 i32 i32 i32 i32) (result i32)))"#; pub const FLOAT_DIV: &str = r#"(import "host_lib" "float_div" (func $float_div (param i32 i32 i32 i32 i32 i32 i32) (result i32)))"#; - pub const FLOAT_ROOT: &str = r#"(import "host_lib" "float_root" (func $float_root (param i32 i32 i32 i32 i32 i32) (result i32)))"#; pub const FLOAT_POW: &str = r#"(import "host_lib" "float_pow" (func $float_pow (param i32 i32 i32 i32 i32 i32) (result i32)))"#; } diff --git a/include/xrpl/tx/wasm/HostContext.h b/include/xrpl/tx/wasm/HostContext.h index 3ce625181c..0b20fc76f5 100644 --- a/include/xrpl/tx/wasm/HostContext.h +++ b/include/xrpl/tx/wasm/HostContext.h @@ -408,13 +408,6 @@ public: std::int32_t mode, rust::Slice out) const noexcept; - [[nodiscard]] std::int32_t - floatRoot( - rust::Slice x, - std::int32_t n, - std::int32_t mode, - rust::Slice out) const noexcept; - [[nodiscard]] std::int32_t floatPower( rust::Slice x, diff --git a/include/xrpl/tx/wasm/HostFunc.h b/include/xrpl/tx/wasm/HostFunc.h index ae0adcd9be..dae9e89ef9 100644 --- a/include/xrpl/tx/wasm/HostFunc.h +++ b/include/xrpl/tx/wasm/HostFunc.h @@ -57,9 +57,6 @@ floatMultiplyImpl(Slice const& x, Slice const& y, int32_t mode); std::expected floatDivideImpl(Slice const& x, Slice const& y, int32_t mode); -std::expected -floatRootImpl(Slice const& x, int32_t n, int32_t mode); - std::expected floatPowerImpl(Slice const& x, int32_t n, int32_t mode); @@ -454,12 +451,6 @@ public: return std::unexpected(HostFunctionError::Unimplemented); } - [[nodiscard]] [[nodiscard]] virtual std::expected - floatRoot(Slice const& x, int32_t n, int32_t mode) const - { - return std::unexpected(HostFunctionError::Unimplemented); - } - [[nodiscard]] [[nodiscard]] virtual std::expected floatPower(Slice const& x, int32_t n, int32_t mode) const { diff --git a/include/xrpl/tx/wasm/HostFuncImpl.h b/include/xrpl/tx/wasm/HostFuncImpl.h index 569b151e29..403b43659b 100644 --- a/include/xrpl/tx/wasm/HostFuncImpl.h +++ b/include/xrpl/tx/wasm/HostFuncImpl.h @@ -280,9 +280,6 @@ public: std::expected floatDivide(Slice const& x, Slice const& y, int32_t mode) const override; - std::expected - floatRoot(Slice const& x, int32_t n, int32_t mode) const override; - std::expected floatPower(Slice const& x, int32_t n, int32_t mode) const override; }; diff --git a/src/libxrpl/tx/wasm/HostContext.cpp b/src/libxrpl/tx/wasm/HostContext.cpp index a67860604a..f37334033d 100644 --- a/src/libxrpl/tx/wasm/HostContext.cpp +++ b/src/libxrpl/tx/wasm/HostContext.cpp @@ -1220,19 +1220,6 @@ HostContext::floatDivide( }); } -std::int32_t -HostContext::floatRoot( - rust::Slice x, - std::int32_t n, - std::int32_t mode, - rust::Slice out) const noexcept -{ - return guarded(hostFunctions_.getJournal(), kHostInternal, [&] { - return invoke( - out, [&] { return hostFunctions_.floatRoot(Slice{x.data(), x.size()}, n, mode); }); - }); -} - std::int32_t HostContext::floatPower( rust::Slice x, diff --git a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp index 2abd73d82c..4ec93eb2d9 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp @@ -383,32 +383,6 @@ floatDivideImpl(Slice const& x, Slice const& y, int32_t mode) } } -std::expected -floatRootImpl(Slice const& x, int32_t n, int32_t mode) -{ - try - { - if (n < 1) - return std::unexpected(HostFunctionError::FloatInputMalformed); - - detail::FloatState const rm(mode); - if (!rm) - return std::unexpected(HostFunctionError::FloatInputMalformed); - - auto const xx = detail::floatDecode(x); - if (!xx) - return std::unexpected(HostFunctionError::FloatInputMalformed); - - return detail::floatEncode(root(*xx, n)); - } - // LCOV_EXCL_START - catch (...) - { - return std::unexpected(HostFunctionError::FloatComputationError); - } - // LCOV_EXCL_STOP -} - std::expected floatPowerImpl(Slice const& x, int32_t n, int32_t mode) { @@ -515,12 +489,6 @@ WasmHostFunctionsImpl::floatDivide(Slice const& x, Slice const& y, int32_t mode) return wasm_float::floatDivideImpl(x, y, mode); } -std::expected -WasmHostFunctionsImpl::floatRoot(Slice const& x, int32_t n, int32_t mode) const -{ - return wasm_float::floatRootImpl(x, n, mode); -} - std::expected WasmHostFunctionsImpl::floatPower(Slice const& x, int32_t n, int32_t mode) const {