Skip to content

Commit d3bc1ee

Browse files
committed
carrot_core [1/8/2025]
1 parent 2e8a128 commit d3bc1ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6737
-3
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
path = external/supercop
1515
url = https://github.com/monero-project/supercop
1616
branch = monero
17+
[submodule "external/mx25519"]
18+
path = external/mx25519
19+
url = https://github.com/jeffro256/mx25519
20+
branch = unclamped

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ else()
360360
message(STATUS "Building without build tag")
361361
endif()
362362

363+
option(MANUAL_SUBMODULES "Skip submodule up-to-date checks" OFF)
363364
if(NOT MANUAL_SUBMODULES)
364365
find_package(Git)
365366
if(GIT_FOUND)
@@ -380,6 +381,7 @@ if(NOT MANUAL_SUBMODULES)
380381
check_submodule(external/trezor-common)
381382
check_submodule(external/randomx)
382383
check_submodule(external/supercop)
384+
check_submodule(external/mx25519)
383385
endif()
384386
endif()
385387

@@ -461,7 +463,7 @@ elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
461463
set(BSDI TRUE)
462464
endif()
463465

464-
include_directories(external/rapidjson/include external/easylogging++ src contrib/epee/include external external/supercop/include)
466+
include_directories(external/rapidjson/include external/easylogging++ src contrib/epee/include external external/supercop/include external/mx25519/include)
465467

466468
if(APPLE)
467469
cmake_policy(SET CMP0042 NEW)

external/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ add_subdirectory(db_drivers)
7070
add_subdirectory(easylogging++)
7171
add_subdirectory(qrcodegen)
7272
add_subdirectory(randomx EXCLUDE_FROM_ALL)
73+
add_subdirectory(mx25519)

external/mx25519

Submodule mx25519 added at 3c3a36d

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ endfunction ()
8383
include(Version)
8484
monero_add_library(version SOURCES ${CMAKE_BINARY_DIR}/version.cpp DEPENDS genversion)
8585

86+
add_subdirectory(carrot_core)
8687
add_subdirectory(common)
8788
add_subdirectory(crypto)
8889
add_subdirectory(ringct)

