Commit Graph

1572 Commits

Author SHA1 Message Date
j-berman
9784ced3db fcmp++ tests: init tree once in memory and grow copy 2024-09-11 10:13:48 -07:00
j-berman
0ff1eaf948 Use macro to de-dupe curve trees test logic 2024-09-11 10:13:48 -07:00
j-berman
b71f2440bc fcmp++: better test names 2024-09-11 10:13:48 -07:00
j-berman
0688538110 fcmp++: add test to trim the tree then grow again after trimming 2024-09-11 10:13:48 -07:00
j-berman
072a82dd3f fcmp++: tests now test trimming to empty tree 2024-09-11 10:13:48 -07:00
j-berman
16ff6a9e68 fcmp++: trim tree when removing a block
- trim_tree now re-adds trimmed outputs back to the locked outputs
table. remove_output then deletes from the locked output table.
- Since outputs added to the tree in a specific block may have
originated from distinct younger blocks (thanks to distinct unlock
times), we need to store the 8 byte output_id in the leaves table
as well, so that in the event of a reorg, upon removing outputs
from the tree we can add them back to the locked outputs table
in the correct order.
2024-09-11 10:13:48 -07:00
j-berman
47d47bdd20 fcmp++: proof len from inputs *AND merkle tree depth 2024-08-14 11:42:30 -07:00
j-berman
918befb0f5 new_leaf_tuples -> new_outputs 2024-08-13 09:25:43 -07:00
j-berman
67f5546d10 lmdb touchup && OutputsByUnlockBlock map -> unordered_map 2024-08-13 09:24:43 -07:00
j-berman
83d56597e2 Clean lmbd impl
- Reverted back to storing output_id in locked_outputs table; it's
required to make sure outputs enter the tree in chain order I see
no other simple way.
- Removed unnecessary comments and db flags (MDB_APPENDDUP already
makes sure key/value doesn't already exist, and when inserting,
every global output id should be unique, so should never get that
error)
2024-08-10 02:20:55 -07:00
j-berman
6525df113c Don't store output_id in locked_outpust table, table stays ordered 2024-08-09 18:31:18 -07:00
j-berman
b6bcca9899 Remove ringct dep in fcmp_pp, impl in fcmp_pp_crypto 2024-08-09 16:29:31 -07:00
j-berman
9ad49189bb link correct cncrypto and ringct_basic libs 2024-08-09 16:24:21 -07:00
j-berman
f17db01250 fcmp++: store {output pubkey, commitment} in db, pre-torsion clear
- We must use the output pubkey to calculate key image generator I
- Since torsion cleared outputs can be spent via ring sig today,
if we torsion clear outputs **before** calculating I, then the key
image of torsioned outputs will be different when constructing
fcmp's, effectively enabling a double spend of torsioned outputs
via ring sig before fcmp's and again via fcmp.
- Storing {output pubkey, commitment} instead of {O.x,I.x,C.x} to
save 32 bytes per output.
2024-08-09 15:43:18 -07:00
j-berman
8b12a335c6 fcmp++: implement iterative audit_tree function
- Recursion goes too deep
2024-08-08 19:26:08 -07:00
j-berman
9f0dd859e6 fix clang compile errors 2024-08-08 14:55:49 -07:00
j-berman
d4847f649e Rename everything from fcmp* to fcmp_pp 2024-08-08 14:10:34 -07:00
j-berman
10c6c12b18 fcmp++: compilation fixes + misc. cleanup
- Removed call to hash_init_point in constructor
- Replaced global static CURVE_TREES_V1 with a smart pointer
- Don't need to link Rust static lib when including curve_trees.h
- leaves table doesn't need dupsort flags, all leaves should be
unique by key
- rename fcmp -> fcmp_pp
- return when 0 leaves passed into trim_tree
2024-08-08 13:31:21 -07:00
j-berman
30fc80b33e Don't copy when flattening leaves 2024-08-02 22:34:06 -07:00
j-berman
cbf6a5d618 Optimize conversion from output to leaf tuple 2024-08-02 22:32:03 -07:00
j-berman
b90cee8bab Store {O,C} for each leaf tuple instead of {O.x,I.x,C.x}
- Can derive {O.x,I.x,C.x} from {O,C}
- Note: this slows down tests since they do the derivation both
on insertion into the tree, and when auditing the tree
- At the hard fork, we don't need to store {O,C} in the
output_amounts table anymore since that table will no longer be
useful
2024-08-02 10:28:13 -07:00
j-berman
54d5d0d5c7 fcmp++: add support for new fcmp types in cryptonote::transaction
- Replace CLSAGs with a single fcmp_pp
- fcmp_pp is an opaque vector of bytes. The length of the vector
is calculated from the number of inputs on serialization (i.e. the
length is not serialized, only the raw bytes are serialized)
- Includes tests for binary serialization happy path and errors
2024-07-31 18:13:23 -07:00
j-berman
c383087955 Instantiate m_curve_trees on BlockchainLMDB class in c'tor 2024-07-29 03:40:44 -07:00
j-berman
b585a7f408 Remove copy in get_tree_extension and better named funcs 2024-07-29 03:40:44 -07:00
j-berman
93795b4c9d Match output unlock time (fix off by 1) 2024-07-29 03:40:44 -07:00
j-berman
634e12e9ad Guarantee insertion order into the tree using global output ID
- Leaves enter the tree in the block they unlock, in the order
they appear in the chain
2024-07-29 03:40:44 -07:00
j-berman
306488b690 Implemented growing the tree on sync + lots of cleaning
- validate output and commitment in tuple conversion function
- function to get_unlock_height from height in chain + unlock_time
- tx_outs_to_leaf_tuples function
- cleaned up trim impl (reduced num params in instructions and
conditional complexity)
- renamed locked_outputs table to locked_leaves (clearer tie to
merkle tree)
- size_t -> uint64_t for db compatibility across 32-bit and 64-bit
machines
- added hash_grow tests
2024-07-29 03:40:44 -07:00
j-berman
8a89c20f3b lmdb migration to init curve trees tree from existing outputs
still rough
2024-07-29 03:40:44 -07:00
j-berman
f50ad5baac trim_tree db impl + db test + some housekeeping 2024-07-29 03:40:44 -07:00
j-berman
42fd22c4ee Better organization 2024-07-29 03:40:44 -07:00
j-berman
55caee9a10 Better tests for hash_trim 2024-07-29 03:40:44 -07:00
j-berman
4be2d7cf91 whitespace fixes 2024-07-29 03:40:44 -07:00
j-berman
5ddca0ce11 Implement and test trim_tree algo in memory 2024-07-29 03:40:44 -07:00
j-berman
36f1e1965f Fix grow_tree, restructure it, and clean the approach
The initial impl didn't capture the following edge case:

  - Tree has 3 (or more) layers + 1 leaf layeri
  - Leaf layer last chunk IS full
  - Layer 0 last chunk is NOT full
  - Layer 1 last chunk is NOT full
  - Layer 2 last chunk IS NOT full

