Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check that the compiled class hash matches the supplied class #246

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

ArniStarkware
Copy link
Contributor

@ArniStarkware ArniStarkware commented Jun 16, 2024

This change is Reviewable

Copy link
Contributor Author

ArniStarkware commented Jun 16, 2024

@codecov-commenter
Copy link

codecov-commenter commented Jun 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.00%. Comparing base (8e9b2d7) to head (b12db17).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #246      +/-   ##
==========================================
- Coverage   83.21%   82.00%   -1.21%     
==========================================
  Files          28       28              
  Lines        1382     1423      +41     
  Branches     1382     1423      +41     
==========================================
+ Hits         1150     1167      +17     
- Misses        173      197      +24     
  Partials       59       59              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ArniStarkware ArniStarkware force-pushed the arni/declare/compile_in_gateway branch from af43060 to 42eaf2b Compare June 17, 2024 13:39
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 3ac61e8 to 960b5ac Compare June 17, 2024 13:54
@ArniStarkware ArniStarkware force-pushed the arni/declare/compile_in_gateway branch from 42eaf2b to f3b59f6 Compare June 18, 2024 11:12
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 960b5ac to 89b09d2 Compare June 18, 2024 11:12
@ArniStarkware ArniStarkware force-pushed the arni/declare/compile_in_gateway branch 2 times, most recently from 71b97d2 to c92756b Compare June 19, 2024 11:59
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 89b09d2 to 0fdbdbb Compare June 19, 2024 12:32
@ArniStarkware ArniStarkware changed the base branch from arni/declare/compile_in_gateway to arni/declare/compile/tests June 19, 2024 12:32
@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from 61e94d8 to 849bdef Compare June 19, 2024 13:29
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 0fdbdbb to 112385e Compare June 19, 2024 13:29
Copy link
Contributor Author

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion

a discussion (no related file):
Add unit test for this part.


@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from 849bdef to 09b9c05 Compare June 24, 2024 13:43
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 112385e to d42570e Compare June 24, 2024 13:44
@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from 09b9c05 to 4fad704 Compare June 25, 2024 10:53
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from d42570e to 3028c48 Compare June 25, 2024 10:53
@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from 4fad704 to d7aba7b Compare June 25, 2024 13:38
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 3028c48 to 7a637fd Compare June 25, 2024 13:38
@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from d7aba7b to d628146 Compare June 25, 2024 13:49
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 7a637fd to bad1644 Compare June 25, 2024 13:50
Copy link
Contributor Author

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

In this PR, we enforce the compiled class hash supplied by the transaction matchs the computed compiled class hash.

Reviewable status: 0 of 9 files reviewed, all discussions resolved

@ArniStarkware ArniStarkware marked this pull request as ready for review June 25, 2024 13:54
@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from d628146 to 686daf9 Compare June 27, 2024 08:48
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from bad1644 to 203eed8 Compare June 27, 2024 08:48
Copy link
Contributor

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 6 files at r2, 8 of 8 files at r3.
Reviewable status: 8 of 9 files reviewed, 3 unresolved discussions (waiting on @ArniStarkware and @dafnamatsry)


crates/gateway/src/gateway_test.rs line 133 at r3 (raw file):

        _ => panic!("Invalid transaction type"),
    };
    let RPCDeclareTransaction::V3(declare_tx_v3) = &declare_tx;

Can you match the downcast code to the previous function?

Code quote:

    let declare_tx = match declare_tx() {
        RPCTransaction::Declare(declare_tx) => declare_tx,
        _ => panic!("Invalid transaction type"),
    };
    let RPCDeclareTransaction::V3(declare_tx_v3) = &declare_tx;

crates/gateway/src/gateway_test.rs line 141 at r3 (raw file):

        Ok(class_info)
        if (
            matches!(class_info.contract_class(), ContractClass::V1(_))

I guess there is no easy way to verify the result of the compilation,
but what do you check here? only the cairo version?


crates/gateway/src/gateway_test.rs line 144 at r3 (raw file):

            && class_info.sierra_program_length() == contract_class.sierra_program.len()
            && class_info.abi_length() == contract_class.abi.len()
        )

Can you also check that the supplied compiled class hash matches the computed compiled class hash?

Copy link
Contributor Author

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 8 of 9 files reviewed, 3 unresolved discussions (waiting on @dafnamatsry and @Yael-Starkware)


crates/gateway/src/gateway_test.rs line 133 at r3 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

Can you match the downcast code to the previous function?

The difference is that here, we want to use declare_tx as the input of the function compile_contract_class.

It is more direct here. Otherwise, I will unwrap a RPCDeclareTransaction and then wrap the same value again.

If anything - I would change the previous test to get a mutable RPCDeclareTransaction - mutate it and use it in the test - but I am unsure how.


crates/gateway/src/gateway_test.rs line 141 at r3 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

I guess there is no easy way to verify the result of the compilation,
but what do you check here? only the cairo version?

First, we check that the compilation was successful. Other than that, yes, we check the Cairo version.


