Handle contract creation tx#1140
Conversation
|
Starting the review tomorrow as my first task. Will try to do it ASAP! |
CPerezz
left a comment
There was a problem hiding this comment.
Nice work done here! It's a quite big PR.
Have done a 1st pass but will need to do a 2nd definitely and check deeper.
| keccak_lookup!(0, tx_nonce_lt_128.expr()); | ||
| keccak_lookup!( | ||
| 1, | ||
| not::expr(tx_nonce_lt_128.expr()), | ||
| tx_nonce_byte_size_cmp.value_equals(1usize) | ||
| ); | ||
| keccak_lookup!(2, tx_nonce_byte_size_cmp.value_equals(2usize)); | ||
| keccak_lookup!(3, tx_nonce_byte_size_cmp.value_equals(3usize)); | ||
| keccak_lookup!(4, tx_nonce_byte_size_cmp.value_equals(4usize)); | ||
| keccak_lookup!(5, tx_nonce_byte_size_cmp.value_equals(5usize)); | ||
| keccak_lookup!(6, tx_nonce_byte_size_cmp.value_equals(6usize)); | ||
| keccak_lookup!(7, tx_nonce_byte_size_cmp.value_equals(7usize)); | ||
| keccak_lookup!(8, tx_nonce_byte_size_cmp.value_equals(8usize)); |
There was a problem hiding this comment.
There has to be a better way to do this I think. It's fine to land this now but we should file a tech-debt issue.
There was a problem hiding this comment.
With the RLP gadget, I believe it will be possible to remove this. Before merging this PR, I'll make it a point to create that issue and define the scope. Again, as I said above, I'm happy to implement the RLP gadget for contract creation address (CREATE/CREATE2)
There was a problem hiding this comment.
@CPerezz I've ported over @z2trillion 's work with tests, which includes the gadget to calculate CREATE address is here:
https://github.com/scroll-tech/zkevm-circuits/blob/feat/contract-create-rlp/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs#L182
I'd suggest I can do the refactoring as part of a separate PR (to make the reviewing process more convenient). But if you think it's better to be wrapped up in this very PR, happy to make the changes :)
There was a problem hiding this comment.
Sure if we file a tech-debt PR before merging with all of the things like this.
There was a problem hiding this comment.
This part of multiple condition guarded keccak lookups has been replaced by a single keccak lookup, where the input rlc and input length is calculated from the ContractCreate gadget that we merged earlier.
| tx_call_data_length.expr(), | ||
| ), | ||
| (CallContextFieldTag::Value, tx_value.expr()), | ||
| (CallContextFieldTag::IsStatic, 0.expr()), |
There was a problem hiding this comment.
How do we know that IsStatic = false? We aren't in a create Tx but we should still be able to be in a non-static call.
There was a problem hiding this comment.
Nevermind. The root call always needs to be non-static right? @ed255 do you happen to know?
There was a problem hiding this comment.
Yes, I forgot to respond to this. My understanding was that a contract creation transaction (is_create * is_root == true) MUST be non-static.
|
@roynalnaruto perfect! I'll take a look to the other one after 2 other pending reviews I have! :) |
### Description The `CREATE2` input length and `RLC(input)` were not tested during the #1164 merge. This PR adds and enables a test for CREATE2 specific `input_len` and `input_rlc` calculation. ### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### How Has This Been Tested? The helper container can test both `CREATE` and `CREATE2` inputs (length and `RLC(input_bytes)`). These inputs are then used as inputs to do a lookup to the Keccak table. ### Related PRs - #1164 - #1140 (needs rebasing after this is merged) --------- Co-authored-by: adria0.eth <5526331+adria0@users.noreply.github.com>
|
Is this ready for review now that the other related PRs have been merged @roynalnaruto ? |
|
@CPerezz Yes it's ready for review. I've also answered your questions and resolved most of the review comments! |
CPerezz
left a comment
There was a problem hiding this comment.
Just one change required.
Aside from a couple nits, the rest looks good!
Nice work @roynalnaruto
| tx_call_data_length.expr(), | ||
| ), | ||
| (CallContextFieldTag::Value, tx_value.expr()), | ||
| (CallContextFieldTag::IsStatic, 0.expr()), |
There was a problem hiding this comment.
Nevermind. The root call always needs to be non-static right? @ed255 do you happen to know?
* fix: Stale code comment * fix: Inconsistent structure constructor enables clippy::inconsistent_struct_constructor lint * fix: Incorrect documentation on the MinMaxGadget * fix: cargo audit * fix clippy
This PR handles "case 1" in the
BeginTxgadget, i.e. a contract deployment transaction.Major changes:
RLP([tx_caller, tx_nonce])to the keccak tablenonceBeginTxgadget:byte_size(tx.nonce))keccak_rlcmethod in constraint builder that computes a random linear combination usingchallenge.keccak_inputBinaryNumbergadget toevm_circuit::util::math_gadget