-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add op counter #24
feat: add op counter #24
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sslivkoff what should opcode_gas
the total gas cost per opcode * count?
@mattsse does it look good to you ? |
I was thinking of mapping each opcode to its constant gas value. Then, when the final opcode result is mapped, I would simply multiply the constant gas by the number of repetitions of that opcode. but this implementation seems inefficient, doesn't it ? |
or it may be some funciton that can calculate the gas?
i tried to use the look up table from revm but it doesn't work it return for some opcode gas 0 and for some good value and for others false value fn step(&mut self, interp: &mut Interpreter, _context: &mut EvmContext<DB>) {
let opcode_val = interp.current_opcode();
let opcode =
OpCode::new(opcode_val).unwrap_or_else(|| unsafe { OpCode::new_unchecked(opcode_val) });
*self.opcode_counts.entry(opcode).or_insert(0) += 1;
let spec_id = revm::primitives::specification::SpecId::SHANGHAI;
let gas_info =
revm::interpreter::instructions::opcode::spec_opcode_gas(spec_id)[opcode_val as usize];
let opcode_gas = gas_info.get_gas() as u64;
*self.opcode_gas.entry(opcode).or_insert(0) += opcode_gas;
}
}``` |
afaui the same op-code can cost different amounts of gas depending on context and depending on input arguments so ideally it would be the sum of each opcode ocurrence but this would not be a simple multiplication |
there's also a bit of complication on contract calls returning whatever amount of spare unused gas they do not use ideally want a situation where the sum of opcode gas entries equals the total amount of gas used by the transaction might need to do some interesting nested gas accounting to make this happen given the various types of gas refunds |
let's also make the fields pub so they can be consumed easily |
no problem! |
@mattsse does it look goods to you ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I few nits,
this could also use a helper function that returns an iterator over all opcodes and their count+gas (opcode, (u64,u64))
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
thanks, i hope this time look good to you :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
related with #20