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

Fix account signature #387

Merged
merged 5 commits into from
Jul 12, 2022

Conversation

andrew-fleming
Copy link
Collaborator

@andrew-fleming andrew-fleming commented Jul 10, 2022

Resolves #386.

This proposed Account change will yield an artifact upon compilation that should be added to Nile to address issue 143.

@frangio
Copy link
Contributor

frangio commented Jul 11, 2022

Why is the ecdsa_ptr implicit argument required in unsafe_execute ?

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.

Looks good to me, left a small question

Comment on lines +129 to +131
# bump nonce
await signer.send_transactions(account, [(initializable.contract_address, 'initialized', [])])

Copy link
Contributor

Choose a reason for hiding this comment

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

was this passing before? if so, why? if not, why is it needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was passing before, but with the proposed changes, the nonce's 0 - 1 is out of range for a valid signature, which in turn, returns a different error. This is similar to what happened here:
#361 (comment)

return _unsafe_execute(call_array_len, call_array, calldata_len, calldata, nonce)
end

func _unsafe_execute{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr,
ecdsa_ptr: SignatureBuiltin*,
Copy link
Contributor

Choose a reason for hiding this comment

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

following Fran's comment, this shouldn't be needed right?

Copy link
Collaborator Author

@andrew-fleming andrew-fleming Jul 11, 2022

Choose a reason for hiding this comment

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

@frangio

Why is the ecdsa_ptr implicit argument required in unsafe_execute ?

Compilation without the ecdsa_ptr in _unsafe_execute fails:

E               starkware.cairo.lang.compiler.preprocessor.preprocessor_error.PreprocessorError: /Users/andrewfleming/Documents/starknet/cairo-contracts/cairo-contracts/.tox/default/lib/python3.7/site-packages/openzeppelin/account/library.cairo:211:9: Cannot convert the implicit arguments of _unsafe_execute to the implicit arguments of execute.
E                       return _unsafe_execute(call_array_len, call_array, calldata_len, calldata, nonce)
E                       ^*******************************************************************************^
E               The implicit arguments of '_unsafe_execute' were defined here:
E               /Users/andrewfleming/Documents/starknet/cairo-contracts/cairo-contracts/.tox/default/lib/python3.7/site-packages/openzeppelin/account/library.cairo:241:26
E                   func _unsafe_execute{
E                                        ^
E               The implicit arguments of 'execute' were defined here:
E               /Users/andrewfleming/Documents/starknet/cairo-contracts/cairo-contracts/.tox/default/lib/python3.7/site-packages/openzeppelin/account/library.cairo:187:18
E                   func execute{
E                                ^

_unsafe_execute makes the actual contract call and seems to require passing the sig builtin for verification:

https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/lang/builtins/signature/signature_builtin_runner.py#L12-L18

I'm still trying to understand this issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

And what if we explicitly pass the implicit arguments without including ecdsa_ptr? It looks like it's trying to pass along all the available implicit arguments including those that aren't needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I understand you question correctly, I don't think this works. Taking out the implicit ecdsa_ptr means we'll still need to create some reference to it to validate the signature...which brings us back to the same initial issue: Signature hint must point to the signature builtin segment, not {addr}.

Copy link
Contributor

@frangio frangio Jul 12, 2022

Choose a reason for hiding this comment

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

My suggestion was to write the call as

_unsafe_execute{syscall_ptr, pedersen_ptr, etc...}(call_array_len, call_array, calldata_len, calldata, nonce)

(I'm not sure if this works)

Copy link
Contributor

Choose a reason for hiding this comment

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

Afaict the implicit arguments are not only received by _unsafe_execute but also passed to the next function call, doing so could revoke ecdsa_ptr but other than that it might work.

@andrew-fleming andrew-fleming merged commit c2007df into OpenZeppelin:main Jul 12, 2022
@andrew-fleming andrew-fleming deleted the fix-account-sig branch July 12, 2022 19:15
@amanusk
Copy link
Contributor

amanusk commented Jul 13, 2022

Just to ask about this, accounts created on goerli with 0.2.0 and have funds in them are currently irrecoverable?

@martriay
Copy link
Contributor

Just to ask about this, accounts created on goerli with 0.2.0 and have funds in them are currently irrecoverable?

I'm afraid so. Mainnet ones shouldn't since they weren't whitelisted. Are you aware of any relevant one that need a solution?

@amanusk
Copy link
Contributor

amanusk commented Jul 13, 2022

Nothing of notice. I was just playing around with starknet-hardhat-plugin and did not understand why things are not working until I hit this error.
Thought it was lack of funding of the accounts at first ..
Fortunately its just testnet tokens 😉

@amanusk
Copy link
Contributor

amanusk commented Jul 13, 2022

BTW, trying to compile the latest main branch, it seems the Account contract fails to compile:

🛑 Failed to compile the following 2 contracts:
   src/openzeppelin/account/Account.cairo
   src/openzeppelin/account/EthAccount.cairo
(cairo_venv) [~/Code/Cairo/cairo-contracts]> 

Could it be related?

@martriay
Copy link
Contributor

BTW, trying to compile the latest main branch, it seems the Account contract fails to compile:

🛑 Failed to compile the following 2 contracts:
   src/openzeppelin/account/Account.cairo
   src/openzeppelin/account/EthAccount.cairo
(cairo_venv) [~/Code/Cairo/cairo-contracts]> 

Could it be related?

Do you see this in the stdout?

Only account contracts may have a function named "__execute__". Use --account_contract flag.

@amanusk
Copy link
Contributor

amanusk commented Jul 13, 2022

Indeed

🔨 Compiling src/openzeppelin/account/Account.cairo
Only account contracts may have a function named "__execute__". Use --account_contract flag.
🔨 Compiling src/openzeppelin/account/IAccount.cairo
🔨 Compiling src/openzeppelin/account/library.cairo
🔨 Compiling src/openzeppelin/account/EthAccount.cairo
Only account contracts may have a function named "__execute__". Use --account_contract flag.
🔨 Compiling src/openzeppelin/security/safemath.cairo
🔨 Compiling src/openzeppelin/security/initializable.cairo
🔨 Compiling src/openzeppelin/security/pausable.cairo
🔨 Compiling src/openzeppelin/security/reentrancyguard.cairo
🛑 Failed to compile the following 2 contracts:
   src/openzeppelin/account/Account.cairo
   src/openzeppelin/account/EthAccount.cairo

Should I compile it like this:

 nile compile --directory ./src/openzeppelin/account --account_contract

@martriay
Copy link
Contributor

martriay commented Jul 13, 2022

Yes. This is fixed in Nile 0.7.0 (fixed in OpenZeppelin/nile#112, about to be integrated in #381).

(env) ➜  cairo-contracts git:(main) nile compile --directory src/ src/openzeppelin/account/{,Eth}Account.cairo --account_contract
🔨 Compiling src/openzeppelin/account/Account.cairo
🔨 Compiling src/openzeppelin/account/EthAccount.cairo
✅ Done

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.

ecdsa_ptr points to reference in Account lib's execute
4 participants