-
Notifications
You must be signed in to change notification settings - Fork 316
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
feat: Origin Tags part 3 (Memory) #9758
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8cb2fe5
Added tags and tags to memory tables and fixed a witness that should …
Rumata888 2e31fa8
Change logic
Rumata888 d979003
fix
Rumata888 2432430
Comment twin rom tests
Rumata888 638ade7
comments
Rumata888 dccc80f
comments
Rumata888 9645c72
fix
Rumata888 38916cd
fix
Rumata888 6ec550d
fix
Rumata888 85eec78
cleanup
Rumata888 6e7f907
Address comments
Rumata888 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,12 @@ template <typename Builder> rom_table<Builder>::rom_table(const std::vector<fiel | |
// if this is the case we might not have a valid pointer to a Builder | ||
// We get around this, by initializing the table when `operator[]` is called | ||
// with a non-const field element. | ||
|
||
// Initialize tags | ||
_tags.resize(raw_entries.size()); | ||
for (size_t i = 0; i < length; ++i) { | ||
_tags[i] = raw_entries[i].get_origin_tag(); | ||
} | ||
} | ||
|
||
// initialize the table once we perform a read. This ensures we always have a valid | ||
|
@@ -37,8 +43,11 @@ template <typename Builder> void rom_table<Builder>::initialize_table() const | |
// populate table. Table entries must be normalized and cannot be constants | ||
for (const auto& entry : raw_entries) { | ||
if (entry.is_constant()) { | ||
entries.emplace_back( | ||
field_pt::from_witness_index(context, context->put_constant_variable(entry.get_value()))); | ||
auto fixed_witness = | ||
field_pt::from_witness_index(context, context->put_constant_variable(entry.get_value())); | ||
fixed_witness.set_origin_tag(entry.get_origin_tag()); | ||
entries.emplace_back(fixed_witness); | ||
|
||
} else { | ||
entries.emplace_back(entry.normalize()); | ||
} | ||
|
@@ -49,13 +58,19 @@ template <typename Builder> void rom_table<Builder>::initialize_table() const | |
context->set_ROM_element(rom_id, i, entries[i].get_witness_index()); | ||
} | ||
|
||
// Preserve tags to restore them in the future lookups | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you forgot to initialize the tags inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a vector, so it is default-initialized |
||
_tags.resize(raw_entries.size()); | ||
for (size_t i = 0; i < length; ++i) { | ||
_tags[i] = raw_entries[i].get_origin_tag(); | ||
} | ||
initialized = true; | ||
} | ||
|
||
template <typename Builder> | ||
rom_table<Builder>::rom_table(const rom_table& other) | ||
: raw_entries(other.raw_entries) | ||
, entries(other.entries) | ||
, _tags(other._tags) | ||
, length(other.length) | ||
, rom_id(other.rom_id) | ||
, initialized(other.initialized) | ||
|
@@ -66,6 +81,7 @@ template <typename Builder> | |
rom_table<Builder>::rom_table(rom_table&& other) | ||
: raw_entries(other.raw_entries) | ||
, entries(other.entries) | ||
, _tags(other._tags) | ||
, length(other.length) | ||
, rom_id(other.rom_id) | ||
, initialized(other.initialized) | ||
|
@@ -76,6 +92,7 @@ template <typename Builder> rom_table<Builder>& rom_table<Builder>::operator=(co | |
{ | ||
raw_entries = other.raw_entries; | ||
entries = other.entries; | ||
_tags = other._tags; | ||
length = other.length; | ||
rom_id = other.rom_id; | ||
initialized = other.initialized; | ||
|
@@ -87,6 +104,7 @@ template <typename Builder> rom_table<Builder>& rom_table<Builder>::operator=(ro | |
{ | ||
raw_entries = other.raw_entries; | ||
entries = other.entries; | ||
_tags = other._tags; | ||
length = other.length; | ||
rom_id = other.rom_id; | ||
initialized = other.initialized; | ||
|
@@ -112,13 +130,24 @@ template <typename Builder> field_t<Builder> rom_table<Builder>::operator[](cons | |
if (context == nullptr) { | ||
context = index.get_context(); | ||
} | ||
|
||
initialize_table(); | ||
if (uint256_t(index.get_value()) >= length) { | ||
const auto native_index = uint256_t(index.get_value()); | ||
if (native_index >= length) { | ||
context->failure("rom_table: ROM array access out of bounds"); | ||
} | ||
|
||
uint32_t output_idx = context->read_ROM_array(rom_id, index.normalize().get_witness_index()); | ||
return field_pt::from_witness_index(context, output_idx); | ||
uint32_t output_idx = context->read_ROM_array(rom_id, index.get_normalized_witness_index()); | ||
auto element = field_pt::from_witness_index(context, output_idx); | ||
|
||
const size_t cast_index = static_cast<size_t>(static_cast<uint64_t>(native_index)); | ||
|
||
// If the index is legitimate, restore the tag | ||
if (native_index < length) { | ||
|
||
element.set_origin_tag(_tags[cast_index]); | ||
} | ||
return element; | ||
} | ||
|
||
template class rom_table<bb::UltraCircuitBuilder>; | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the bug