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

fix: move constants to namespace to avoid colision #142

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/test-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@

using hash_type = cartesi::keccak_256_hasher::hash_type;

// Calculate root hash for data buffer of log2_size
namespace detail {

constexpr int WORD_LOG2_SIZE = 3;
constexpr uint64_t WORD_SIZE = (UINT64_C(1) << WORD_LOG2_SIZE);
constexpr int PAGE_LOG2_SIZE = 12;
constexpr int PAGE_SIZE = (UINT64_C(1) << PAGE_LOG2_SIZE);

// Calculate root hash for data buffer of log2_size
namespace detail {
static hash_type merkle_hash(cartesi::keccak_256_hasher &h, const std::string_view &data, int log2_size) {
hash_type result;
if (log2_size > WORD_LOG2_SIZE) {
Expand Down Expand Up @@ -121,10 +121,10 @@ static hash_type calculate_emulator_hash(const std::vector<std::string> &pmas_fi
static_cast<int>(path.size()) != end) {
throw std::invalid_argument("PMA filename '" + path + "' does not match '%x--%x.bin'");
}
if ((length >> PAGE_LOG2_SIZE) << PAGE_LOG2_SIZE != length) {
if ((length >> detail::PAGE_LOG2_SIZE) << detail::PAGE_LOG2_SIZE != length) {
throw std::invalid_argument("PMA '" + path + "' length not multiple of page length");
}
if ((start >> PAGE_LOG2_SIZE) << PAGE_LOG2_SIZE != start) {
if ((start >> detail::PAGE_LOG2_SIZE) << detail::PAGE_LOG2_SIZE != start) {
throw std::invalid_argument("PMA '" + path + "' start not page-aligned");
}
auto data = load_file(path);
Expand All @@ -138,10 +138,10 @@ static hash_type calculate_emulator_hash(const std::vector<std::string> &pmas_fi
cartesi::back_merkle_tree tree(64, 12, 3);
uint64_t last = 0;
for (const auto &e : pma_entries) {
tree.pad_back((e.start - last) >> PAGE_LOG2_SIZE);
for (uint64_t s = 0; s < e.length; s += PAGE_SIZE) {
std::string_view page{e.data.data() + s, PAGE_SIZE};
auto page_hash = merkle_hash(page, PAGE_LOG2_SIZE);
tree.pad_back((e.start - last) >> detail::PAGE_LOG2_SIZE);
for (uint64_t s = 0; s < e.length; s += detail::PAGE_SIZE) {
std::string_view page{e.data.data() + s, detail::PAGE_SIZE};
auto page_hash = merkle_hash(page, detail::PAGE_LOG2_SIZE);
tree.push_back(page_hash);
}
last = e.start + e.length;
Expand Down