In this case, when updating layer 1, we need to use layer 0's old
last hash to update layer 1's old last hash. Same for Layer 2.

The solution is to use logic that checks the *prev* layer when
updating a layer to determine if the old last hash from the prev
layer is needed.

This commit restructures the grow_tree impl to account for this
and simplifies the approach as follows:

1. Read the tree to get num leaf tuples + last hashes in each layer

2. Get the tree extension using the above values + new leaf tuples
2a. Prior to updating the leaf layer, call the function
get_update_leaf_layer_metadata. This function uses existing totals
in the leaf layer, the new total of leaf tuples,  and tree params
to calculate how the layer after the leaf layer should be updated.
2b. For each subsequent layer, call the function
get_update_layer_metadata. This function uses the existing totals
in the *prev* layer, the new total of children in the *prev* layer,
and tree params to calculate how the layer should be updated.

3. Grow the tree using the tree extension.

This approach isolates update logic and actual hashing into neat
structured functions, rather than mix the two. This makes the code
easier to follow without needing to keep so much in your head at
one time.
2024-07-29 03:40:44 -07:00
j-berman
8287ba6f78 faster trim_tree tests 2024-07-29 03:40:44 -07:00
j-berman
ed040cacc1 implement trim_tree_in_memory 2024-07-29 03:40:44 -07:00
j-berman
e8af7090b0 expose and test hash_trim from rust lib 2024-07-29 03:40:44 -07:00
j-berman
ae89fddc00 Set up trim_tree_in_memory test 2024-07-29 03:40:44 -07:00
j-berman
c7c6c6afff CurveTreesUnitTest -> CurveTreesGlobalTree class 2024-07-29 03:40:44 -07:00
j-berman
17b1f421c0 cleaner lmdb test structure for curve trees 2024-07-29 03:40:44 -07:00
j-berman
6045357f6a implement db->audit_tree, and flesh out db test to init/extend tree 2024-07-29 03:40:44 -07:00
j-berman
ab7c74136b Simplify edge case handling in hash_layer
- When retrieving last chunks, set next_start_child_chunk_index
so can know the correct start index without needing to modify
the offset
- Other smaller cleanup
2024-07-29 03:40:44 -07:00
Luke Parker
c792b21535 Use statics on the Rust side for generators 2024-07-29 03:40:44 -07:00
Luke Parker
af47a135eb Remove cxx and expose scalars/points directly 2024-07-29 03:40:44 -07:00
j-berman
af9b74fcc7 start LMDB grow_tree 2024-07-29 03:40:44 -07:00
j-berman
5ad026975a Cleaner template usage, moved static functions out of CurveTrees class 2024-07-29 03:40:44 -07:00
j-berman
9ba00be519 Move curve_trees.h implementations into curve_trees.cpp file 2024-07-29 03:40:44 -07:00
j-berman
4ade675939 Consolidate hash_leaf_layer into hash_layer 2024-07-29 03:40:44 -07:00
j-berman
9e68475ebd Use widths from fcmp++ repo test & align tests with width 2024-07-29 03:40:44 -07:00
j-berman
29e0fe759e Add Curve class, and Helios & Selene classes that derive from Curve 2024-07-29 03:40:44 -07:00