crates/gateway/src/gateway_test.rs line 144 at r3 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

Can you also check that the supplied compiled class hash matches the computed compiled class hash?

It is checked inside the function compile_contract_class. Testing it here is will just repeat this logic. This subject is being tested in test_compile_contract_class_failure.

@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from 686daf9 to 5419863 Compare June 27, 2024 11:07
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 203eed8 to 4e760df Compare June 27, 2024 11:07
Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 8 files at r3, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @ArniStarkware and @Yael-Starkware)


crates/gateway/src/gateway_test.rs line 112 at r5 (raw file):

        RPCTransaction::Declare(RPCDeclareTransaction::V3(declare_tx)) => declare_tx,
        _ => panic!("Invalid transaction type"),
    };

Suggestion:

    let tx = assert_matches!(
        declare_tx(),
        RPCTransaction::Declare(RPCDeclareTransaction::V3(tx)) => tx
    );
 

crates/gateway/src/gateway_test.rs line 132 at r5 (raw file):

        RPCTransaction::Declare(declare_tx) => declare_tx,
        _ => panic!("Invalid transaction type"),
    };

Same as above.

Code quote:

    let declare_tx = match declare_tx() {
        RPCTransaction::Declare(declare_tx) => declare_tx,
        _ => panic!("Invalid transaction type"),
    };

crates/gateway/src/gateway_test.rs line 144 at r5 (raw file):

            && class_info.sierra_program_length() == contract_class.sierra_program.len()
            && class_info.abi_length() == contract_class.abi.len()
        )

Please separate to 3 different assert statements.

Code quote:

    assert_matches!(
        result,
        Ok(class_info)
        if (
            matches!(class_info.contract_class(), ContractClass::V1(_))
            && class_info.sierra_program_length() == contract_class.sierra_program.len()
            && class_info.abi_length() == contract_class.abi.len()
        )

crates/gateway/src/stateful_transaction_validator_test.rs line 49 at r5 (raw file):

    local_test_state_reader_factory(CairoVersion::Cairo1, false),
    Ok(TransactionHash(StarkFelt::try_from(
        "0x02da54b89e00d2e201f8e3ed2bcc715a69e89aefdce88aff2d2facb8dec55c0a"

Why did it change?

Code quote:

0x02da54b89e00d2e201f8e3ed2bcc715a69e89aefdce88aff2d2facb8dec55c0a

@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from 5419863 to 6d1e94b Compare June 27, 2024 15:41
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 4e760df to f8db27c Compare June 27, 2024 15:41
Copy link
Contributor Author

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 7 of 9 files reviewed, 7 unresolved discussions (waiting on @dafnamatsry and @Yael-Starkware)


crates/gateway/src/gateway_test.rs line 112 at r5 (raw file):

        RPCTransaction::Declare(RPCDeclareTransaction::V3(declare_tx)) => declare_tx,
        _ => panic!("Invalid transaction type"),
    };

Done.


crates/gateway/src/gateway_test.rs line 132 at r5 (raw file):

Previously, dafnamatsry wrote…

Same as above.

Done.


crates/gateway/src/gateway_test.rs line 144 at r5 (raw file):

Previously, dafnamatsry wrote…

Please separate to 3 different assert statements.

Done.


crates/gateway/src/stateful_transaction_validator_test.rs line 49 at r5 (raw file):

Previously, dafnamatsry wrote…

Why did it change?

compiled_class_hash changed from CompiledClassHash::Default().

Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 6 files at r2, 3 of 8 files at r3, 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArniStarkware and @Yael-Starkware)


crates/gateway/src/gateway_test.rs line 165 at r6 (raw file):

        result,
        Ok(class_info) => class_info
    );

Suggestion:

    let class_info = compile_contract_class(&declare_tx).unwrap();

@ArniStarkware ArniStarkware force-pushed the arni/declare/compile/tests branch from 6d1e94b to a70795b Compare June 30, 2024 08:50
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from f8db27c to 358bcbd Compare June 30, 2024 08:50
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from 358bcbd to dffdc5a Compare June 30, 2024 09:14
@ArniStarkware ArniStarkware changed the base branch from arni/declare/compile/tests to main June 30, 2024 09:14
@ArniStarkware ArniStarkware force-pushed the arni/declare/compute_compiled_class_hash branch from dffdc5a to b12db17 Compare June 30, 2024 09:26
Copy link
Contributor Author

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 8 of 9 files reviewed, 4 unresolved discussions (waiting on @dafnamatsry and @Yael-Starkware)


crates/gateway/src/gateway_test.rs line 165 at r6 (raw file):

        result,
        Ok(class_info) => class_info
    );

Done.

Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @Yael-Starkware)

Copy link
Contributor

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r5, 1 of 2 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)

@ArniStarkware ArniStarkware merged commit 1e568dc into main Jul 1, 2024
8 checks passed
@ArniStarkware ArniStarkware deleted the arni/declare/compute_compiled_class_hash branch July 1, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants