mirror of
https://github.com/monero-project/monero.git
synced 2025-01-10 14:49:41 -05:00
Only pass a single prior child
This commit is contained in:
parent
c792b21535
commit
effa9eea0e
@ -44,22 +44,20 @@ template class CurveTrees<Helios, Selene>;
|
|||||||
template<typename C>
|
template<typename C>
|
||||||
typename C::Point get_new_parent(const C &curve, const typename C::Chunk &new_children)
|
typename C::Point get_new_parent(const C &curve, const typename C::Chunk &new_children)
|
||||||
{
|
{
|
||||||
// New parent means no prior children, fill priors with 0
|
|
||||||
std::vector<typename C::Scalar> prior_children;
|
|
||||||
tower_cycle::extend_zeroes(curve, new_children.len, prior_children);
|
|
||||||
|
|
||||||
return curve.hash_grow(
|
return curve.hash_grow(
|
||||||
curve.m_hash_init_point,
|
curve.m_hash_init_point,
|
||||||
0,/*offset*/
|
0,/*offset*/
|
||||||
typename C::Chunk{prior_children.data(), prior_children.size()},
|
curve.zero_scalar(),
|
||||||
new_children
|
new_children
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
template Helios::Point get_new_parent<Helios>(const Helios &curve, const typename Helios::Chunk &new_children);
|
||||||
|
template Selene::Point get_new_parent<Selene>(const Selene &curve, const typename Selene::Chunk &new_children);
|
||||||
//----------------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------------
|
||||||
//----------------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------------
|
||||||
// Static functions
|
// Static functions
|
||||||
//----------------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------------
|
||||||
// Hash the first chunk of children being added to a layer
|
// Hash the first chunk of the children now being added to a layer
|
||||||
template<typename C>
|
template<typename C>
|
||||||
static typename C::Point get_first_parent(const C &curve,
|
static typename C::Point get_first_parent(const C &curve,
|
||||||
const typename C::Chunk &new_children,
|
const typename C::Chunk &new_children,
|
||||||
@ -72,21 +70,17 @@ static typename C::Point get_first_parent(const C &curve,
|
|||||||
if (last_chunk_ptr == nullptr)
|
if (last_chunk_ptr == nullptr)
|
||||||
return get_new_parent<C>(curve, new_children);
|
return get_new_parent<C>(curve, new_children);
|
||||||
|
|
||||||
std::vector<typename C::Scalar> prior_children;
|
typename C::Scalar first_child_after_offset = curve.zero_scalar();
|
||||||
|
|
||||||
if (child_layer_last_hash_updated)
|
if (child_layer_last_hash_updated)
|
||||||
{
|
{
|
||||||
// If the last chunk has updated children in it, then we need to get the delta to the old children
|
// If the last chunk has updated children in it, then we need to get the delta to the old children
|
||||||
prior_children.emplace_back(last_chunk_ptr->last_child);
|
first_child_after_offset = last_chunk_ptr->last_child;
|
||||||
|
|
||||||
// Extend prior children by zeroes for any additional new children, since they must be new
|
|
||||||
if (new_children.len > 1)
|
|
||||||
tower_cycle::extend_zeroes(curve, new_children.len - 1, prior_children);
|
|
||||||
}
|
}
|
||||||
else if (offset > 0)
|
else if (offset > 0)
|
||||||
{
|
{
|
||||||
// If we're updating the parent hash and no children were updated, then we're just adding new children
|
// If we're updating the parent hash and no children were updated, then we're just adding new children
|
||||||
// to the existing last chunk and can fill priors with 0
|
// to the existing last chunk and can leave first_child_after_offset as zero
|
||||||
tower_cycle::extend_zeroes(curve, new_children.len, prior_children);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -97,7 +91,7 @@ static typename C::Point get_first_parent(const C &curve,
|
|||||||
return curve.hash_grow(
|
return curve.hash_grow(
|
||||||
last_chunk_ptr->last_parent,
|
last_chunk_ptr->last_parent,
|
||||||
offset,
|
offset,
|
||||||
typename C::Chunk{prior_children.data(), prior_children.size()},
|
first_child_after_offset,
|
||||||
new_children
|
new_children
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
24
src/fcmp/fcmp_rust/Cargo.lock
generated
24
src/fcmp/fcmp_rust/Cargo.lock
generated
@ -71,7 +71,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ciphersuite"
|
name = "ciphersuite"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake2",
|
"blake2",
|
||||||
"dalek-ff-group",
|
"dalek-ff-group",
|
||||||
@ -161,7 +161,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "dalek-ff-group"
|
name = "dalek-ff-group"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crypto-bigint",
|
"crypto-bigint",
|
||||||
"curve25519-dalek",
|
"curve25519-dalek",
|
||||||
@ -198,7 +198,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ec-divisors"
|
name = "ec-divisors"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dalek-ff-group",
|
"dalek-ff-group",
|
||||||
"group",
|
"group",
|
||||||
@ -272,7 +272,7 @@ checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "flexible-transcript"
|
name = "flexible-transcript"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake2",
|
"blake2",
|
||||||
"digest",
|
"digest",
|
||||||
@ -285,7 +285,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "full-chain-membership-proofs"
|
name = "full-chain-membership-proofs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ciphersuite",
|
"ciphersuite",
|
||||||
"ec-divisors",
|
"ec-divisors",
|
||||||
@ -305,7 +305,7 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "generalized-bulletproofs"
|
name = "generalized-bulletproofs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ciphersuite",
|
"ciphersuite",
|
||||||
"flexible-transcript",
|
"flexible-transcript",
|
||||||
@ -368,7 +368,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "helioselene"
|
name = "helioselene"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crypto-bigint",
|
"crypto-bigint",
|
||||||
"dalek-ff-group",
|
"dalek-ff-group",
|
||||||
@ -429,7 +429,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "minimal-ed448"
|
name = "minimal-ed448"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crypto-bigint",
|
"crypto-bigint",
|
||||||
"ff",
|
"ff",
|
||||||
@ -444,7 +444,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "multiexp"
|
name = "multiexp"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ff",
|
"ff",
|
||||||
"group",
|
"group",
|
||||||
@ -613,7 +613,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "std-shims"
|
name = "std-shims"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a17500708f5c6d79ec9cc33d53c771149db152c3"
|
source = "git+https://github.com/kayabaNerve/fcmp-plus-plus#a11db094aac0384b9e62930f6f9f0d062d436897"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
"spin",
|
"spin",
|
||||||
@ -627,9 +627,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.65"
|
version = "2.0.66"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106"
|
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -113,12 +113,12 @@ SeleneScalar selene_zero_scalar();
|
|||||||
|
|
||||||
CResult<HeliosPoint> hash_grow_helios(HeliosPoint existing_hash,
|
CResult<HeliosPoint> hash_grow_helios(HeliosPoint existing_hash,
|
||||||
uintptr_t offset,
|
uintptr_t offset,
|
||||||
HeliosScalarSlice prior_children,
|
HeliosScalar first_child_after_offset,
|
||||||
HeliosScalarSlice new_children);
|
HeliosScalarSlice new_children);
|
||||||
|
|
||||||
CResult<SelenePoint> hash_grow_selene(SelenePoint existing_hash,
|
CResult<SelenePoint> hash_grow_selene(SelenePoint existing_hash,
|
||||||
uintptr_t offset,
|
uintptr_t offset,
|
||||||
SeleneScalarSlice prior_children,
|
SeleneScalar first_child_after_offset,
|
||||||
SeleneScalarSlice new_children);
|
SeleneScalarSlice new_children);
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
@ -79,12 +79,11 @@ pub extern "C" fn selene_point_to_bytes(selene_point: SelenePoint) -> *const u8
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the x coordinate of the ed25519 point
|
// Get the x coordinate of the ed25519 point
|
||||||
// TODO: Move this to C++
|
|
||||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn ed25519_point_to_selene_scalar(ed25519_point: *const u8) -> SeleneScalar {
|
pub extern "C" fn ed25519_point_to_selene_scalar(ed25519_point: *const u8) -> SeleneScalar {
|
||||||
let mut ed25519_point = unsafe { core::slice::from_raw_parts(ed25519_point, 32) };
|
let mut ed25519_point = unsafe { core::slice::from_raw_parts(ed25519_point, 32) };
|
||||||
// TODO: If not moved to C++, at least return an error here (instead of unwrapping)
|
// TODO: Return an error here (instead of unwrapping)
|
||||||
let ed25519_point = <Ed25519>::read_G(&mut ed25519_point).unwrap();
|
let ed25519_point = <Ed25519>::read_G(&mut ed25519_point).unwrap();
|
||||||
|
|
||||||
let xy_coords = <Ed25519 as Ciphersuite>::G::to_xy(ed25519_point);
|
let xy_coords = <Ed25519 as Ciphersuite>::G::to_xy(ed25519_point);
|
||||||
@ -153,14 +152,14 @@ impl<T, E> CResult<T, E> {
|
|||||||
pub extern "C" fn hash_grow_helios(
|
pub extern "C" fn hash_grow_helios(
|
||||||
existing_hash: HeliosPoint,
|
existing_hash: HeliosPoint,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
prior_children: HeliosScalarSlice,
|
first_child_after_offset: HeliosScalar,
|
||||||
new_children: HeliosScalarSlice,
|
new_children: HeliosScalarSlice,
|
||||||
) -> CResult<HeliosPoint, io::Error> {
|
) -> CResult<HeliosPoint, io::Error> {
|
||||||
let hash = hash_grow(
|
let hash = hash_grow(
|
||||||
helios_generators(),
|
helios_generators(),
|
||||||
existing_hash,
|
existing_hash,
|
||||||
offset,
|
offset,
|
||||||
prior_children.into(),
|
first_child_after_offset,
|
||||||
new_children.into(),
|
new_children.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -178,14 +177,14 @@ pub extern "C" fn hash_grow_helios(
|
|||||||
pub extern "C" fn hash_grow_selene(
|
pub extern "C" fn hash_grow_selene(
|
||||||
existing_hash: SelenePoint,
|
existing_hash: SelenePoint,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
prior_children: SeleneScalarSlice,
|
first_child_after_offset: SeleneScalar,
|
||||||
new_children: SeleneScalarSlice,
|
new_children: SeleneScalarSlice,
|
||||||
) -> CResult<SelenePoint, io::Error> {
|
) -> CResult<SelenePoint, io::Error> {
|
||||||
let hash = hash_grow(
|
let hash = hash_grow(
|
||||||
selene_generators(),
|
selene_generators(),
|
||||||
existing_hash,
|
existing_hash,
|
||||||
offset,
|
offset,
|
||||||
prior_children.into(),
|
first_child_after_offset,
|
||||||
new_children.into(),
|
new_children.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -48,13 +48,13 @@ Selene::CycleScalar Selene::point_to_cycle_scalar(const Selene::Point &point) co
|
|||||||
Helios::Point Helios::hash_grow(
|
Helios::Point Helios::hash_grow(
|
||||||
const Helios::Point &existing_hash,
|
const Helios::Point &existing_hash,
|
||||||
const std::size_t offset,
|
const std::size_t offset,
|
||||||
const Helios::Chunk &prior_children,
|
const Helios::Scalar &first_child_after_offset,
|
||||||
const Helios::Chunk &new_children) const
|
const Helios::Chunk &new_children) const
|
||||||
{
|
{
|
||||||
auto res = fcmp_rust::hash_grow_helios(
|
auto res = fcmp_rust::hash_grow_helios(
|
||||||
existing_hash,
|
existing_hash,
|
||||||
offset,
|
offset,
|
||||||
prior_children,
|
first_child_after_offset,
|
||||||
new_children);
|
new_children);
|
||||||
if (res.err != 0) {
|
if (res.err != 0) {
|
||||||
throw std::runtime_error("failed to hash grow");
|
throw std::runtime_error("failed to hash grow");
|
||||||
@ -65,13 +65,13 @@ Helios::Point Helios::hash_grow(
|
|||||||
Selene::Point Selene::hash_grow(
|
Selene::Point Selene::hash_grow(
|
||||||
const Selene::Point &existing_hash,
|
const Selene::Point &existing_hash,
|
||||||
const std::size_t offset,
|
const std::size_t offset,
|
||||||
const Selene::Chunk &prior_children,
|
const Selene::Scalar &first_child_after_offset,
|
||||||
const Selene::Chunk &new_children) const
|
const Selene::Chunk &new_children) const
|
||||||
{
|
{
|
||||||
auto res = fcmp_rust::hash_grow_selene(
|
auto res = fcmp_rust::hash_grow_selene(
|
||||||
existing_hash,
|
existing_hash,
|
||||||
offset,
|
offset,
|
||||||
prior_children,
|
first_child_after_offset,
|
||||||
new_children);
|
new_children);
|
||||||
if (res.err != 0) {
|
if (res.err != 0) {
|
||||||
throw std::runtime_error("failed to hash grow");
|
throw std::runtime_error("failed to hash grow");
|
||||||
@ -150,6 +150,10 @@ std::string Selene::to_string(const typename Selene::Point &point) const
|
|||||||
//----------------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------------
|
||||||
SeleneScalar ed_25519_point_to_scalar(const crypto::ec_point &point)
|
SeleneScalar ed_25519_point_to_scalar(const crypto::ec_point &point)
|
||||||
{
|
{
|
||||||
|
// If this function receives the ec_point, this is fine
|
||||||
|
// If this function can receive a decompressed point, it'd be notably faster
|
||||||
|
// to extract the Wei25519 x coordinate from the C side of things and then
|
||||||
|
// pass that
|
||||||
return fcmp_rust::ed25519_point_to_selene_scalar((uint8_t*) &point.data);
|
return fcmp_rust::ed25519_point_to_selene_scalar((uint8_t*) &point.data);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------------
|
||||||
@ -182,7 +186,6 @@ void extend_scalars_from_cycle_points(const C_POINTS &curve,
|
|||||||
|
|
||||||
for (const auto &point : points)
|
for (const auto &point : points)
|
||||||
{
|
{
|
||||||
// TODO: implement reading just the x coordinate of points on curves in curve cycle in C/C++
|
|
||||||
typename C_SCALARS::Scalar scalar = curve.point_to_cycle_scalar(point);
|
typename C_SCALARS::Scalar scalar = curve.point_to_cycle_scalar(point);
|
||||||
scalars_out.push_back(std::move(scalar));
|
scalars_out.push_back(std::move(scalar));
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public:
|
|||||||
virtual typename C::Point hash_grow(
|
virtual typename C::Point hash_grow(
|
||||||
const typename C::Point &existing_hash,
|
const typename C::Point &existing_hash,
|
||||||
const std::size_t offset,
|
const std::size_t offset,
|
||||||
const typename C::Chunk &prior_children,
|
const typename C::Scalar &first_child_after_offset,
|
||||||
const typename C::Chunk &new_children) const = 0;
|
const typename C::Chunk &new_children) const = 0;
|
||||||
|
|
||||||
virtual typename C::Scalar zero_scalar() const = 0;
|
virtual typename C::Scalar zero_scalar() const = 0;
|
||||||
@ -120,7 +120,7 @@ public:
|
|||||||
Point hash_grow(
|
Point hash_grow(
|
||||||
const Point &existing_hash,
|
const Point &existing_hash,
|
||||||
const std::size_t offset,
|
const std::size_t offset,
|
||||||
const Chunk &prior_children,
|
const Scalar &first_child_after_offset,
|
||||||
const Chunk &new_children) const override;
|
const Chunk &new_children) const override;
|
||||||
|
|
||||||
Scalar zero_scalar() const override;
|
Scalar zero_scalar() const override;
|
||||||
@ -154,7 +154,7 @@ public:
|
|||||||
Point hash_grow(
|
Point hash_grow(
|
||||||
const Point &existing_hash,
|
const Point &existing_hash,
|
||||||
const std::size_t offset,
|
const std::size_t offset,
|
||||||
const Chunk &prior_children,
|
const Scalar &first_child_after_offset,
|
||||||
const Chunk &new_children) const override;
|
const Chunk &new_children) const override;
|
||||||
|
|
||||||
Scalar zero_scalar() const override;
|
Scalar zero_scalar() const override;
|
||||||
|
Loading…
Reference in New Issue
Block a user