Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix build with Boost 1.85 and remove instances of viewkey logging #9450

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

jeffro256
Copy link
Contributor

@jeffro256 jeffro256 commented Aug 23, 2024

  1. Use std::is_standard_layout and std::is_trivially_copyable instead of std::is_pod for KV byte-wise serialization, which fixes compile issue for Boost UUIDs
  2. Use std::has_unique_object_representations instead of alignof(T) == 1 for epee byte spans and epee hex functions
  3. Removed reimplementation of std::hash for boost::uuids::uuid
  4. Removed << operator overload for crypto::secret_key
  5. Removed instances in code where private view key was dumped to the log in plaintext

@vtnerd
Copy link
Contributor

vtnerd commented Aug 23, 2024

This was a correct compile-time check, POD implied standard layout and trivial. Now you have to check for multiple things as you do here. One thing I noticed is that I didn't check for trivial copyable in epee::span, I'll look into upgrading that separately.

The epee::span check also does an alignof(...) == 1 in a crappy way to identify padding. I'm not sure if this can be added here without breaking compilation.

@jeffro256
Copy link
Contributor Author

POD implied standard layout and trivial

You're right, it's just that its probably too tight of property for what we need. namely, to do blob serialization, we don't care if the class is trivial as long as it is trivially copyable.

One thing I noticed is that I didn't check for trivial copyable in epee::span, I'll look into upgrading that separately.

We might want to change it here in this PR because Boost 1.85 also broke static assertions in other parts of the codebase: https://github.com/monero-project/monero/actions/runs/10529735156/job/29178145531?pr=9450.

@jeffro256 jeffro256 changed the title epee: fix serialization compile errors with Boost 1.85 build: fix build with Boost 1.85 and remove instances of viewkey logging Aug 23, 2024
@jeffro256 jeffro256 force-pushed the fix_kvser_boost_158 branch 2 times, most recently from 64d5655 to 75f1810 Compare August 23, 2024 23:06
@jeffro256
Copy link
Contributor Author

Okay so sorry for the spam, but it should be ready now

@jeffro256
Copy link
Contributor Author

jeffro256 commented Aug 24, 2024

Side note: we use a variable time algorithm for converting some of these secrets into hex which opens us up to cache timing attacks. Not a huge deal since we usually only hexify tx ephemeral privkeys (except in the wallet save code), and/or it can't be trivially triggered repeatedly. However, this is far from ideal.

@selsta
Copy link
Collaborator

selsta commented Aug 25, 2024

can confrim this solves compilation issues for me, please squash

@jeffro256
Copy link
Contributor Author

Squashed and implemented @vtnerd's suggestions for epee byte span functions

@@ -1091,6 +1091,7 @@ endif()
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS ${BOOST_COMPONENTS})
add_definitions(-DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION)
add_definitions(-DBOOST_NO_AUTO_PTR)
add_definitions(-DBOOST_UUID_DISABLE_ALIGNMENT) # This restores UUID's std::has_unique_object_representations property
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this target dependent instead of universal definition?

Roughly:

target_compile_definitions(boost::uuid PUBLIC -DBOOST_UUID_DISABLE_ALIGNMENT)

Or something like this:

set_property(TARGET boost::uuid APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS -DBOOST_UUID_DISABLE_ALIGNMENT)

The main objective is preventing polluting the global flag namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this flag for all translation units which include boost/uuid/uuid.hpp

Copy link
Collaborator

@selsta selsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also open against release-v0.18

@jeffro256
Copy link
Contributor Author

This PR requires C++17, which is not yet supported on the release branch

jeffro256 added a commit to jeffro256/monero that referenced this pull request Aug 28, 2024
…ing [RELEASE]

1. Use `std::is_standard_layout` and `std::is_trivially_copyable` instead of `std::is_pod` for KV byte-wise serialization, which fixes compile issue for Boost UUIDs
2. Removed reimplementation of `std::hash` for `boost::uuids::uuid`
3. Removed `<<` operator overload for `crypto::secret_key`
4. Removed instances in code where private view key was dumped to the log in plaintext

