limit the number of instructions that can be evaluated (#2459)

* limit the number of instructions that can be evaluated

* code cleanup
This commit is contained in:
tyrelr 2023-05-04 12:46:11 -06:00 committed by GitHub
parent dc9e298bff
commit 39acaf1459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,6 +128,7 @@ const OP_HALT: &str = "Halt";
const OP_HALT_IF_NULL: &str = "HaltIfNull";
const MAX_LOOP_COUNT: u8 = 2;
const MAX_TOTAL_INSTRUCTION_COUNT: u32 = 100_000;
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
enum ColumnType {
@ -428,6 +429,7 @@ pub(super) fn explain(
let mut visited_branch_state: HashSet<BranchStateHash> = HashSet::new();
let mut gas = MAX_TOTAL_INSTRUCTION_COUNT;
let mut result_states = Vec::new();
while let Some(mut state) = states.pop() {
@ -435,6 +437,13 @@ pub(super) fn explain(
let (_, ref opcode, p1, p2, p3, ref p4) = program[state.program_i];
state.history.push(state.program_i);
//limit the number of 'instructions' that can be evaluated
if gas > 0 {
gas -= 1;
} else {
break;
}
if state.visited[state.program_i] > MAX_LOOP_COUNT {
if logger.log_enabled() {
let program_history: Vec<&(i64, String, i64, i64, i64, Vec<u8>)> =