Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Add invalid signature support #104

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Conversation

xiaodino
Copy link

@xiaodino xiaodino commented Jun 1, 2023

Description

Support skipping the following invalid transations:

  • nonce too low
  • nonce too high
  • intrinsic gas too low
  • insufficient funds for gas * price + value
  • invalid ecdsa signature

Issue Link

#70

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • 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

Contents

@xiaodino xiaodino marked this pull request as ready for review June 13, 2023 06:02
eth-types/src/lib.rs Outdated Show resolved Hide resolved
Copy link

@Brechtpd Brechtpd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks very good!

make test failed on some commented code (wat) but easy fix, just add this in bus-mapping/src/lib.rs:

+//!     invalid: false,

Afterwards make test works but I guess these errors that are tx table lookup related so seems like there's an issue there:

test super_circuit::test::serial_test_super_circuit_1tx_1max_tx ... [2023-06-13T18:07:46Z ERROR zkevm_circuits::super_circuit::test] Verification failures: [
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 218,
                name: "State transition (delta) constraint of rw_counter",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 219,
                name: "State transition (to) constraint of call_id",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 220,
                name: "State transition (to) constraint of is_root",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 222,
                name: "State transition (to) constraint of code_hash",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 224,
                name: "State transition (to) constraint of stack_pointer",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 225,
                name: "State transition (to) constraint of gas_left",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 230,
                name: "num_rows_until_next_step_next := height - 1",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        Lookup Tx(index: 205) is not satisfied in Region 25 ('Execution step') at offset 19,
        Lookup Tx(index: 205) is not satisfied in Region 25 ('Execution step') at offset 2,
        Lookup Tx(index: 208) is not satisfied in Region 25 ('Execution step') at offset 1,
    ]
FAILED
test super_circuit::test::serial_test_super_circuit_1tx_2max_tx ... [2023-06-13T18:08:35Z ERROR zkevm_circuits::super_circuit::test] Verification failures: [
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 218,
                name: "State transition (delta) constraint of rw_counter",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 219,
                name: "State transition (to) constraint of call_id",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 220,
                name: "State transition (to) constraint of is_root",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 222,
                name: "State transition (to) constraint of code_hash",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 224,
                name: "State transition (to) constraint of stack_pointer",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 225,
                name: "State transition (to) constraint of gas_left",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 230,
                name: "num_rows_until_next_step_next := height - 1",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        Lookup Tx(index: 205) is not satisfied in Region 25 ('Execution step') at offset 19,
        Lookup Tx(index: 205) is not satisfied in Region 25 ('Execution step') at offset 2,
        Lookup Tx(index: 208) is not satisfied in Region 25 ('Execution step') at offset 1,
    ]
FAILED
test super_circuit::test::serial_test_super_circuit_2tx_2max_tx ... [2023-06-13T18:09:25Z ERROR zkevm_circuits::super_circuit::test] Verification failures: [
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 218,
                name: "State transition (delta) constraint of rw_counter",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 219,
                name: "State transition (to) constraint of call_id",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 220,
                name: "State transition (to) constraint of is_root",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 222,
                name: "State transition (to) constraint of code_hash",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 224,
                name: "State transition (to) constraint of stack_pointer",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 225,
                name: "State transition (to) constraint of gas_left",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 230,
                name: "num_rows_until_next_step_next := height - 1",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 0,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 218,
                name: "State transition (delta) constraint of rw_counter",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 26,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 219,
                name: "State transition (to) constraint of call_id",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 26,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 220,
                name: "State transition (to) constraint of is_root",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 26,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 222,
                name: "State transition (to) constraint of code_hash",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 26,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 224,
                name: "State transition (to) constraint of stack_pointer",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 26,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 225,
                name: "State transition (to) constraint of gas_left",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 26,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        ConstraintCaseDebug {
            constraint: Constraint {
                gate: Gate {
                    index: 2531,
                    name: "BeginTx",
                },
                index: 230,
                name: "num_rows_until_next_step_next := height - 1",
            },
            location: InRegion {
                region: Region 25 ('Execution step'),
                offset: 26,
            },
            cell_values: [
                (
                    DebugVirtualCell {
                        name: "",
                        column: DebugColumn {
                            column_type: Advice,
                            index: 353,
                            annotation: "EVM_q_step",
                        },
                        rotation: 0,
                    },
                    "1",
                ),
            ],
        },
        Lookup Tx(index: 205) is not satisfied in Region 25 ('Execution step') at offset 19,
        Lookup Tx(index: 205) is not satisfied in Region 25 ('Execution step') at offset 45,
        Lookup Tx(index: 205) is not satisfied in Region 25 ('Execution step') at offset 2,
        Lookup Tx(index: 205) is not satisfied in Region 25 ('Execution step') at offset 28,
        Lookup Tx(index: 208) is not satisfied in Region 25 ('Execution step') at offset 1,
        Lookup Tx(index: 208) is not satisfied in Region 25 ('Execution step') at offset 27,
    ]