src/carrot_core/CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright (c) 2024, The Monero Project
2+
#
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are
6+
# permitted provided that the following conditions are met:
7+
#
8+
# 1. Redistributions of source code must retain the above copyright notice, this list of
9+
# conditions and the following disclaimer.
10+
#
11+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
12+
# of conditions and the following disclaimer in the documentation and/or other
13+
# materials provided with the distribution.
14+
#
15+
# 3. Neither the name of the copyright holder nor the names of its contributors may be
16+
# used to endorse or promote products derived from this software without specific
17+
# prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21+
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22+
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27+
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
set(carrot_core_sources
30+
account_secrets.cpp
31+
address_utils.cpp
32+
carrot_enote_scan.cpp
33+
core_types.cpp
34+
destination.cpp
35+
device_ram_borrowed.cpp
36+
enote_utils.cpp
37+
hash_functions.cpp
38+
output_set_finalization.cpp
39+
payment_proposal.cpp)
40+
41+
monero_find_all_headers(carrot_core_headers, "${CMAKE_CURRENT_SOURCE_DIR}")
42+
43+
monero_add_library(carrot_core
44+
${carrot_core_sources}
45+
${carrot_core_headers})
46+
47+
target_link_libraries(carrot_core
48+
PUBLIC
49+
cncrypto
50+
epee
51+
ringct
52+
seraphis_crypto
53+
PRIVATE
54+
${EXTRA_LIBRARIES})
55+
56+
target_include_directories(carrot_core
57+
PUBLIC
58+
"${CMAKE_CURRENT_SOURCE_DIR}"
59+
PRIVATE
60+
${Boost_INCLUDE_DIRS})
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright (c) 2024, The Monero Project
2+
//
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without modification, are
6+
// permitted provided that the following conditions are met:
7+
//
8+
// 1. Redistributions of source code must retain the above copyright notice, this list of
9+
// conditions and the following disclaimer.
10+
//
11+
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12+
// of conditions and the following disclaimer in the documentation and/or other
13+
// materials provided with the distribution.
14+
//
15+
// 3. Neither the name of the copyright holder nor the names of its contributors may be
16+
// used to endorse or promote products derived from this software without specific
17+
// prior written permission.
18+
//
19+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20+
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21+
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22+
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26+
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27+
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
//paired header
30+
#include "account_secrets.h"
31+
32+
//local headers
33+
#include "config.h"
34+
#include "crypto/generators.h"
35+
#include "hash_functions.h"
36+
#include "ringct/rctOps.h"
37+
#include "transcript_fixed.h"
38+
39+
//third party headers
40+
41+
//standard headers
42+
43+
#undef MONERO_DEFAULT_LOG_CATEGORY
44+
#define MONERO_DEFAULT_LOG_CATEGORY "carrot"
45+
46+
namespace carrot
47+
{
48+
//-------------------------------------------------------------------------------------------------------------------
49+
void make_carrot_provespend_key(const crypto::secret_key &s_master,
50+
crypto::secret_key &k_prove_spend_out)
51+
{
52+
// k_ps = H_n(s_m)
53+
const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_PROVE_SPEND_KEY>();
54+
derive_scalar(transcript.data(), transcript.size(), &s_master, to_bytes(k_prove_spend_out));
55+
}
56+
//-------------------------------------------------------------------------------------------------------------------
57+
void make_carrot_viewbalance_secret(const crypto::secret_key &s_master,
58+
crypto::secret_key &s_view_balance_out)
59+
{
60+
// s_vb = H_32(s_m)
61+
const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_VIEW_BALANCE_SECRET>();
62+
derive_bytes_32(transcript.data(), transcript.size(), &s_master, to_bytes(s_view_balance_out));
63+
}
64+
//-------------------------------------------------------------------------------------------------------------------
65+
void make_carrot_generateimage_key(const crypto::secret_key &s_view_balance,
66+
crypto::secret_key &k_generate_image_out)
67+
{
68+
// k_gi = H_n(s_vb)
69+
const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_GENERATE_IMAGE_KEY>();
70+
derive_scalar(transcript.data(), transcript.size(), &s_view_balance, to_bytes(k_generate_image_out));
71+
}
72+
//-------------------------------------------------------------------------------------------------------------------
73+
void make_carrot_viewincoming_key(const crypto::secret_key &s_view_balance,
74+
crypto::secret_key &k_view_out)
75+
{
76+
// k_v = H_n(s_vb)
77+
const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_INCOMING_VIEW_KEY>();
78+
derive_scalar(transcript.data(), transcript.size(), &s_view_balance, to_bytes(k_view_out));
79+
}
80+
//-------------------------------------------------------------------------------------------------------------------
81+
void make_carrot_generateaddress_secret(const crypto::secret_key &s_view_balance,
82+
crypto::secret_key &s_generate_address_out)
83+
{
84+
// s_ga = H_32(s_vb)
85+
const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_GENERATE_ADDRESS_SECRET>();
86+
derive_bytes_32(transcript.data(), transcript.size(), &s_view_balance, to_bytes(s_generate_address_out));
87+
}
88+
//-------------------------------------------------------------------------------------------------------------------
89+
void make_carrot_spend_pubkey(const crypto::secret_key &k_generate_image,
90+
const crypto::secret_key &k_prove_spend,
91+
crypto::public_key &spend_pubkey_out)
92+
{
93+
// k_ps T
94+
rct::key tmp;
95+
rct::scalarmultKey(tmp, rct::pk2rct(crypto::get_T()), rct::sk2rct(k_prove_spend));
96+
97+
// K_s = k_gi G + k_ps T
98+
rct::addKeys1(tmp, rct::sk2rct(k_generate_image), tmp);
99+
spend_pubkey_out = rct::rct2pk(tmp);
100+
}
101+
//-------------------------------------------------------------------------------------------------------------------
102+
} //namespace carrot

