Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Conversation

zhenfeizhang
Copy link

@zhenfeizhang zhenfeizhang commented Feb 20, 2023

Description

[PR description]

#344

[link issue here]

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

  • PK endieness was not correct.

Rationale

[design decisions and extended information]

How Has This Been Tested?

cargo test -p zkevm-circuits --features "onephase, enable-sign-verify, reject-eip2718" --release tx_cir  -- --nocapture
test tx_circuit::tx_circuit_tests::tx_circuit_2tx_2max_tx ... FAILED
test tx_circuit::tx_circuit_tests::tx_circuit_bad_address ... FAILED
test tx_circuit::tx_circuit_tests::tx_circuit_0tx_1max_tx ... ok
test tx_circuit::tx_circuit_tests::tx_circuit_1tx_1max_tx ... ok
test tx_circuit::tx_circuit_tests::tx_circuit_1tx_2max_tx ... ok
test tx_circuit::sign_verify::sign_verify_tests::sign_verify ... ok

How to fill a PR description

Please give a concise description of your PR.

The target readers could be future developers, reviewers, and auditors. By reading your description, they should easily understand the changes proposed in this pull request.

MUST: Reference the issue to resolve

Single responsability

Is RECOMMENDED to create single responsibility commits, but not mandatory.

Anyway, you MUST enumerate the changes in a unitary way, e.g.

This PR contains:
- Cleanup of xxxx, yyyy
- Changed xxxx to yyyy in order to bla bla
- Added xxxx function to ...
- Refactored ....

Design choices

RECOMMENDED to:

  • What types of design choices did you face?
  • What decisions you have made?
  • Any valuable information that could help reviewers to think critically

@zhenfeizhang zhenfeizhang self-assigned this Feb 20, 2023
@lispc
Copy link

lispc commented Feb 20, 2023

tx_circuit_2tx_2max_tx failed? is it expected?

@@ -0,0 +1 @@
pub(crate) const DEGREE: usize = 19;
Copy link

Choose a reason for hiding this comment

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

is this change needed?

Copy link
Author

Choose a reason for hiding this comment

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

fixed with 89fafcd

let pk_hash = keccak(&sign_data);
let address = pk_hash.to_address();
assert_eq!(address, tx.caller_address);
}
Copy link

Choose a reason for hiding this comment

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

suggest change to log::error! so the test tx_circuit_bad_address will not panic

Copy link
Author

Choose a reason for hiding this comment

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

fixed with 89fafcd

@zhenfeizhang
Copy link
Author

zhenfeizhang commented Feb 20, 2023

test tx_circuit::tx_circuit_tests::tx_circuit_2tx_2max_tx ... FAILED
test tx_circuit::tx_circuit_tests::tx_circuit_bad_address ... FAILED

because of the assertion

        // assert tx.caller_address == recovered_pk
        for (sign_data, tx) in keccak_inputs_sign_verify(&sign_datas)
            .into_iter()
            .zip(self.txs.iter())
        {
            let pk_hash = keccak(&sign_data);
            let address = pk_hash.to_address();
            assert_eq!(address, tx.caller_address);
        }

---- tx_circuit::tx_circuit_tests::tx_circuit_2tx_2max_tx stdout ----
thread 'tx_circuit::tx_circuit_tests::tx_circuit_2tx_2max_tx' panicked at 'assertion failed: `(left == right)`
  left: `0x2e67890492c05eebdb86a6a9d2e0dbabd9629623`,
 right: `0x1c4fab018e8d4d88f0812c40651462c8fe689c7c`', zkevm-circuits/src/tx_circuit.rs:1686:13

---- tx_circuit::tx_circuit_tests::tx_circuit_bad_address stdout ----
thread 'tx_circuit::tx_circuit_tests::tx_circuit_bad_address' panicked at 'assertion failed: `(left == right)`
  left: `0xeefca179f40d3b8b3d941e6a13e48835a3af8241`,
 right: `0x1230000000000000000000000000000000000456`', zkevm-circuits/src/tx_circuit.rs:1686:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

shall we keep this check and return an error instead, or remove this check? @kunxian-xia

@lispc
Copy link

lispc commented Feb 20, 2023

@kunxian-xia can you have another check of tx_circuit_2tx_2max_tx? strange..

@zhenfeizhang
Copy link
Author

before padding
address from sign data 0xeefca179f40d3b8b3d941e6a13e48835a3af8241
address from sign data 0xf77b585877dcc1b7a1e71cb81898081b6d421ad0
address from sign data 0xd0377f5f15ede557b4b69cf49b2f6a25748f9010
address from sign data 0x2e67890492c05eebdb86a6a9d2e0dbabd9629623
address from sign data 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf
===
tx.caller_address: 0xeefca179f40d3b8b3d941e6a13e48835a3af8241 
address from sign data 0xeefca179f40d3b8b3d941e6a13e48835a3af8241
tx.caller_address: 0xd0377f5f15ede557b4b69cf49b2f6a25748f9010 
address from sign data 0xf77b585877dcc1b7a1e71cb81898081b6d421ad0
[2023-02-20T15:05:32Z ERROR zkevm_circuits::tx_circuit] pk address from sign data 0xf77b585877dcc1b7a1e71cb81898081b6d421ad0 does not match the one from tx address 0xd0377f5f15ede557b4b69cf49b2f6a25748f9010
===
after padding
address from sign data 0xeefca179f40d3b8b3d941e6a13e48835a3af8241
address from sign data 0xf77b585877dcc1b7a1e71cb81898081b6d421ad0
address from sign data 0xd0377f5f15ede557b4b69cf49b2f6a25748f9010
address from sign data 0x2e67890492c05eebdb86a6a9d2e0dbabd9629623
address from sign data 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf

seems like sign_datas is already padded and 0xf77b585877dcc1b7a1e71cb81898081b6d421ad0 is get inserted somehow

@kunxian-xia kunxian-xia marked this pull request as ready for review February 21, 2023 03:11
let (_pk, _, address) = ecdsa_chip.range.gate.inner_product(
ctx,
&powers_of_256_cells[0..20].to_vec(),
&pk_hash_cells[12..].to_vec(),

Choose a reason for hiding this comment

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

pk_hash_cells is in little endian order?

.into_iter()
.enumerate()
.filter(|(idx, _)| {
// each sign_data produce two inputs for hashing
Copy link
Author

Choose a reason for hiding this comment

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

cool! and LGTM!

@lispc lispc merged commit 06e9d64 into scroll-stable Feb 21, 2023
@lispc lispc deleted the fix/ecdsa_err branch February 21, 2023 05:01
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