Skip to content

Commit

Permalink
feat: rollup rework
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Sep 14, 2023
1 parent cb6f039 commit 51e9ef0
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 142 deletions.
2 changes: 1 addition & 1 deletion lib/grpc-interfaces
2 changes: 1 addition & 1 deletion lib/machine-emulator-defines
6 changes: 0 additions & 6 deletions src/cartesi-machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,6 @@ local options = {
rollup = rollup or {}
rollup.rx_buffer = { start = 0x60000000, length = 2 << 20 }
rollup.tx_buffer = { start = 0x60200000, length = 2 << 20 }
rollup.input_metadata = { start = 0x60400000, length = 4096 }
rollup.voucher_hashes = { start = 0x60600000, length = 2 << 20 }
rollup.notice_hashes = { start = 0x60800000, length = 2 << 20 }
htif_yield_automatic = true
htif_yield_manual = true
return true
Expand Down Expand Up @@ -1659,9 +1656,6 @@ else
assert(remote_address, "rollup requires --remote-address for snapshot/rollback")
check_rollup_memory_range_config(config.rollup.tx_buffer, "tx-buffer")
check_rollup_memory_range_config(config.rollup.rx_buffer, "rx-buffer")
check_rollup_memory_range_config(config.rollup.input_metadata, "input-metadata")
check_rollup_memory_range_config(config.rollup.voucher_hashes, "voucher-hashes")
check_rollup_memory_range_config(config.rollup.notice_hashes, "notice-hashes")
end
local cycles = machine:read_mcycle()
if initial_hash then
Expand Down
15 changes: 0 additions & 15 deletions src/clua-machine-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,12 +835,6 @@ static void push_cm_rollup_config(lua_State *L, const cm_rollup_config *r) {
lua_setfield(L, -2, "rx_buffer"); // rollup
push_cm_memory_range_config(L, &r->tx_buffer); // rollup tx_buffer
lua_setfield(L, -2, "tx_buffer"); // rollup
push_cm_memory_range_config(L, &r->input_metadata); // rollup input_metadata
lua_setfield(L, -2, "input_metadata"); // rollup
push_cm_memory_range_config(L, &r->voucher_hashes); // rollup voucher_hashes
lua_setfield(L, -2, "voucher_hashes"); // rollup
push_cm_memory_range_config(L, &r->notice_hashes); // rollup notice_hashes
lua_setfield(L, -2, "notice_hashes"); // rollup
}

/// \brief Pushes cm_flash_drive_configs to the Lua stack
Expand Down Expand Up @@ -982,15 +976,6 @@ static void check_cm_rollup_config(lua_State *L, int tabidx, cm_rollup_config *r
lua_pop(L, 1);
lua_getfield(L, -1, "tx_buffer");
clua_check_cm_memory_range_config(L, -1, "rollup rx buffer", &r->tx_buffer);
lua_pop(L, 1);
lua_getfield(L, -1, "input_metadata");
clua_check_cm_memory_range_config(L, -1, "rollup input metadata", &r->input_metadata);
lua_pop(L, 1);
lua_getfield(L, -1, "voucher_hashes");
clua_check_cm_memory_range_config(L, -1, "rollup voucher hashes", &r->voucher_hashes);
lua_pop(L, 1);
lua_getfield(L, -1, "notice_hashes");
clua_check_cm_memory_range_config(L, -1, "rollup notice hashes", &r->notice_hashes);
lua_pop(L, 2);
}

Expand Down
9 changes: 0 additions & 9 deletions src/json-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,6 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, rollup_config &valu
const auto new_path = path + to_string(key) + "/";
ju_get_field(jconfig, "rx_buffer"s, value.rx_buffer, new_path);
ju_get_field(jconfig, "tx_buffer"s, value.tx_buffer, new_path);
ju_get_field(jconfig, "input_metadata"s, value.input_metadata, new_path);
ju_get_field(jconfig, "voucher_hashes"s, value.voucher_hashes, new_path);
ju_get_field(jconfig, "notice_hashes"s, value.notice_hashes, new_path);
}

template void ju_get_opt_field<uint64_t>(const nlohmann::json &j, const uint64_t &key, rollup_config &value,
Expand All @@ -940,9 +937,6 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, std::optional<rollu
auto &value = optional.value();
ju_get_field(jconfig, "rx_buffer"s, value.rx_buffer, new_path);
ju_get_field(jconfig, "tx_buffer"s, value.tx_buffer, new_path);
ju_get_field(jconfig, "input_metadata"s, value.input_metadata, new_path);
ju_get_field(jconfig, "voucher_hashes"s, value.voucher_hashes, new_path);
ju_get_field(jconfig, "notice_hashes"s, value.notice_hashes, new_path);
}

