Skip to content

Commit

Permalink
Merge pull request #583 from 0xPolygonHermez/fractasy_report_gasprice…
Browse files Browse the repository at this point in the history
…_and_balance_opcodes

Report GASPRICE and BALANCE opcodes usage in ProcessBatch() response
  • Loading branch information
fractasy authored Sep 20, 2023
2 parents 7aabb6d + 18d23b7 commit 1382d73
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 160 deletions.
365 changes: 207 additions & 158 deletions src/grpc/gen/executor.pb.cc

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions src/grpc/gen/executor.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/grpc/proto/executor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ message ProcessTransactionResponse {
// Efective Gas Price
string effective_gas_price = 15;
uint32 effective_percentage = 16;
// Flag to indicate if opcode 'GASPRICE' has been called
uint32 has_gasprice_opcode = 17;
// Flag to indicate if opcode 'BALANCE' has been called
uint32 has_balance_opcode = 18;
}

message Log {
Expand Down
16 changes: 16 additions & 0 deletions src/main_sm/fork_5/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,10 @@ zkresult FullTracer::onFinishTx(Context &ctx, const RomCommand &cmd)
finalTrace.responses[finalTrace.responses.size() - 1].error = "";
}

// set flags has_gasprice_opcode and has_balance_opcode
finalTrace.responses[finalTrace.responses.size() - 1].has_gasprice_opcode = hasGaspriceOpcode;
finalTrace.responses[finalTrace.responses.size() - 1].has_balance_opcode = hasBalanceOpcode;

// Order all logs (from all CTX) in order of index
map<uint64_t, Log> auxLogs;
map<uint64_t, map<uint64_t, Log>>::iterator logIt;
Expand Down Expand Up @@ -1804,6 +1808,18 @@ zkresult FullTracer::onOpcode(Context &ctx, const RomCommand &cmd)
codeId = opcodeInfo[codeId].codeID;
singleInfo.op = codeId;

// set flag 'has_gasprice_opcode' if opcode is GASPRICE
if (codeId == 0x3a /*GASPRICE*/)
{
hasGaspriceOpcode = true;
}

// set flag 'has_balance_opcode' if opcode is BALANCE
if (codeId == 0x31 /*BALANCE*/)
{
hasBalanceOpcode = true;
}

// Check depth changes and update depth
singleInfo.depth = depth;

Expand Down
4 changes: 3 additions & 1 deletion src/main_sm/fork_5/main/full_tracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class FullTracer: public FullTracerInterface
ReturnFromCreate returnFromCreate;
unordered_map<uint64_t, ContextData> callData;
string previousMemory;
bool hasGaspriceOpcode;
bool hasBalanceOpcode;
#ifdef LOG_TIME_STATISTICS
TimeMetricStorage tms;
struct timeval t;
Expand Down Expand Up @@ -75,7 +77,7 @@ class FullTracer: public FullTracerInterface
const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7,
const mpz_class &value );

FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txCount(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0) { };
FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txCount(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0), hasGaspriceOpcode(false), hasBalanceOpcode(false) { };
~FullTracer()
{
#ifdef LOG_TIME_STATISTICS
Expand Down
4 changes: 3 additions & 1 deletion src/prover/full_tracer_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class Response
vector<Opcode> execution_trace;
string effective_gas_price;
uint32_t effective_percentage;
Response() : type(0), gas_left(0), gas_used(0), gas_refunded(0), effective_percentage(0) {};
bool has_gasprice_opcode;
bool has_balance_opcode;
Response() : type(0), gas_left(0), gas_used(0), gas_refunded(0), effective_percentage(0), has_gasprice_opcode(false), has_balance_opcode(false) {};
};

class FinalTrace
Expand Down

0 comments on commit 1382d73

Please sign in to comment.