src/carrot_core/account_secrets.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (c) 2024, The Monero Project
2+
//
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without modification, are
6+
// permitted provided that the following conditions are met:
7+
//
8+
// 1. Redistributions of source code must retain the above copyright notice, this list of
9+
// conditions and the following disclaimer.
10+
//
11+
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12+
// of conditions and the following disclaimer in the documentation and/or other
13+
// materials provided with the distribution.
14+
//
15+
// 3. Neither the name of the copyright holder nor the names of its contributors may be
16+
// used to endorse or promote products derived from this software without specific
17+
// prior written permission.
18+
//
19+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20+
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21+
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22+
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26+
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27+
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
////
30+
// Core implementation details for making Carrot privkeys, secrets, and pubkeys.
31+
// - Carrot is a specification for FCMP-RingCT compatible addressing
32+
//
33+
// references:
34+
// * https://github.com/jeffro256/carrot/blob/master/carrot.md
35+
///
36+
37+
#pragma once
38+
39+
//local headers
40+
#include "crypto/crypto.h"
41+
42+
//third party headers
43+
44+
//standard headers
45+
46+
//forward declarations
47+
48+
49+
namespace carrot
50+
{
51+
52+
/**
53+
* brief: make_carrot_provespend_key - prove-spend key, for signing input proofs to spend enotes
54+
* k_ps = H_n(s_m)
55+
* param: s_master - s_m
56+
* outparam: k_prove_spend_out - k_ps
57+
*/
58+
void make_carrot_provespend_key(const crypto::secret_key &s_master,
59+
crypto::secret_key &k_prove_spend_out);
60+
/**
61+
* brief: make_carrot_viewbalance_secret - view-balance secret, for viewing all balance information
62+
* s_vb = H_n(s_m)
63+
* param: s_master - s_m
64+
* outparam: s_view_balance_out - s_vb
65+
*/
66+
void make_carrot_viewbalance_secret(const crypto::secret_key &s_master,
67+
crypto::secret_key &s_view_balance_out);
68+
/**
69+
* brief: make_carrot_generateimage_key - generate-image key, for identifying enote spends
70+
* k_gi = H_n(s_vb)
71+
* param: s_view_balance - s_vb
72+
* outparam: k_generate_image_out - k_gi
73+
*/
74+
void make_carrot_generateimage_key(const crypto::secret_key &s_view_balance,
75+
crypto::secret_key &k_generate_image_out);
76+
/**
77+
* brief: make_carrot_viewincoming_key - view-incoming key, for identifying received external enotes
78+
* k_v = H_n(s_vb)
79+
* param: s_view_balance - s_vb
80+
* outparam: k_view_out - k_v
81+
*/
82+
void make_carrot_viewincoming_key(const crypto::secret_key &s_view_balance,
83+
crypto::secret_key &k_view_out);
84+
/**
85+
* brief: make_carrot_generateaddress_secret - generate-address secret, for generating addresses
86+
* s_ga = H_32(s_vb)
87+
* param: s_view_balance - s_vb
88+
* outparam: s_generate_address_out - s_ga
89+
*/
90+
void make_carrot_generateaddress_secret(const crypto::secret_key &s_view_balance,
91+
crypto::secret_key &s_generate_address_out);
92+
/**
93+
* brief: make_carrot_spend_pubkey - base public spendkey for rerandomizable RingCT
94+
* K_s = k_gi G + k_ps T
95+
* param: k_generate_image - k_gi
96+
* param: k_prove_spend - k_ps
97+
* outparam: spend_pubkey_out - K_s
98+
*/
99+
void make_carrot_spend_pubkey(const crypto::secret_key &k_generate_image,
100+
const crypto::secret_key &k_prove_spend,
101+
crypto::public_key &spend_pubkey_out);
102+
103+
} //namespace carrot

0 commit comments

Comments
 (0)