-
Notifications
You must be signed in to change notification settings - Fork 284
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: Minimal globals in constant rollup data #882
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c84e1db
fix: move chainid into tx_context
LHerskind 22bdf02
chore: fix prettier
LHerskind 65e6bcf
feat: add version to tx_context
LHerskind 00c390e
feat: add global variables to ConstantRollupData
LHerskind 517a0ab
chore: fix prettier
LHerskind 981edb2
feat: force chain_id and version match between kernel and globals
LHerskind 86eb4e0
chore: fix tidy
LHerskind ca7ae7d
feat: add block_number and timestamp
LHerskind d320679
chore: update snapshots
LHerskind f557dd8
feat: Add globals to root rollup public inputs
LHerskind 043afa5
fix: update decoder
LHerskind 16b52b3
fix: update snapshots
LHerskind 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
91 changes: 91 additions & 0 deletions
91
circuits/cpp/src/aztec3/circuits/abis/global_variables.hpp
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#pragma once | ||
#include "function_data.hpp" | ||
#include "tx_context.hpp" | ||
|
||
#include "aztec3/utils/array.hpp" | ||
#include "aztec3/utils/types/circuit_types.hpp" | ||
#include "aztec3/utils/types/convert.hpp" | ||
#include "aztec3/utils/types/native_types.hpp" | ||
|
||
#include <barretenberg/barretenberg.hpp> | ||
|
||
namespace aztec3::circuits::abis { | ||
|
||
using aztec3::utils::types::CircuitTypes; | ||
using aztec3::utils::types::NativeTypes; | ||
|
||
template <typename NCT> struct GlobalVariables { | ||
using address = typename NCT::address; | ||
using fr = typename NCT::fr; | ||
using boolean = typename NCT::boolean; | ||
|
||
fr chain_id = 0; | ||
fr version = 0; | ||
fr block_number = 0; | ||
fr timestamp = 0; | ||
|
||
boolean operator==(GlobalVariables<NCT> const& other) const | ||
{ | ||
return chain_id == other.chain_id && version == other.version && block_number == other.block_number && | ||
timestamp == other.timestamp; | ||
}; | ||
|
||
template <typename Composer> GlobalVariables<CircuitTypes<Composer>> to_circuit_type(Composer& composer) const | ||
{ | ||
static_assert((std::is_same<NativeTypes, NCT>::value)); | ||
|
||
// Capture the composer: | ||
auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; | ||
auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; | ||
|
||
GlobalVariables<CircuitTypes<Composer>> globals = { | ||
to_ct(chain_id), | ||
to_ct(version), | ||
to_ct(block_number), | ||
to_ct(timestamp), | ||
}; | ||
|
||
return globals; | ||
}; | ||
|
||
fr hash() const | ||
{ | ||
std::vector<fr> inputs; | ||
inputs.push_back(chain_id); | ||
inputs.push_back(version); | ||
inputs.push_back(block_number); | ||
inputs.push_back(timestamp); | ||
|
||
return NCT::compress(inputs, GeneratorIndex::GLOBAL_VARIABLES); | ||
} | ||
}; | ||
|
||
template <typename NCT> void read(uint8_t const*& it, GlobalVariables<NCT>& globals) | ||
{ | ||
using serialize::read; | ||
|
||
read(it, globals.chain_id); | ||
read(it, globals.version); | ||
read(it, globals.block_number); | ||
read(it, globals.timestamp); | ||
}; | ||
|
||
template <typename NCT> void write(std::vector<uint8_t>& buf, GlobalVariables<NCT> const& globals) | ||
{ | ||
using serialize::write; | ||
|
||
write(buf, globals.chain_id); | ||
write(buf, globals.version); | ||
write(buf, globals.block_number); | ||
write(buf, globals.timestamp); | ||
}; | ||
|
||
template <typename NCT> std::ostream& operator<<(std::ostream& os, GlobalVariables<NCT> const& globals) | ||
{ | ||
return os << "chain_id: " << globals.chain_id << "\n" | ||
<< "version: " << globals.version << "\n" | ||
<< "block_number: " << globals.block_number << "\n" | ||
<< "timestamp: " << globals.timestamp << "\n"; | ||
} | ||
|
||
} // namespace aztec3::circuits::abis |
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
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
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.
can we rename
version
toaztecVersion
andchainId
tobaseChainID
to make it more clear what these are. Otherwise, especially for noir devs this will be super super confusingThere 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.
Technically they are both chainIds, so could also be
baseChainId
androllupChainId
🤷. Version mainly chosen just to be different tochainId
to make it clear it was not the same thing.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.
yea I am fine with baseChainId and rollupChainId!