FAILED

failures:

---- super_circuit::test::serial_test_super_circuit_1tx_1max_tx stdout ----
thread 'super_circuit::test::serial_test_super_circuit_1tx_1max_tx' panicked at 'Failed verification', zkevm-circuits/src/super_circuit/test.rs:33:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- super_circuit::test::serial_test_super_circuit_1tx_2max_tx stdout ----
thread 'super_circuit::test::serial_test_super_circuit_1tx_2max_tx' panicked at 'Failed verification', zkevm-circuits/src/super_circuit/test.rs:33:9

---- super_circuit::test::serial_test_super_circuit_2tx_2max_tx stdout ----
thread 'super_circuit::test::serial_test_super_circuit_2tx_2max_tx' panicked at 'Failed verification', zkevm-circuits/src/super_circuit/test.rs:33:9


failures:
    super_circuit::test::serial_test_super_circuit_1tx_1max_tx
    super_circuit::test::serial_test_super_circuit_1tx_2max_tx
    super_circuit::test::serial_test_super_circuit_2tx_2max_tx

test result: FAILED. 1 passed; 3 failed; 0 ignored; 0 measured; 414 filtered out; finished in 145.80s

bus-mapping/src/evm/opcodes/begin_end_tx.rs Outdated Show resolved Hide resolved
geth-utils/gethutil/trace.go Outdated Show resolved Hide resolved
Comment on lines 30 to 37
ecdsa = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20" }
ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20" }
maingate = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20" }
integer = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20" }
ecdsa = { git = "https://github.com/xiaodino/halo2wrong", rev = "24a7880c259f19cc6cf786ca47cfda34433ee9fb" }
ecc = { git = "https://github.com/xiaodino/halo2wrong", rev = "24a7880c259f19cc6cf786ca47cfda34433ee9fb" }
maingate = { git = "https://github.com/xiaodino/halo2wrong", rev = "24a7880c259f19cc6cf786ca47cfda34433ee9fb" }
integer = { git = "https://github.com/xiaodino/halo2wrong", rev = "24a7880c259f19cc6cf786ca47cfda34433ee9fb" }
libsecp256k1 = "0.7"
num-bigint = { version = "0.4" }
rand_chacha = "0.3"
snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-verifier", tag = "v2023_04_20", default-features = false, features = ["loader_halo2", "system_halo2"] }
snark-verifier = { git = "https://github.com/xiaodino/snark-verifier", rev = "6131ee5d6c7126e608f798e5037b102ca3cbd406", default-features = false, features = ["loader_halo2", "system_halo2"] }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How hard would it be to still use the pse forks for now (for when we create a PR on the PSE repo which won't want to update these dependencies just yet)? So this would simply set if the signature is valid or not without any in-circuit checks.

let balance_not_enough =
LtWordGadget::construct(cb, sender_balance_prev, total_eth_cost.sum());

// A transaction is invalid when

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add invalid signature case here as well no?

zkevm-circuits/src/evm_circuit/execution/begin_tx.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/test.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/test.rs Outdated Show resolved Hide resolved
Comment on lines +247 to +248
TxFieldTag::TxInvalid,
assigned_sig_verif.is_invalid.value().copied(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tx may also be invalid because of invalid nonce/etc... So if we just set the value here to if the tx signature is valid, how can we support the other invalid cases? I think we may need a separate tag for just TxSignatureInvalid so we can lookup this value in the EVM circuit and then check if TxInvalid is indeed the correct value taking into account all possible invalid tx cases. Or do I miss something?

zkevm-circuits/src/tx_circuit.rs Outdated Show resolved Hide resolved
@xiaodino xiaodino mentioned this pull request Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants