Skip to content

Commit 0edd756

Browse files
committed
add metadata collection for tx-level reverts
1 parent 26f55a8 commit 0edd756

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/tx_execution.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,14 @@ TxExecutionResult TxExecution::simulate(const Tx& tx)
143143
try {
144144
// Insert revertibles. This can throw if there is a nullifier collision.
145145
// Such an exception should be handled and the tx be provable.
146-
insert_revertibles(tx);
146+
// We catch separately here to record the revert reason in call stack metadata,
147+
// since no calls have populated the metadata yet at this point.
148+
try {
149+
insert_revertibles(tx);
150+
} catch (const TxExecutionException& e) {
151+
call_stack_metadata_collector.notify_tx_revert(e.what());
152+
throw;
153+
}
147154

148155
// App logic.
149156
if (tx.app_logic_enqueued_calls.empty()) {

barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/call_stack_metadata_collector.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class CallStackMetadataCollectorInterface {
2727
const std::optional<std::string>& halting_message,
2828
const ReturnDataProvider& return_data_provider,
2929
const InternalCallStackProvider& internal_call_stack_provider) = 0;
30+
// Notify a tx-level revert that happened outside of an enqueued call (e.g., during revertible insertions).
31+
// This creates a synthetic CallStackMetadata entry to capture the revert reason.
32+
virtual void notify_tx_revert(const std::string& revert_message) = 0;
3033
virtual std::vector<CallStackMetadata> dump_call_stack_metadata() = 0;
3134
};
3235

barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ void CallStackMetadataCollector::notify_exit_call(bool success,
7474
call_stack_metadata.top().nested.push_back(std::move(top_call_stack_metadata));
7575
}
7676

77+
void CallStackMetadataCollector::notify_tx_revert(const std::string& revert_message)
78+
{
79+
// Create a synthetic CallStackMetadata entry to capture the revert reason.
80+
// This is used when a tx-level revert happens outside of an enqueued call
81+
// (e.g., during revertible insertions from private).
82+
assert(call_stack_metadata.size() == 1);
83+
call_stack_metadata.top().nested.push_back({
84+
.timestamp = timestamp++,
85+
.phase = current_phase,
86+
.contract_address = 0, // No specific contract
87+
.caller_pc = 0,
88+
.calldata = {},
89+
.is_static_call = false,
90+
.gas_limit = {},
91+
.output = {},
92+
.reverted = true,
93+
.nested = {},
94+
.internal_call_stack_at_exit = {},
95+
.halting_message = revert_message,
96+
.num_nested_calls = 0,
97+
});
98+
}
99+
77100
std::vector<CallStackMetadata> CallStackMetadataCollector::dump_call_stack_metadata()
78101
{
79102
assert(call_stack_metadata.size() == 1);

barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class CallStackMetadataCollector : public CallStackMetadataCollectorInterface {
2626
const std::optional<std::string>& halting_message,
2727
const ReturnDataProvider& return_data_provider,
2828
const InternalCallStackProvider& internal_call_stack_provider) override;
29+
void notify_tx_revert(const std::string& revert_message) override;
2930
std::vector<CallStackMetadata> dump_call_stack_metadata() override;
3031

3132
private:
@@ -56,6 +57,7 @@ class NoopCallStackMetadataCollector : public CallStackMetadataCollectorInterfac
5657
const ReturnDataProvider&,
5758
const InternalCallStackProvider&) override
5859
{}
60+
void notify_tx_revert(const std::string&) override {}
5961
std::vector<CallStackMetadata> dump_call_stack_metadata() override { return {}; }
6062
};
6163

barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_call_stack_metadata_collector.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MockCallStackMetadataCollector : public CallStackMetadataCollectorInterfac
2929
const ReturnDataProvider& return_data_provider,
3030
const InternalCallStackProvider& internal_call_stack_provider),
3131
(override));
32+
MOCK_METHOD(void, notify_tx_revert, (const std::string& revert_message), (override));
3233
MOCK_METHOD(std::vector<CallStackMetadata>, dump_call_stack_metadata, (), (override));
3334
};
3435

0 commit comments

Comments
 (0)