Crude gas metering - #19
Conversation
| println!( | ||
| "evm gas: {}, r55 gas: {}, total cost: {}", | ||
| evm_gas, r55_gas, total_cost | ||
| ); |
There was a problem hiding this comment.
Just curious; which formatter are you using?
There was a problem hiding this comment.
maybe log::info or debug instead of println?
leonardoalt
left a comment
There was a problem hiding this comment.
Nice! I'd say we can almost merge as is. We should probably merge the changes into rvemu first?
|
|
||
| // This is the minimum "gas used" to ABI decode 'empty' calldata into Rust type arguments. Real calldata will take more gas. | ||
| // Internalising this would focus gas metering more on the function logic | ||
| let base_cost = 9_175_538; |
There was a problem hiding this comment.
This is the minimum cost to ABI decode calldata to Rust types, from here
Perhaps base cost is not the best naming and it could be abi_decode_cost. I've subtracted it because it overshadows function execution cost and happens before it.
There was a problem hiding this comment.
But do we need to count it separately here with a constant? Doesn't the decoding code also run in RISCV?
There was a problem hiding this comment.
I counted it separately mainly because the decoding logic consumes significantly more cycles compared to the user function logic.
So every contract call incurs a minimum decoding cost of ~9M cycles + the actual cost of contract execution- which is in the thousands and negligible by comparison due to the difference in magnitude.
The decoding logic does run inside RISCV tho and if we want to factor it in, we probably have to come up with a reduction like 0.001 * r55_cost, to be able to properly add it to EVM gas costs.
There was a problem hiding this comment.
Right, that's kinda crazy. Let's merge this like this and we can investigate later why ABI decoding takes so many cycles
There was a problem hiding this comment.
Yeah! I think we're g2g with this PR then
Yup, waiting on that here: r55-eth/rvemu#1 or do you mean to upstream it? |
Ah right, I actually don't have write permissions there, I just asked Lucas to transfer the repo to r55-eth org. |
Sweet, thanks! I've pushed in the change for that. |
explores #17
Some notes:
mint=> 11.4K,balance=> 6K,approve=> 11.2K