diff --git a/cairo_programs/cairo-1-contracts/field_sqrt.cairo b/cairo_programs/cairo-1-contracts/field_sqrt.cairo new file mode 100644 index 0000000000..9f0339e20e --- /dev/null +++ b/cairo_programs/cairo-1-contracts/field_sqrt.cairo @@ -0,0 +1,19 @@ +#[contract] +mod FieldSqrt { + use core::traits::Into; + use option::OptionTrait; + use ec::ec_point_from_x; + use ec::ec_point_non_zero; + use ec::ec_point_unwrap; + + #[external] + fn field_sqrt() -> felt252 { + let p = ec_point_from_x(10).unwrap(); + let p_nz = ec_point_non_zero(p); + + let (qx, _) = ec_point_unwrap(p_nz); + + assert(qx == 10, 'bad finalize x'); + qx + } +} diff --git a/src/tests/cairo_1_run_from_entrypoint_tests.rs b/src/tests/cairo_1_run_from_entrypoint_tests.rs index 3a52063b11..286fd045a8 100644 --- a/src/tests/cairo_1_run_from_entrypoint_tests.rs +++ b/src/tests/cairo_1_run_from_entrypoint_tests.rs @@ -520,3 +520,10 @@ fn widelmul128_test() { &[1_usize.into()], ); } + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn field_sqrt_test() { + let program_data = include_bytes!("../../cairo_programs/cairo-1-contracts/field_sqrt.casm"); + run_cairo_1_entrypoint(program_data.as_slice(), 0, &[], &[10.into()]); +}