add SHA3.sol for keccak worst case and adapt w3utils.py and deploy.py#15
Conversation
|
I took a quick look at the generated bytecode and each sha3 iteration looks like this: I think this can be improved significantly to increase the ratio of I'll try to figure out how to improve it |
|
Giving that the out of gas exception work now we can attach as many |
|
This one uses as many as possible |
if the Tx reverts, do we generate a proof? |
This should work since privacy-ethereum/zkevm-circuits#979 but didn't test it yet |
|
I just tested it and get |
Ah yeah! This is expected. Although in the EVM side the out of gas situation is a single error, in the circuits we implement them separate for each opcode (this is because each opcode has a different logic to calculate its gas cost). So currently out of gas checks for some opcodes are implemented, but for others not yet. Edit1: If this error is encountered the proof generation fails. I'm not sure if privacy-ethereum/zkevm-circuits#979 fixes it, but I think it's best to avoid the OutOfGasSHA3 state until it's implemented. |
|
@AronisAt79 can you try with this contract? // SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
contract CheckKeccak {
function checkBatchYul(uint256 l) external returns (bytes32 r) {
uint256 len = l / 32;
uint256 p = 0;
uint256 n = 1;
for (uint256 i; i<len; i++) {
assembly {
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
pop(keccak256(p, n))
}
}
return 0;
}
}The SHA3 (also called KECCAK256) opcode takes input from memory and outputs to the stack. Since the input and output are in different places, chaining the opcodes (like In the contract code I passed each sha3 iteration will look like this: |
|
Thank you both! I am seeing that both approaches result in similar iterations. I will try with the .sol deployment for now, as it is easier to do withing the tool, but @pinkiebell , could you please send the corresponding solidity file (from your bytecode) just for my info? |
|
I added this here via the bytecode util, no solidity file |
so it will be already part of the precompiled l2 ? |
it isn't yet but I will add all the bytecodes to the l2 genesis 👌 |
|
@ed255, @pinkiebell thanks, |
Could you provide more details on this issue?
Just for clarity, |
|
@ed255 thanks for the hints during our call yesterday! Indeed the problem was the default solidity optimizations applied by brownie. I modified the compiler config and it now works as expected! |
TxTrace.zip