template void ju_get_opt_field<uint64_t>(const nlohmann::json &j, const uint64_t &key,
Expand Down Expand Up @@ -1159,9 +1153,6 @@ void to_json(nlohmann::json &j, const rollup_config &config) {
j = nlohmann::json{
{"rx_buffer", config.rx_buffer},
{"tx_buffer", config.tx_buffer},
{"input_metadata", config.input_metadata},
{"voucher_hashes", config.voucher_hashes},
{"notice_hashes", config.notice_hashes},
};
}

Expand Down
9 changes: 1 addition & 8 deletions src/machine-c-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ static std::optional<cartesi::rollup_config> convert_from_c(const cm_rollup_conf
return {};
}
cartesi::rollup_config new_cpp_rollup_config{convert_from_c(&c_config->rx_buffer),
convert_from_c(&c_config->tx_buffer), convert_from_c(&c_config->input_metadata),
convert_from_c(&c_config->voucher_hashes), convert_from_c(&c_config->notice_hashes)};
convert_from_c(&c_config->tx_buffer)};
return new_cpp_rollup_config;
}

Expand All @@ -299,9 +298,6 @@ static cm_rollup_config convert_to_c(const std::optional<cartesi::rollup_config>
}
new_c_rollup_config.rx_buffer = convert_to_c(cpp_config->rx_buffer);
new_c_rollup_config.tx_buffer = convert_to_c(cpp_config->tx_buffer);
new_c_rollup_config.input_metadata = convert_to_c(cpp_config->input_metadata);
new_c_rollup_config.voucher_hashes = convert_to_c(cpp_config->voucher_hashes);
new_c_rollup_config.notice_hashes = convert_to_c(cpp_config->notice_hashes);
return new_c_rollup_config;
}

