15 assert(p.
on_curve() &&
"Point p is not on the curve");
16 assert(q.
on_curve() &&
"Point q is not on the curve");
19 add_events.emit({ .p = p, .q = q, .result = result });
28 assert(point.
on_curve() &&
"Point must be on the curve for scalar multiplication");
31 auto bits =
to_radix.to_le_bits(scalar, 254);
38 intermediate_states[0] = { result, temp, bit };
40 for (
size_t i = 1; i < 254; i++) {
42 temp =
add(temp, temp);
45 result =
add(result, temp);
47 intermediate_states[i] = { result, temp, bit };
50 { .point = point, .scalar = scalar, .intermediate_states =
std::move(intermediate_states), .result = result });
60 uint32_t space_id =
memory.get_space_id();
67 uint64_t max_write_address =
static_cast<uint64_t
>(dst_address) + 2;
69 throw std::runtime_error(
"dst address out of range");
73 throw std::runtime_error(
"One of the points is not on the curve");
77 memory.set(dst_address, MemoryValue::from<FF>(result.
x()));
78 memory.set(dst_address + 1, MemoryValue::from<FF>(result.
y()));
79 memory.set(dst_address + 2, MemoryValue::from<uint1_t>(result.
is_infinity() ? 1 : 0));
86 .dst_address = dst_address });
87 }
catch (
const std::exception& e) {
96 .dst_address = dst_address });
97 throw EccException(
"Add failed: " + std::string(e.what()));
#define AVM_HIGHEST_MEM_ADDRESS
static const StandardAffinePoint & infinity()
constexpr bool is_infinity() const noexcept
constexpr const BaseField & x() const noexcept
constexpr const BaseField & y() const noexcept
constexpr bool on_curve() const noexcept
EventEmitterInterface< ScalarMulEvent > & scalar_mul_events
EmbeddedCurvePoint add(const EmbeddedCurvePoint &p, const EmbeddedCurvePoint &q) override
EmbeddedCurvePoint scalar_mul(const EmbeddedCurvePoint &point, const FF &scalar) override
EventEmitterInterface< EccAddMemoryEvent > & add_memory_events
ExecutionIdManagerInterface & execution_id_manager
EventEmitterInterface< EccAddEvent > & add_events
virtual uint32_t get_execution_id() const =0
StandardAffinePoint< AvmFlavorSettings::EmbeddedCurve::AffineElement > EmbeddedCurvePoint
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept