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

Add EthAccount #853

Merged

Conversation

ericnordelo
Copy link
Member

@ericnordelo ericnordelo commented Dec 12, 2023

Fixes #573

PR Checklist

  • Tests
  • Documentation
  • Added entry to CHANGELOG.md
  • Tried the feature on a public network

@ericnordelo ericnordelo marked this pull request as ready for review December 15, 2023 15:36
Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Great start, Eric! I left some feedback.

I also have some doubts on the EthAccount dual dispatcher. The v0 eth account pubkey used the felt252 eth address; whereas, this implementation uses the secp256k1point eth pubkey. Backward compatibility will be an issue. Do you agree?

Also, this review is just for the code. I didn't want to wait any longer, so I haven't looked at the docs yet

src/account/eth_account/eth_account.cairo Outdated Show resolved Hide resolved
src/account/eth_account/eth_account.cairo Outdated Show resolved Hide resolved
src/account/eth_account/eth_account.cairo Outdated Show resolved Hide resolved
src/account/eth_account/eth_account.cairo Outdated Show resolved Hide resolved
src/account/eth_account/interface.cairo Outdated Show resolved Hide resolved
src/tests/mocks/eth_account_mocks.cairo Outdated Show resolved Hide resolved
src/tests/mocks/eth_account_mocks.cairo Outdated Show resolved Hide resolved
src/presets/eth_account.cairo Outdated Show resolved Hide resolved
src/account/utils.cairo Outdated Show resolved Hide resolved
src/account/utils/secp256k1.cairo Outdated Show resolved Hide resolved
ericnordelo and others added 3 commits December 21, 2023 14:28
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
…o/cairo-contracts into feat/migrate-eth-account-#573
@ericnordelo
Copy link
Member Author

I also have some doubts on the EthAccount dual dispatcher. The v0 eth account pubkey used the felt252 eth address; whereas, this implementation uses the secp256k1point eth pubkey. Backward compatibility will be an issue. Do you agree?

I don't think we need to be BC with the cairo 0 version, but I'm wondering if we should add the camelCase interfaces for this module at all. A reason to keep it is that some contracts and modules can still be using isValidSignature, and this could be compatible by just passing a different signature (secp256k1 compatible). cc @martriay

Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Nice work on the docs! I know this is still a WIP, but I left a few comments and questions

docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

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

Great progress! Left some partial comments, still missing a few modules.

docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
@@ -3,6 +3,7 @@

// Class Hashes
:account-class-hash: 0x016c6081eb34ad1e0c5513234ed0c025b3c7f305902d291bad534cd6474c85bc
:eth-account-upgradeable-class-hash: TBD
Copy link
Contributor

Choose a reason for hiding this comment

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

comment to remind us to complete this once we have it

src/account/eth_account/interface.cairo Outdated Show resolved Hide resolved
src/account/eth_account/eth_account.cairo Outdated Show resolved Hide resolved
src/account/utils/secp256k1.cairo Outdated Show resolved Hide resolved
src/account/utils/signature.cairo Outdated Show resolved Hide resolved
Comment on lines 35 to 52
#[derive(Drop, starknet::Event)]
struct OwnerAdded {
#[key]
new_owner_guid: felt252
}

#[derive(Drop, starknet::Event)]
struct OwnerRemoved {
#[key]
removed_owner_guid: felt252
}

mod Errors {
const INVALID_CALLER: felt252 = 'EthAccount: invalid caller';
const INVALID_SIGNATURE: felt252 = 'EthAccount: invalid signature';
const INVALID_TX_VERSION: felt252 = 'EthAccount: invalid tx version';
const UNAUTHORIZED: felt252 = 'EthAccount: unauthorized';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if this can be abstracted out so it's easily reused in both modules somehow

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we are prefixing messages with the module name, I don't think so. Do you have something in mind? We could implement traits with different implementations in scope, but that would be overkilling the issue imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking more about normalizing the errors as Account: ... because I still feel like treating Account and EthAccount as roughly the same component, the separation wasn't ideal but a workaround. No strong opinions, we can leave it like this.

///
/// Requirements:
///
/// - The transaction version must be `TRANSACTION_VERSION` for actual transactions.
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be updated after #858

@ericnordelo
Copy link
Member Author

ericnordelo commented Jan 3, 2024

@andrew-fleming I've pushed the updates regarding error messages, after we confirm we are ok with it, I will update the rest in the other PR. The rules I'm following:

  • Use assertion macros instead of inline functions (assert! and assert_eq!). These allow us to pass ByteArrays instead of short strings.
  • Use assert_eq! over assert! when applicable.
  • Avoid adding messages to assertions as much as possible to avoid redundancy. There are cases where messages are helpful, but sometimes they are redundant. for example, assert!(big_point_1 != big_point_2); shouldn't need a message while assert_eq!(parity, true, "Parity should be odd"); add some clarity.
  • When the message is helpful, I'm following these short rules by basically using "X should be Y" or "X should have Y" or just "Should be/have Y", etc...

Let me know what you think.

Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

I just left a small comment and a question on the same minor thing. Overall, the error messages look good though. Nice work!

...after we confirm we are ok with it, I will update the rest in the other PR

Good call 👍

src/tests/account/test_eth_account.cairo Outdated Show resolved Hide resolved
src/tests/account/test_dual_eth_account.cairo Outdated Show resolved Hide resolved
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

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

Really great job! It looks very good to me. I think we're ready to test this onchain.

src/tests/presets/test_eth_account.cairo Show resolved Hide resolved
docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
ericnordelo and others added 2 commits January 17, 2024 11:38
@martriay
Copy link
Contributor

martriay commented Jan 29, 2024

We can fix the conflicts and merge.

src/account/account/account.cairo Outdated Show resolved Hide resolved
src/account/account/account.cairo Outdated Show resolved Hide resolved
docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

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

fix conflicts and good to merge!

@ericnordelo ericnordelo merged commit 6d26b84 into OpenZeppelin:main Jan 31, 2024
5 checks passed
@ericnordelo ericnordelo deleted the feat/migrate-eth-account-#573 branch January 31, 2024 11:06
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.

Migrate EthAccount contract
4 participants