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

Migrate account presets to camelCase #446

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 73 additions & 29 deletions docs/modules/ROOT/pages/accounts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ A more detailed writeup on the topic can be found on https://perama-v.github.io/
** <<call,Call>>
** <<accountcallarray,AccountCallArray>>
* <<multicall_transactions,Multicall transactions>>
* <<api_specification,API Specification>>
** <<get_public_key,`get_public_key`>>
** <<get_nonce,`get_nonce`>>
** <<set_public_key,`set_public_key`>>
** <<is_valid_signature,`is_valid_signature`>>
** <<execute,`\\__execute__`>>
** <<is_valid_eth_signature,`is_valid_eth_signature`>>
** <<eth_execute,`eth_execute`>>
** <<unsafe_execute,`_unsafe_execute`>>
* <<contract_api_specification,Contract API Specification>>
* <<library_api_specification,Library API Specification>>
* <<presets,Presets>>
** <<account,Account>>
** <<eth_account,Eth Account>>
Expand Down Expand Up @@ -81,14 +74,14 @@ namespace IAccount:
# Getters
#

func get_nonce() -> (res : felt):
func getNonce() -> (res : felt):
end

#
# Business logic
#

func is_valid_signature(
func isValidSignature(
Comment on lines -91 to +84
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to camelCase the return is_valid here as well

hash: felt,
signature_len: felt,
signature: felt*
Expand All @@ -110,7 +103,7 @@ end

While the interface is agnostic of signature validation schemes, this implementation assumes there's a public-private key pair controlling the Account.
That's why the `constructor` function expects a `public_key` parameter to set it.
Since there's also a `set_public_key()` method, accounts can be effectively transferred.
Since there's also a `setPublicKey()` method, accounts can be effectively transferred.

=== Signer

Expand Down Expand Up @@ -200,7 +193,7 @@ That's why if you want to change the public key controlling the Account, you wou

[,python]
----
await signer.send_transaction(account, account.contract_address, 'set_public_key', [NEW_KEY])
await signer.send_transaction(account, account.contract_address, 'setPublicKey', [NEW_KEY])
----

Or if you want to update the Account's L1 address on the `AccountRegistry` contract, you would
Expand Down Expand Up @@ -318,25 +311,25 @@ Finally, the `\\__execute__` method takes the `AccountCallArray` and calldata an
NOTE: Every transaction utilizes `AccountCallArray`.
A single `Call` is treated as a bundle with one message.

== API Specification
== Contract API Specification

This in a nutshell is the Account contract public API:
This in a nutshell is the Account contract public API, followed by the `Account` and `EthAccount` presets:

[,cairo]
----
func get_public_key() -> (res: felt):
func getPublicKey() -> (publicKey: felt):
end

func get_nonce() -> (res: felt):
func getNonce() -> (nonce: felt):
end

func set_public_key(new_public_key: felt):
func setPublicKey(newPublicKey: felt):
end

func is_valid_signature(hash: felt,
func isValidSignature(hash: felt,
signature_len: felt,
signature: felt*
) -> (is_valid: felt):
) -> (isValid: felt):
end

func __execute__(
Expand All @@ -349,7 +342,7 @@ func __execute__(
end
----

=== `get_public_key`
=== `getPublicKey`

Returns the public key associated with the Account contract.

Expand All @@ -359,10 +352,10 @@ Returns:

[,cairo]
----
public_key: felt
publicKey: felt
----

=== `get_nonce`
=== `getNonce`

Returns the current transaction nonce for the Account.

Expand All @@ -375,7 +368,7 @@ Returns:
nonce: felt
----

=== `set_public_key`
=== `setPublicKey`

Sets the public key that will control this Account.
It can be used to rotate keys for security, change them in case of compromised keys or even transferring ownership of the account.
Expand All @@ -384,12 +377,12 @@ Parameters:

[,cairo]
----
public_key: felt
publicKey: felt
----

Returns: None.

=== `is_valid_signature`
=== `isValidSignature`

This function is inspired by https://eips.ethereum.org/EIPS/eip-1271[EIP-1271] and returns `TRUE` if a given signature is valid, otherwise it reverts.
In the future it will return `FALSE` if a given signature is invalid (for more info please check https://github.com/OpenZeppelin/cairo-contracts/issues/327[this issue]).
Expand All @@ -407,7 +400,7 @@ Returns:

[,cairo]
----
is_valid: felt
isValid: felt
----

NOTE: It may return `FALSE` in the future if a given signature is invalid (follow the discussion on https://github.com/OpenZeppelin/cairo-contracts/issues/327[this issue]).
Expand Down Expand Up @@ -443,10 +436,61 @@ response_len: felt
response: felt*
----


== Library API Specification


=== `is_valid_signature`

Returns `TRUE` if a given StarkKey signature is valid, otherwise it reverts.

Parameters:

[,cairo]
----
signature_len: felt
signature: felt*
----

Returns:

[,cairo]
----
is_valid: felt
----

NOTE: It may return `FALSE` in the future if a given signature is invalid (follow the discussion on https://github.com/OpenZeppelin/cairo-contracts/issues/327[this issue]).


=== `execute`

This function calls the target contract with the intended function selector and calldata parameters. It uses `is_valid_signature` to validate the nonce and if the signature matches the message represented by `call_array` and `calldata`.

Parameters:

[,cairo]
----
call_array_len: felt
call_array: AccountCallArray*
calldata_len: felt
calldata: felt*
nonce: felt
----

NOTE: The current signature scheme expects a 2-element array like `[sig_r, sig_s]`.

Returns:

[,cairo]
----
response_len: felt
response: felt*
----


=== `is_valid_eth_signature`

Returns `TRUE` if a given signature in the secp256k1 curve is valid, otherwise it reverts.
In the future it will return `FALSE` if a given signature is invalid (for more info please check https://github.com/OpenZeppelin/cairo-contracts/issues/327[this issue]).

Parameters:

Expand All @@ -467,7 +511,7 @@ NOTE: It may return `FALSE` in the future if a given signature is invalid (follo

=== `eth_execute`

This follows the same idea as the vanilla version of `execute` with the sole difference that signature verification is on the secp256k1 curve.
Same as `execute` with the sole difference that it uses `is_valid_eth_signature` for validation.

Parameters:

Expand Down
6 changes: 3 additions & 3 deletions src/openzeppelin/account/IAccount.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ namespace IAccount:
# Getters
#

func get_nonce() -> (res : felt):
func getNonce() -> (nonce : felt):
end

#
# Business logic
#

func is_valid_signature(
func isValidSignature(
hash: felt,
signature_len: felt,
signature: felt*
) -> (is_valid: felt):
) -> (isValid: felt):
end

func __execute__(
Expand Down
37 changes: 18 additions & 19 deletions src/openzeppelin/account/presets/Account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func constructor{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}(public_key: felt):
Account.initializer(public_key)
}(publicKey: felt):
Account.initializer(publicKey)
return ()
end

Expand All @@ -28,23 +28,23 @@ end
#

@view
func get_public_key{
func getPublicKey{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}() -> (res: felt):
let (res) = Account.get_public_key()
return (res=res)
}() -> (publicKey: felt):
let (publicKey) = Account.get_public_key()
return (publicKey=publicKey)
end

@view
func get_nonce{
func getNonce{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}() -> (res: felt):
let (res) = Account.get_nonce()
return (res=res)
}() -> (nonce: felt):
let (nonce) = Account.get_nonce()
return (nonce=nonce)
end

@view
Expand All @@ -53,21 +53,20 @@ func supportsInterface{
pedersen_ptr: HashBuiltin*,
range_check_ptr
} (interfaceId: felt) -> (success: felt):
let (success) = ERC165.supports_interface(interfaceId)
return (success)
return ERC165.supports_interface(interfaceId)
end

#
# Setters
#

@external
func set_public_key{
func setPublicKey{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}(new_public_key: felt):
Account.set_public_key(new_public_key)
}(newPublicKey: felt):
Account.set_public_key(newPublicKey)
return ()
end

Expand All @@ -76,7 +75,7 @@ end
#

@view
func is_valid_signature{
func isValidSignature{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr,
Expand All @@ -85,9 +84,9 @@ func is_valid_signature{
hash: felt,
signature_len: felt,
signature: felt*
) -> (is_valid: felt):
let (is_valid) = Account.is_valid_signature(hash, signature_len, signature)
return (is_valid=is_valid)
) -> (isValid: felt):
let (isValid) = Account.is_valid_signature(hash, signature_len, signature)
return (isValid=isValid)
end

@external
Expand Down
Loading