Expand Down Expand Up @@ -708,9 +704,6 @@ void cm_delete_machine_config(const cm_machine_config *config) {
delete[] config->tlb.image_filename;
delete[] config->rollup.rx_buffer.image_filename;
delete[] config->rollup.tx_buffer.image_filename;
delete[] config->rollup.input_metadata.image_filename;
delete[] config->rollup.voucher_hashes.image_filename;
delete[] config->rollup.notice_hashes.image_filename;
delete[] config->uarch.ram.image_filename;

delete config;
Expand Down
3 changes: 0 additions & 3 deletions src/machine-c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ typedef struct { // NOLINT(modernize-use-using)
bool has_value; ///< Represents whether the rest of the struct have been filled
cm_memory_range_config rx_buffer; ///< RX buffer memory range
cm_memory_range_config tx_buffer; ///< TX buffer memory range
cm_memory_range_config input_metadata; ///< Input metadata memory range
cm_memory_range_config voucher_hashes; ///< Voucher hashes memory range
cm_memory_range_config notice_hashes; ///< Notice hashes memory range
} cm_rollup_config;

/// \brief microarchitecture RAM configuration
Expand Down
3 changes: 0 additions & 3 deletions src/machine-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ static void adjust_image_filenames(machine_config &c, const std::string &dir) {
auto &r = c.rollup.value();
r.rx_buffer.image_filename = c.get_image_filename(dir, r.rx_buffer);
r.tx_buffer.image_filename = c.get_image_filename(dir, r.tx_buffer);
r.input_metadata.image_filename = c.get_image_filename(dir, r.input_metadata);
r.voucher_hashes.image_filename = c.get_image_filename(dir, r.voucher_hashes);
r.notice_hashes.image_filename = c.get_image_filename(dir, r.notice_hashes);
}

if (c.uarch.ram.length > 0) {
Expand Down
5 changes: 2 additions & 3 deletions src/machine-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ struct htif_config final {
struct rollup_config { // NOLINT(bugprone-exception-escape)
memory_range_config rx_buffer{}; ///< RX buffer
memory_range_config tx_buffer{}; ///< TX buffer
memory_range_config input_metadata{}; ///< Buffer for input metadata
memory_range_config voucher_hashes{}; ///< Buffer for the voucher hash array
memory_range_config notice_hashes{}; ///< Buffer for the notice hash array
memory_range_config hash_types{}; ///<
memory_range_config hash_values{}; ///<
};

/// \brief Machine state configuration
Expand Down
61 changes: 1 addition & 60 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,6 @@ const pma_entry::flags machine::m_rollup_tx_buffer_flags{
PMA_ISTART_DID::rollup_tx_buffer // DID
};

const pma_entry::flags machine::m_rollup_input_metadata_flags{
true, // R
false, // W
false, // X
true, // IR
true, // IW
PMA_ISTART_DID::rollup_input_metadata // DID
};

const pma_entry::flags machine::m_rollup_voucher_hashes_flags{
true, // R
true, // W
false, // X
true, // IR
true, // IW
PMA_ISTART_DID::rollup_voucher_hashes // DID
};

const pma_entry::flags machine::m_rollup_notice_hashes_flags{
true, // R
true, // W
false, // X
true, // IR
true, // IW
PMA_ISTART_DID::rollup_notice_hashes // DID
};

pma_entry machine::make_memory_range_pma_entry(const std::string &description, const memory_range_config &c) {
if (c.image_filename.empty()) {
return make_callocd_memory_pma_entry(description, c.start, c.length);
Expand All @@ -146,20 +119,6 @@ pma_entry machine::make_rollup_tx_buffer_pma_entry(const memory_range_config &c)
return make_memory_range_pma_entry("rollup tx buffer memory range"s, c).set_flags(m_rollup_tx_buffer_flags);
}

pma_entry machine::make_rollup_input_metadata_pma_entry(const memory_range_config &c) {
return make_memory_range_pma_entry("rollup input metadata memory range"s, c)
.set_flags(m_rollup_input_metadata_flags);
}

pma_entry machine::make_rollup_voucher_hashes_pma_entry(const memory_range_config &c) {
return make_memory_range_pma_entry("rollup voucher hashes memory range"s, c)
.set_flags(m_rollup_voucher_hashes_flags);
}

pma_entry machine::make_rollup_notice_hashes_pma_entry(const memory_range_config &c) {
return make_memory_range_pma_entry("rollup notice hashes memory range"s, c).set_flags(m_rollup_notice_hashes_flags);
}

pma_entry &machine::register_pma_entry(pma_entry &&pma) {
if (m_s.pmas.capacity() <= m_s.pmas.size()) { // NOLINT(readability-static-accessed-through-instance)
throw std::runtime_error{"too many PMAs when adding "s + pma.get_description()};
Expand Down Expand Up @@ -205,12 +164,6 @@ static bool DID_is_protected(PMA_ISTART_DID DID) {
return false;
case PMA_ISTART_DID::rollup_tx_buffer:
return false;
case PMA_ISTART_DID::rollup_input_metadata:
return false;
case PMA_ISTART_DID::rollup_voucher_hashes:
return false;
case PMA_ISTART_DID::rollup_notice_hashes:
return false;
default:
return true;
}
Expand Down Expand Up @@ -378,17 +331,11 @@ machine::machine(const machine_config &c, const machine_runtime_config &r) :
// Register rollup memory ranges
if (m_c.rollup.has_value()) {
if (m_c.rollup->rx_buffer.length == 0 || m_c.rollup->rx_buffer.start == 0 ||
m_c.rollup->tx_buffer.length == 0 || m_c.rollup->tx_buffer.start == 0 ||
m_c.rollup->input_metadata.length == 0 || m_c.rollup->input_metadata.start == 0 ||
m_c.rollup->voucher_hashes.length == 0 || m_c.rollup->voucher_hashes.start == 0 ||
m_c.rollup->notice_hashes.length == 0 || m_c.rollup->notice_hashes.start == 0) {
m_c.rollup->tx_buffer.length == 0 || m_c.rollup->tx_buffer.start == 0) {
throw std::invalid_argument{"incomplete rollup configuration"};
}
register_pma_entry(make_rollup_tx_buffer_pma_entry(m_c.rollup->tx_buffer));
register_pma_entry(make_rollup_rx_buffer_pma_entry(m_c.rollup->rx_buffer));
register_pma_entry(make_rollup_input_metadata_pma_entry(m_c.rollup->input_metadata));
register_pma_entry(make_rollup_voucher_hashes_pma_entry(m_c.rollup->voucher_hashes));
register_pma_entry(make_rollup_notice_hashes_pma_entry(m_c.rollup->notice_hashes));
}

// Register HTIF device
Expand Down Expand Up @@ -553,9 +500,6 @@ machine_config machine::get_serialization_config(void) const {
auto &r = c.rollup.value();
r.rx_buffer.image_filename.clear();
r.tx_buffer.image_filename.clear();
r.input_metadata.image_filename.clear();
r.voucher_hashes.image_filename.clear();
r.notice_hashes.image_filename.clear();
}
c.uarch.processor.cycle = read_uarch_cycle();
c.uarch.processor.halt_flag = read_uarch_halt_flag();
Expand Down Expand Up @@ -660,9 +604,6 @@ void machine::store_pmas(const machine_config &c, const std::string &dir) const
const auto &r = c.rollup.value();
store_memory_pma(find_pma_entry<uint64_t>(r.rx_buffer.start), dir);
store_memory_pma(find_pma_entry<uint64_t>(r.tx_buffer.start), dir);
store_memory_pma(find_pma_entry<uint64_t>(r.input_metadata.start), dir);
store_memory_pma(find_pma_entry<uint64_t>(r.voucher_hashes.start), dir);
store_memory_pma(find_pma_entry<uint64_t>(r.notice_hashes.start), dir);
}
if (!m_uarch.get_state().ram.get_istart_E()) {
store_memory_pma(m_uarch.get_state().ram, dir);
Expand Down
18 changes: 0 additions & 18 deletions src/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ class machine final {
static const pma_entry::flags m_flash_drive_flags; ///< PMA flags used for flash drives
static const pma_entry::flags m_rollup_rx_buffer_flags; ///< PMA flags used for rollup rx buffer
static const pma_entry::flags m_rollup_tx_buffer_flags; ///< PMA flags used for rollup tx buffer
static const pma_entry::flags m_rollup_input_metadata_flags; ///< PMA flags used for rollup input metadata
static const pma_entry::flags m_rollup_voucher_hashes_flags; ///< PMA flags used for rollup voucher hashes
static const pma_entry::flags m_rollup_notice_hashes_flags; ///< PMA flags used for rollup notice hashes

/// \brief Allocates a new PMA entry.
/// \param pma PMA entry to add to machine.
Expand Down Expand Up @@ -95,21 +92,6 @@ class machine final {
/// \returns New PMA entry with tx buffer flags already set.
static pma_entry make_rollup_tx_buffer_pma_entry(const memory_range_config &c);

/// \brief Creates a new rollup input metadata PMA entry.
/// \param c Memory range configuration.
/// \returns New PMA entry with rollup input metadata flags already set.
static pma_entry make_rollup_input_metadata_pma_entry(const memory_range_config &c);

/// \brief Creates a new rollup voucher hashes PMA entry.
/// \param c Memory range configuration.
/// \returns New PMA entry with rollup voucher hashes flags already set.
static pma_entry make_rollup_voucher_hashes_pma_entry(const memory_range_config &c);

/// \brief Creates a new rollup notice hahes PMA entry.
/// \param c Memory range configuration.
/// \returns New PMA entry with rollup notice hashes flags already set.
static pma_entry make_rollup_notice_hashes_pma_entry(const memory_range_config &c);

/// \brief Saves PMAs into files for serialization
/// \param config Machine config to be stored
/// \param directory Directory where PMAs will be stored
Expand Down
3 changes: 0 additions & 3 deletions src/pma-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ enum class PMA_ISTART_DID {
HTIF = PMA_HTIF_DID_DEF, ///< DID for HTIF device
rollup_rx_buffer = PMA_ROLLUP_RX_BUFFER_DID_DEF, ///< DID for rollup receive buffer
rollup_tx_buffer = PMA_ROLLUP_TX_BUFFER_DID_DEF, ///< DID for rollup transmit buffer
rollup_input_metadata = PMA_ROLLUP_INPUT_METADATA_DID_DEF, ///< DID for rollup input metadata memory range
rollup_voucher_hashes = PMA_ROLLUP_VOUCHER_HASHES_DID_DEF, ///< DID for rollup voucher hashes memory range
rollup_notice_hashes = PMA_ROLLUP_NOTICE_HASHES_DID_DEF, ///< DID for rollup notice hashes memory range
};

} // namespace cartesi
Expand Down
12 changes: 0 additions & 12 deletions src/protobuf-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ void set_proto_memory_range(const memory_range_config &m, CartesiMachine::Memory
void set_proto_rollup(const rollup_config &r, CartesiMachine::RollupConfig *proto_r) {
set_proto_memory_range(r.rx_buffer, proto_r->mutable_rx_buffer());
set_proto_memory_range(r.tx_buffer, proto_r->mutable_tx_buffer());
set_proto_memory_range(r.input_metadata, proto_r->mutable_input_metadata());
set_proto_memory_range(r.voucher_hashes, proto_r->mutable_voucher_hashes());
set_proto_memory_range(r.notice_hashes, proto_r->mutable_notice_hashes());
}

void set_proto_machine_config(const machine_config &c, CartesiMachine::MachineConfig *proto_c) {
Expand Down Expand Up @@ -793,15 +790,6 @@ rollup_config get_proto_rollup_config(const CartesiMachine::RollupConfig &proto_
if (proto_r.has_tx_buffer()) {
r.tx_buffer = get_proto_memory_range_config(proto_r.tx_buffer());
}
if (proto_r.has_input_metadata()) {
r.input_metadata = get_proto_memory_range_config(proto_r.input_metadata());
}
if (proto_r.has_voucher_hashes()) {
r.voucher_hashes = get_proto_memory_range_config(proto_r.voucher_hashes());
}
if (proto_r.has_input_metadata()) {
r.notice_hashes = get_proto_memory_range_config(proto_r.notice_hashes());
}
return r;
}

Expand Down

0 comments on commit 51e9ef0

Please sign in to comment.