-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Minimal globals in constant rollup data (#882)
* fix: move chainid into tx_context * chore: fix prettier * feat: add version to tx_context * feat: add global variables to ConstantRollupData * chore: fix prettier * feat: force chain_id and version match between kernel and globals * chore: fix tidy * feat: add block_number and timestamp * chore: update snapshots * feat: Add globals to root rollup public inputs * fix: update decoder * fix: update snapshots
- Loading branch information
Showing
33 changed files
with
576 additions
and
174 deletions.
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.