From ee1e8b96d996ea56368f1f9d7cffc21c5db3e70a Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Thu, 31 Aug 2023 14:57:22 -0300 Subject: [PATCH] feat: rollup rework --- lib/grpc-interfaces | 2 +- lib/machine-emulator-defines | 2 +- src/cartesi-machine.lua | 259 ++++++++++------------------------- src/clua-htif.cpp | 13 +- src/clua-machine-util.cpp | 15 -- src/dtb.cpp | 15 -- src/htif.h | 5 +- src/json-util.cpp | 9 -- src/jsonrpc-discover.json | 9 -- src/machine-c-api.cpp | 9 +- src/machine-c-api.h | 3 - src/machine-config.cpp | 3 - src/machine-config.h | 3 - src/machine.cpp | 61 +-------- src/machine.h | 18 --- src/pma-constants.h | 3 - src/protobuf-util.cpp | 12 -- 17 files changed, 83 insertions(+), 358 deletions(-) diff --git a/lib/grpc-interfaces b/lib/grpc-interfaces index 4ec6e6620..68b7d09dc 160000 --- a/lib/grpc-interfaces +++ b/lib/grpc-interfaces @@ -1 +1 @@ -Subproject commit 4ec6e6620abce44048b9a8493124683ef15e0731 +Subproject commit 68b7d09dca030370512b7b8b715a00ba1e1bf200 diff --git a/lib/machine-emulator-defines b/lib/machine-emulator-defines index c30dfb2bd..cc8020c30 160000 --- a/lib/machine-emulator-defines +++ b/lib/machine-emulator-defines @@ -1 +1 @@ -Subproject commit c30dfb2bdfe994396f3e6d8f173b197c1b39785c +Subproject commit cc8020c301d09a0fd12a8490edfa3e89cc764897 diff --git a/src/cartesi-machine.lua b/src/cartesi-machine.lua index d07840464..4a68c7d2a 100755 --- a/src/cartesi-machine.lua +++ b/src/cartesi-machine.lua @@ -139,9 +139,6 @@ where options are: --rollup-rx-buffer=:[,:[,...]...] --rollup-tx-buffer=:[,:[,...]...] - --rollup-input-metadata=:[,:[,...]...] - --rollup-voucher-hashes=:[,:[,...]...] - --rollup-notice-hashes=:[,:[,...]...] defines the individual the memory ranges used by rollups. : is one of @@ -161,9 +158,6 @@ where options are: --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-manual --htif-yield-automatic @@ -171,24 +165,15 @@ where options are: advances the state of the machine through a number of inputs in an epoch : is one of - epoch_index: input: - input_metadata: input_index_begin: input_index_end: - voucher: - voucher_hashes: - notice: - notice_hashes: - report: + output: + outputs_root_hash: hashes - epoch_index - the index of the epoch (the value of %%e). - - input (default: "epoch-%%e-input-%%i.bin") - the pattern that derives the name of the file read for input %%i - of epoch index %%e. + input (default: "input-%%i.bin") + the pattern that derives the name of the file read for input %%i. input_index_begin (default: 0) index of first input to advance (the first value of %%i). @@ -196,36 +181,19 @@ where options are: input_index_end (default: 0) one past index of last input to advance (one past last value of %%i). - input_metadata (default: "epoch-%%e-input-metadata-%%i.bin") - the pattern that derives the name of the file read for - input metadata %%i of epoch index %%e. - - voucher (default: "epoch-%%e-input-%%i-voucher-%%o.bin") - the pattern that derives the name of the file written for voucher %%o - of input %%i of epoch %%e. - - voucher_hashes (default: "epoch-%%e-input-%%i-voucher-hashes.bin") - the pattern that derives the name of the file written for the voucher - hashes of input %%i of epoch %%e. + output (default: "input-%%i-output-%%o.bin") + the pattern that derives the name of the file written for output %%o + of input %%i. - notice (default: "epoch-%%e-input-%%i-notice-%%o.bin") - the pattern that derives the name of the file written for notice %%o - of input %%i of epoch %%e. - - notice_hashes (default: "epoch-%%e-input-%%i-notice-hashes.bin") - the pattern that derives the name of the file written for the notice - hashes of input %%i of epoch %%e. - - report (default: "epoch-%%e-input-%%i-report-%%o.bin") - the pattern that derives the name of the file written for report %%o - of input %%i of epoch %%e. + outputs_root_hash (default: "input-%%i-outputs-root-hash.bin") + the pattern that derives the name of the file written for outputs root + hash of input %%i. hashes print out hashes before every input. - the input index ranges in {input_index_begin, ..., input_index_end-1}. - for each input, "%%e" is replaced by the epoch index, "%%i" by the - input index, and "%%o" by the voucher, notice, or report index. + the input index ranges in {input_index_begin, ..., input_index_end-1}. for + each input, "%%i" by the input index, and "%%o" by the output index. --rollup-inspect-state=:[,:[,...]...] inspect the state of the machine with a query. @@ -242,7 +210,7 @@ where options are: the pattern that derives the name of the file written for report %%o of the query. - while the query is processed, "%%o" is replaced by the current report index. + while the query is processed, "%%o" is replaced by the current output index. --concurrency=:[,:[,...]...] configures the number of threads used in some implementation parts. @@ -629,9 +597,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 @@ -688,32 +653,23 @@ local options = { function(all, opts) if not opts then return false end local r = util.parse_options(opts, { - epoch_index = true, input = true, - input_metadata = true, input_index_begin = true, input_index_end = true, - voucher = true, - voucher_hashes = true, - notice = true, - notice_hashes = true, - report = true, + output = true, + outputs_root_hash = true, hashes = true, }) assert(not r.hashes or r.hashes == true, "invalid hashes value in " .. all) - r.epoch_index = assert(util.parse_number(r.epoch_index), "invalid epoch index in " .. all) - r.input = r.input or "epoch-%e-input-%i.bin" - r.input_metadata = r.input_metadata or "epoch-%e-input-metadata-%i.bin" + r.input = r.input or "input-%i.bin" r.input_index_begin = r.input_index_begin or 0 r.input_index_begin = assert(util.parse_number(r.input_index_begin), "invalid input index begin in " .. all) r.input_index_end = r.input_index_end or 0 r.input_index_end = assert(util.parse_number(r.input_index_end), "invalid input index end in " .. all) - r.voucher = r.voucher or "epoch-%e-input-%i-voucher-%o.bin" - r.voucher_hashes = r.voucher_hashes or "epoch-%e-input-%i-voucher-hashes.bin" - r.notice = r.notice or "epoch-%e-input-%i-notice-%o.bin" - r.notice_hashes = r.notice_hashes or "epoch-%e-input-%i-notice-hashes.bin" - r.report = r.report or "epoch-%e-input-%i-report-%o.bin" + r.output = r.output or "input-%i-output-%o.bin" + r.outputs_root_hash = r.outputs_root_hash or "input-%i-outputs-root-hash.bin" r.next_input_index = r.input_index_begin + r.output_index = 0 rollup_advance = r return true end, @@ -1029,33 +985,6 @@ local options = { return true end, }, - { - "^(%-%-rollup%-input%-metadata%=(.+))$", - function(all, opts) - if not opts then return false end - rollup = rollup or {} - rollup.input_metadata = parse_memory_range(opts, "rollup input metadata", all) - return true - end, - }, - { - "^(%-%-rollup%-voucher%-hashes%=(.+))$", - function(all, opts) - if not opts then return false end - rollup = rollup or {} - rollup.voucher_hashes = parse_memory_range(opts, "rollup voucher hashes", all) - return true - end, - }, - { - "^(%-%-rollup%-notice%-hashes%=(.+))$", - function(all, opts) - if not opts then return false end - rollup = rollup or {} - rollup.notice_hashes = parse_memory_range(opts, "rollup notice hashes", all) - return true - end, - }, { "^%-%-gdb(%=?)(.*)$", function(o, address) @@ -1204,12 +1133,6 @@ local function store_machine_config(config, output) store_memory_range(config.rollup.rx_buffer, " ", output) output(" tx_buffer = ") store_memory_range(config.rollup.tx_buffer, " ", output) - output(" input_metadata = ") - store_memory_range(config.rollup.input_metadata, " ", output) - output(" voucher_hashes = ") - store_memory_range(config.rollup.voucher_hashes, " ", output) - output(" notice_hashes = ") - store_memory_range(config.rollup.notice_hashes, " ", output) output(" },\n") end output(" uarch = {\n") @@ -1412,9 +1335,8 @@ local htif_yield_reason = { [cartesi.machine.HTIF_YIELD_REASON_PROGRESS] = "progress", [cartesi.machine.HTIF_YIELD_REASON_RX_ACCEPTED] = "rx-accepted", [cartesi.machine.HTIF_YIELD_REASON_RX_REJECTED] = "rx-rejected", - [cartesi.machine.HTIF_YIELD_REASON_TX_VOUCHER] = "tx-voucher", - [cartesi.machine.HTIF_YIELD_REASON_TX_NOTICE] = "tx-notice", - [cartesi.machine.HTIF_YIELD_REASON_TX_REPORT] = "tx-report", + [cartesi.machine.HTIF_YIELD_REASON_TX_OUTPUT] = "tx-output", + [cartesi.machine.HTIF_YIELD_REASON_TX_VERIFIABLE_OUTPUT] = "tx-verifiable-output", [cartesi.machine.HTIF_YIELD_REASON_TX_EXCEPTION] = "tx-exception", } @@ -1458,11 +1380,15 @@ local function check_rollup_htif_config(htif) assert(htif.yield_automatic, "yield automatic must be enabled for rollup") end +local function set_yield_data(machine, reason, data) + machine:write_htif_fromhost_data(((reason & 0xffff) << 32) | (data & 0xffffff)) +end + local function get_yield(machine) local cmd = machine:read_htif_tohost_cmd() local data = machine:read_htif_tohost_data() local reason = data >> 32 - return cmd, reason, data + return cmd, (reason & 0xffff), (data & 0xffffffff) end local function get_and_print_yield(machine, htif) @@ -1501,28 +1427,19 @@ local function instantiate_filename(pattern, values) return (string.gsub(pattern, "\0", "%")) end -local function save_rollup_voucher_and_notice_hashes(machine, config, advance) - local values = { e = advance.epoch_index, i = advance.next_input_index - 1 } - save_rollup_hashes(machine, config.voucher_hashes, instantiate_filename(advance.voucher_hashes, values)) - save_rollup_hashes(machine, config.notice_hashes, instantiate_filename(advance.notice_hashes, values)) -end - local function load_memory_range(machine, config, filename) stderr("Loading %s\n", filename) local f = assert(io.open(filename, "rb")) local s = assert(f:read("*a")) f:close() machine:write_memory(config.start, s) + return #s end -local function load_rollup_input_and_metadata(machine, config, advance) +local function load_rollup_input(machine, config, advance) local values = { e = advance.epoch_index, i = advance.next_input_index } - machine:replace_memory_range(config.input_metadata) -- clear - load_memory_range(machine, config.input_metadata, instantiate_filename(advance.input_metadata, values)) machine:replace_memory_range(config.rx_buffer) -- clear - load_memory_range(machine, config.rx_buffer, instantiate_filename(advance.input, values)) - machine:replace_memory_range(config.voucher_hashes) -- clear - machine:replace_memory_range(config.notice_hashes) -- clear + return load_memory_range(machine, config.rx_buffer, instantiate_filename(advance.input, values)) end local function load_rollup_query(machine, config, inspect) @@ -1530,55 +1447,30 @@ local function load_rollup_query(machine, config, inspect) load_memory_range(machine, config.rx_buffer, inspect.query) -- load query payload end -local function save_rollup_advance_state_voucher(machine, config, advance) - local values = { e = advance.epoch_index, i = advance.next_input_index - 1, o = advance.voucher_index } - local name = instantiate_filename(advance.voucher, values) +local function save_rollup_state_output_with_format(machine, config, advance, length, format) + local values = { e = advance.epoch_index, i = advance.next_input_index - 1, o = advance.output_index } + local name = instantiate_filename(format, values) stderr("Storing %s\n", name) local f = assert(io.open(name, "wb")) - -- skip address and offset to reach payload length - local length = string.unpack(">I8", machine:read_memory(config.start + 3 * 32 - 8, 8)) - -- add address, offset, and payload length to amount to be read - length = length + 3 * 32 assert(f:write(machine:read_memory(config.start, length))) f:close() end -local function save_rollup_advance_state_notice(machine, config, advance) - local values = { e = advance.epoch_index, i = advance.next_input_index - 1, o = advance.notice_index } - local name = instantiate_filename(advance.notice, values) - stderr("Storing %s\n", name) - local f = assert(io.open(name, "wb")) - -- skip offset to reach payload length - local length = string.unpack(">I8", machine:read_memory(config.start + 2 * 32 - 8, 8)) - -- add offset and payload length to amount to be read - length = length + 2 * 32 - assert(f:write(machine:read_memory(config.start, length))) - f:close() +local function save_rollup_state_output(machine, config, advance, length) + return save_rollup_state_output_with_format(machine, config, advance, length, advance.output) end -local function dump_exception(machine, config) - -- skip offset to reach payload length - local length = string.unpack(">I8", machine:read_memory(config.start + 2 * 32 - 8, 8)) - -- add offset and payload length to amount to be read - local payload = machine:read_memory(config.start + 2 * 32, length) - stderr("Rollup exception with payload: %q\n", payload) +local function save_rollup_state_outputs_root_hash(machine, config, advance, length) + return save_rollup_state_output_with_format(machine, config, advance, length, advance.outputs_root_hash) end -local function save_rollup_advance_state_report(machine, config, advance) - local values = { e = advance.epoch_index, i = advance.next_input_index - 1, o = advance.report_index } - local name = instantiate_filename(advance.report, values) - stderr("Storing %s\n", name) - local f = assert(io.open(name, "wb")) - -- skip offset to reach payload length - local length = string.unpack(">I8", machine:read_memory(config.start + 2 * 32 - 8, 8)) - -- add offset and payload length to amount to be read - length = length + 2 * 32 - assert(f:write(machine:read_memory(config.start, length))) - f:close() +local function dump_exception(machine, config, length) + local payload = machine:read_memory(config.start, length) + stderr("Rollup exception with payload: %q\n", payload) end local function save_rollup_inspect_state_report(machine, config, inspect) - local values = { o = inspect.report_index } + local values = { o = inspect.output_index } local name = instantiate_filename(inspect.report, values) stderr("Storing %s\n", name) local f = assert(io.open(name, "wb")) @@ -1656,9 +1548,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 @@ -1705,70 +1594,62 @@ else break -- deal with yield manual elseif machine:read_iflags_Y() then - local _, reason = get_and_print_yield(machine, config.htif) + local _, reason, output_length = get_and_print_yield(machine, config.htif) -- there are advance state inputs to feed if reason == cartesi.machine.HTIF_YIELD_REASON_TX_EXCEPTION then - dump_exception(machine, config.rollup.tx_buffer) + dump_exception(machine, config.rollup.tx_buffer, output_length) exit_code = 1 - elseif rollup_advance and rollup_advance.next_input_index < rollup_advance.input_index_end then - -- save only if we have already run an input - if rollup_advance.next_input_index > rollup_advance.input_index_begin then - save_rollup_voucher_and_notice_hashes(machine, config.rollup, rollup_advance) - end - if reason == cartesi.machine.HTIF_YIELD_REASON_RX_REJECTED then - machine:rollback() - cycles = machine:read_mcycle() - else - assert(reason == cartesi.machine.HTIF_YIELD_REASON_RX_ACCEPTED, "invalid manual yield reason") + break + elseif reason == cartesi.machine.HTIF_YIELD_REASON_RX_REJECTED then + machine:rollback() + cycles = machine:read_mcycle() + else + assert(reason == cartesi.machine.HTIF_YIELD_REASON_RX_ACCEPTED, "invalid manual yield reason") + + -- extract ouput_hash, skip first yield + if rollup_advance and rollup_advance.next_input_index ~= 0 then + assert(output_length == 32) + save_rollup_state_outputs_root_hash(machine, config.rollup.tx_buffer, rollup_advance, output_length) end - stderr("\nEpoch %d before input %d\n", rollup_advance.epoch_index, rollup_advance.next_input_index) + end + if rollup_advance and rollup_advance.next_input_index < rollup_advance.input_index_end then if rollup_advance.hashes then print_root_hash(machine) end machine:snapshot() - load_rollup_input_and_metadata(machine, config.rollup, rollup_advance) + local input_length = load_rollup_input(machine, config.rollup, rollup_advance) if rollup_advance.hashes then print_root_hash(machine) end machine:reset_iflags_Y() - machine:write_htif_fromhost_data(0) -- tell machine it is an rollup_advance state, but this is default - rollup_advance.voucher_index = 0 - rollup_advance.notice_index = 0 - rollup_advance.report_index = 0 + set_yield_data(machine, cartesi.machine.HTIF_YIELD_REASON_ADVANCE_STATE, input_length) + rollup_advance.output_index = 0 rollup_advance.next_input_index = rollup_advance.next_input_index + 1 else - -- there are outputs of a prevous advance state to save - if rollup_advance and rollup_advance.next_input_index > rollup_advance.input_index_begin then - save_rollup_voucher_and_notice_hashes(machine, config.rollup, rollup_advance) - end -- there is an inspect state query to feed if rollup_inspect and rollup_inspect.query then stderr("\nBefore query\n") - load_rollup_query(machine, config.rollup, rollup_inspect) + local input_length = load_rollup_query(machine, config.rollup, rollup_inspect) machine:reset_iflags_Y() - machine:write_htif_fromhost_data(1) -- tell machine it is an inspect state - rollup_inspect.report_index = 0 + set_yield_data(machine, cartesi.machine.HTIF_YIELD_REASON_INSPECT_STATE, input_length) rollup_inspect.query = nil rollup_advance = nil end end -- deal with yield automatic elseif machine:read_iflags_X() then - local _, reason = get_and_print_yield(machine, config.htif) + local _, reason, length = get_and_print_yield(machine, config.htif) -- we have fed an advance state input if rollup_advance and rollup_advance.next_input_index > rollup_advance.input_index_begin then - if reason == cartesi.machine.HTIF_YIELD_REASON_TX_VOUCHER then - save_rollup_advance_state_voucher(machine, config.rollup.tx_buffer, rollup_advance) - rollup_advance.voucher_index = rollup_advance.voucher_index + 1 - elseif reason == cartesi.machine.HTIF_YIELD_REASON_TX_NOTICE then - save_rollup_advance_state_notice(machine, config.rollup.tx_buffer, rollup_advance) - rollup_advance.notice_index = rollup_advance.notice_index + 1 - elseif reason == cartesi.machine.HTIF_YIELD_REASON_TX_REPORT then - save_rollup_advance_state_report(machine, config.rollup.tx_buffer, rollup_advance) - rollup_advance.report_index = rollup_advance.report_index + 1 + if reason == cartesi.machine.HTIF_YIELD_REASON_TX_OUTPUT then + save_rollup_state_output(machine, config.rollup.tx_buffer, rollup_advance, length) + rollup_advance.output_index = rollup_advance.output_index + 1 + elseif reason == cartesi.machine.HTIF_YIELD_REASON_TX_VERIFIABLE_OUTPUT then + save_rollup_state_output(machine, config.rollup.tx_buffer, rollup_advance, length) + rollup_advance.output_index = rollup_advance.output_index + 1 end -- ignore other reasons -- we have feed the inspect state query elseif rollup_inspect and not rollup_inspect.query then - if reason == cartesi.machine.HTIF_YIELD_REASON_TX_REPORT then - save_rollup_inspect_state_report(machine, config.rollup.tx_buffer, rollup_inspect) - rollup_inspect.report_index = rollup_inspect.report_index + 1 + if reason == cartesi.machine.HTIF_YIELD_REASON_TX_OUTPUT then + save_rollup_state_output(machine, config.rollup.tx_buffer, rollup_inspect, length) + rollup_inspect.output_index = rollup_inspect.output_index + 1 end -- ignore other reasons end diff --git a/src/clua-htif.cpp b/src/clua-htif.cpp index 18f4b3b56..4a634564b 100644 --- a/src/clua-htif.cpp +++ b/src/clua-htif.cpp @@ -34,14 +34,15 @@ int clua_htif_export(lua_State *L, int ctxidx) { named_constant{HTIF_YIELD_AUTOMATIC, "HTIF_YIELD_AUTOMATIC"}, named_constant{HTIF_YIELD_MANUAL, "HTIF_YIELD_MANUAL"}, named_constant{HTIF_YIELD_REASON_PROGRESS, "HTIF_YIELD_REASON_PROGRESS"}, - named_constant{HTIF_YIELD_REASON_RX_ACCEPTED, "HTIF_YIELD_REASON_RX_ACCEPTED"}, - named_constant{HTIF_YIELD_REASON_RX_REJECTED, "HTIF_YIELD_REASON_RX_REJECTED"}, - named_constant{HTIF_YIELD_REASON_TX_VOUCHER, "HTIF_YIELD_REASON_TX_VOUCHER"}, - named_constant{HTIF_YIELD_REASON_TX_NOTICE, "HTIF_YIELD_REASON_TX_NOTICE"}, - named_constant{HTIF_YIELD_REASON_TX_REPORT, "HTIF_YIELD_REASON_TX_REPORT"}, - named_constant{HTIF_YIELD_REASON_TX_EXCEPTION, "HTIF_YIELD_REASON_TX_EXCEPTION"}, + named_constant{HTIF_YIELD_REASON_RX_ACCEPTED_DEF, "HTIF_YIELD_REASON_RX_ACCEPTED"}, + named_constant{HTIF_YIELD_REASON_RX_REJECTED_DEF, "HTIF_YIELD_REASON_RX_REJECTED"}, + named_constant{HTIF_YIELD_REASON_TX_OUTPUT_DEF, "HTIF_YIELD_REASON_TX_OUTPUT"}, + named_constant{HTIF_YIELD_REASON_TX_VERIFIABLE_OUTPUT_DEF, "HTIF_YIELD_REASON_TX_VERIFIABLE_OUTPUT"}, + named_constant{HTIF_YIELD_REASON_TX_EXCEPTION_DEF, "HTIF_YIELD_REASON_TX_EXCEPTION"}, named_constant{HTIF_CONSOLE_GETCHAR, "HTIF_CONSOLE_GETCHAR"}, named_constant{HTIF_CONSOLE_PUTCHAR, "HTIF_CONSOLE_PUTCHAR"}, + named_constant{HTIF_YIELD_REASON_ADVANCE_STATE_DEF, "HTIF_YIELD_REASON_ADVANCE_STATE"}, + named_constant{HTIF_YIELD_REASON_INSPECT_STATE_DEF, "HTIF_YIELD_REASON_INSPECT_STATE"}, }; for (const auto &c : constants) { lua_pushinteger(L, static_cast(c.value)); diff --git a/src/clua-machine-util.cpp b/src/clua-machine-util.cpp index 76c3ff26e..17361bc5b 100644 --- a/src/clua-machine-util.cpp +++ b/src/clua-machine-util.cpp @@ -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 @@ -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); } diff --git a/src/dtb.cpp b/src/dtb.cpp index c66b408da..6a0086e28 100644 --- a/src/dtb.cpp +++ b/src/dtb.cpp @@ -168,21 +168,6 @@ void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_le fdt.prop_u64_list<2>("reg", {r.tx_buffer.start, r.tx_buffer.length}); fdt.end_node(); } - { // input_metadata - fdt.begin_node_num("input_metadata", r.input_metadata.start); - fdt.prop_u64_list<2>("reg", {r.input_metadata.start, r.input_metadata.length}); - fdt.end_node(); - } - { // voucher_hashes - fdt.begin_node_num("voucher_hashes", r.voucher_hashes.start); - fdt.prop_u64_list<2>("reg", {r.voucher_hashes.start, r.voucher_hashes.length}); - fdt.end_node(); - } - { // notice_hashes - fdt.begin_node_num("notice_hashes", r.notice_hashes.start); - fdt.prop_u64_list<2>("reg", {r.notice_hashes.start, r.notice_hashes.length}); - fdt.end_node(); - } fdt.end_node(); } diff --git a/src/htif.h b/src/htif.h index bcc4eec8b..05d0eab6a 100644 --- a/src/htif.h +++ b/src/htif.h @@ -88,9 +88,8 @@ enum HTIF_yield_reason : uint64_t { HTIF_YIELD_REASON_PROGRESS = HTIF_YIELD_REASON_PROGRESS_DEF, HTIF_YIELD_REASON_RX_ACCEPTED = HTIF_YIELD_REASON_RX_ACCEPTED_DEF, HTIF_YIELD_REASON_RX_REJECTED = HTIF_YIELD_REASON_RX_REJECTED_DEF, - HTIF_YIELD_REASON_TX_VOUCHER = HTIF_YIELD_REASON_TX_VOUCHER_DEF, - HTIF_YIELD_REASON_TX_NOTICE = HTIF_YIELD_REASON_TX_NOTICE_DEF, - HTIF_YIELD_REASON_TX_REPORT = HTIF_YIELD_REASON_TX_REPORT_DEF, + HTIF_YIELD_REASON_TX_OUTPUT = HTIF_YIELD_REASON_TX_OUTPUT_DEF, + HTIF_YIELD_REASON_TX_VERIFIABLE_OUTPUT = HTIF_YIELD_REASON_TX_VERIFIABLE_OUTPUT_DEF, HTIF_YIELD_REASON_TX_EXCEPTION = HTIF_YIELD_REASON_TX_EXCEPTION_DEF, }; /// \brief Mapping between CSRs and their relative addresses in HTIF memory diff --git a/src/json-util.cpp b/src/json-util.cpp index e4ebd1215..be111cd7d 100644 --- a/src/json-util.cpp +++ b/src/json-util.cpp @@ -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(const nlohmann::json &j, const uint64_t &key, rollup_config &value, @@ -940,9 +937,6 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, std::optional(const nlohmann::json &j, const uint64_t &key, @@ -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}, }; } diff --git a/src/jsonrpc-discover.json b/src/jsonrpc-discover.json index d13236f2b..c82063209 100644 --- a/src/jsonrpc-discover.json +++ b/src/jsonrpc-discover.json @@ -1584,15 +1584,6 @@ }, "tx_buffer": { "$ref": "#/components/schemas/MemoryRangeConfig" - }, - "input_metadata": { - "$ref": "#/components/schemas/MemoryRangeConfig" - }, - "voucher_hashes": { - "$ref": "#/components/schemas/MemoryRangeConfig" - }, - "notice_hashes": { - "$ref": "#/components/schemas/MemoryRangeConfig" } } }, diff --git a/src/machine-c-api.cpp b/src/machine-c-api.cpp index 0808d5b7b..c0251f2af 100644 --- a/src/machine-c-api.cpp +++ b/src/machine-c-api.cpp @@ -286,8 +286,7 @@ static std::optional 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; } @@ -299,9 +298,6 @@ static cm_rollup_config convert_to_c(const std::optional } 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; } @@ -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; diff --git a/src/machine-c-api.h b/src/machine-c-api.h index 7c411e89f..61d570505 100644 --- a/src/machine-c-api.h +++ b/src/machine-c-api.h @@ -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 diff --git a/src/machine-config.cpp b/src/machine-config.cpp index 2eac08c05..7326f0cb9 100644 --- a/src/machine-config.cpp +++ b/src/machine-config.cpp @@ -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) { diff --git a/src/machine-config.h b/src/machine-config.h index c05986fcd..aad75fda9 100644 --- a/src/machine-config.h +++ b/src/machine-config.h @@ -118,9 +118,6 @@ 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 }; /// \brief Machine state configuration diff --git a/src/machine.cpp b/src/machine.cpp index c48271340..7177785f4 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -103,33 +103,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); @@ -149,20 +122,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()}; @@ -208,12 +167,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; } @@ -381,17 +334,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 @@ -559,9 +506,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(); @@ -666,9 +610,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(r.rx_buffer.start), dir); store_memory_pma(find_pma_entry(r.tx_buffer.start), dir); - store_memory_pma(find_pma_entry(r.input_metadata.start), dir); - store_memory_pma(find_pma_entry(r.voucher_hashes.start), dir); - store_memory_pma(find_pma_entry(r.notice_hashes.start), dir); } if (!m_uarch.get_state().ram.get_istart_E()) { store_memory_pma(m_uarch.get_state().ram, dir); diff --git a/src/machine.h b/src/machine.h index b2d1cb0df..a101ab924 100644 --- a/src/machine.h +++ b/src/machine.h @@ -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. @@ -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 diff --git a/src/pma-constants.h b/src/pma-constants.h index 06e5a05d1..b238fdff5 100644 --- a/src/pma-constants.h +++ b/src/pma-constants.h @@ -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 diff --git a/src/protobuf-util.cpp b/src/protobuf-util.cpp index ba22f7818..9d25e824a 100644 --- a/src/protobuf-util.cpp +++ b/src/protobuf-util.cpp @@ -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) { @@ -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; }