Release version of monero-project#9450
@@ -484,7 +484,7 @@ namespace cryptonote
crypto::generate_ring_signature(tx_prefix_hash, boost::get<txin_to_key>(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data());
ss_ring_s << "signatures:" << ENDL;
std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature& s){ss_ring_s << s << ENDL;});
ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output << ENDL;
ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << rct::sk2rct(in_contexts[i].in_ephemeral.sec) << ENDL << "real_output: " << src_entr.real_output << ENDL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are unwrap functions to expose the inner type without copy - unwrap(unwrap(txkey.sec)). This occurs several times throughout this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function rct::sk2rct also doesn't copy, but unwrap is a definitely a lot cleaner

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function does a return by value - so it is definitely triggering the copy constructor in this situation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind I missed the & by the function name. Yikes! This violates the aliasing rule, too bad I missed this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay newest force push drops usage of rct::sk2rct to convert secret keys to rct::key and uses unwrap or a wrapper called crypto::secret_key_explicit_print_ref. I can look into making a PR to fix the strict aliasing later

@woodser
Copy link
Contributor

woodser commented Aug 30, 2024

Builds for me as well (on the release branch). Thanks.

@woodser
Copy link
Contributor

woodser commented Sep 6, 2024

Is this generally stable enough to be used / trusted with funds?

I'm not able to build on macOS otherwise, so I'm stuck without it.

From vtnerd's last review, it looks like we're awaiting a couple more changes.

@jeffro256
Copy link
Contributor Author

It's probably safe for funds, but I'm going to push a commit very soon that makes it better (i.e. still copyless) in the scenario where we fix the strict aliasing violations with the rct::x2rct and rct::rct2x functions.

1. Use `std::is_standard_layout` and `std::is_trivially_copyable` instead of `std::is_pod` for KV byte-wise serialization, which fixes compile issue for Boost UUIDs
2. Use `std::has_unique_object_representations` instead of `alignof(T) == 1` for epee byte spans and epee hex functions
3. Removed reimplementation of `std::hash` for `boost::uuids::uuid
4. Removed `<<` operator overload for `crypto::secret_key`
5. Removed instances in code where private view key was dumped to the log in plaintext
@jeffro256
Copy link
Contributor Author

Windows build failure is unrelated to this PR

jeffro256 added a commit to jeffro256/monero that referenced this pull request Sep 10, 2024
…ing [RELEASE]

1. Use std::is_standard_layout and std::is_trivially_copyable instead of std::is_pod for KV byte-wise serialization, which fixes compile issue for Boost UUIDs
2. Removed reimplementation of std::hash for boost::uuids::uuid
3. Removed << operator overload for crypto::secret_key
4. Removed instances in code where private view key was dumped to the log in plaintext

Release version of monero-project#9450, containing C++14 modified assertions
woodser pushed a commit to woodser/monero that referenced this pull request Sep 21, 2024
…ing [RELEASE]

1. Use std::is_standard_layout and std::is_trivially_copyable instead of std::is_pod for KV byte-wise serialization, which fixes compile issue for Boost UUIDs
2. Removed reimplementation of std::hash for boost::uuids::uuid
3. Removed << operator overload for crypto::secret_key
4. Removed instances in code where private view key was dumped to the log in plaintext

Release version of monero-project#9450, containing C++14 modified assertions
everoddandeven pushed a commit to everoddandeven/monero that referenced this pull request Oct 1, 2024
…ing [RELEASE]

1. Use std::is_standard_layout and std::is_trivially_copyable instead of std::is_pod for KV byte-wise serialization, which fixes compile issue for Boost UUIDs
2. Removed reimplementation of std::hash for boost::uuids::uuid
3. Removed << operator overload for crypto::secret_key
4. Removed instances in code where private view key was dumped to the log in plaintext

Release version of monero-project#9450, containing C++14 modified assertions
@luigi1111 luigi1111 merged commit fabbde3 into monero-project:master Oct 1, 2024
17 of 18 checks passed
@hhartzer
Copy link

It would be great if there could be a new release with this feature to get Monero back into FreeBSD ports. It's currently marked as broken: https://cgit.freebsd.org/ports/commit/?id=3da4573eecd73a44684a43970822cac66177a70c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants