Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

add evm_unlockUnknownAccount #622

Closed
wants to merge 0 commits into from
Closed

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Sep 1, 2020

This feature is much-needed for on the fly transaction creation, I hope you accept this PR!
I can write more tests if required

@davidmurdoch
Copy link
Member

davidmurdoch commented Sep 1, 2020

Thanks for the PR. We'll need to discuss implementation details (such as the RPC endpoint) before merging.

Related issue: #588

@rymnc
Copy link
Contributor Author

rymnc commented Sep 1, 2020

Thanks for the PR. We'll need to discuss implementation details (such as the RPC endpoint) before mergeing.

Related issue: #588

Thank You!

@rymnc
Copy link
Contributor Author

rymnc commented Sep 2, 2020

@davidmurdoch would you be open to using the
web3.extend module?
It could help if you are planning of extending the json rpc api
Documentation
It has i/o formatters as well

@davidmurdoch
Copy link
Member

I don't think this is something that could be done from within ganache-core, as we don't use web3 (except for a couple of RPC calls when in forking mode). Maybe trufflesuite/truffle could extend their injected web3 with ganache's missing RPC methods, if they don't already.

@rymnc
Copy link
Contributor Author

rymnc commented Sep 2, 2020

yes, that's true. Just had a little doubt though. does truffle use ganache-core?

@davidmurdoch
Copy link
Member

Yes, it does for the default development chain.

@rymnc
Copy link
Contributor Author

rymnc commented Sep 10, 2020

@davidmurdoch any update on integrating this endpoint into the suite?

@davidmurdoch
Copy link
Member

davidmurdoch commented Sep 11, 2020

@aaryamannchallani We're discussing this internally. For now, let's change the name to evm_unlockAccount, as we use the evm_ namespace for our non-standard rpc endpoints.

There are some security considerations to be aware of here. As is, this will allow any user to unlock any account, even an intentionally locked account (accounts that are in accounts but not in unlocked_accounts, which can happen at start up or via some of the personal_ RPC calls).

So we need to a think of a way to secure this RPC endpoint by default, as ganache is often used in collaborative environments.

@rymnc
Copy link
Contributor Author

rymnc commented Sep 11, 2020

got it, will make that change
as for the locked accounts, I'll have to read the codebase a bit more

Copy link
Member

@davidmurdoch davidmurdoch left a comment

Choose a reason for hiding this comment

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

We chatted about this internally and decided on this method should be named evm_unlockUnknownAccount.

Before we can merge this the behavior needs to be changed so that it does not unlock accounts found in this.state.personal_accounts, as these can already be unlocked (if previously locked at start up or via personal_lockAccount) via personal_unlockAccount.

return callback(null, true);
}
// If Account exists, this is the callback
callback(null, "Account Already Unlocked");
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this should return false instead of "Account Already Unlocked".

@@ -574,6 +574,18 @@ GethApiDouble.prototype.debug_traceTransaction = function(txHash, params, callba
this.state.queueTransactionTrace(txHash, params, callback);
};

// Unlocks any account after server start
GethApiDouble.prototype.debug_unlockAccount = function(address, callback) {
Copy link
Member

Choose a reason for hiding this comment

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

We chatted about this internally and decided on this method should be named evm_unlockUnknownAccount.

// Checks if given address is already unlocked
if (this.state.unlocked_accounts[address.toLowerCase()] !== true) {
// Unlocks it
this.state.unlocked_accounts[address.toLowerCase()] = true;
Copy link
Member

@davidmurdoch davidmurdoch Sep 11, 2020

Choose a reason for hiding this comment

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

Before we can merge this the behavior needs to be changed so that it does not unlock accounts found in this.state.personal_accounts, as these can already be unlocked (if previously locked at start up or via personal_lockAccount) via personal_unlockAccount.

Copy link
Member

Choose a reason for hiding this comment

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

In the case where the account cannot be unlocked, return an error in the callback:

  callback(new Error("cannot unlock known/personal account"));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in this commit

@rymnc
Copy link
Contributor Author

rymnc commented Sep 12, 2020

@davidmurdoch let me know if this is what you require!

@rymnc rymnc changed the title add debug_unlockAccount add evm_unlockUnknownAccount Sep 12, 2020
@rymnc
Copy link
Contributor Author

rymnc commented Sep 15, 2020 via email

@rymnc
Copy link
Contributor Author

rymnc commented Sep 15, 2020

ah thank you!
will it be in the next version 🙂

@davidmurdoch
Copy link
Member

I didn't mean to close this just yet! I just pushed the wrong local branch :-). I'm working on fixing it back up now.

@rymnc
Copy link
Contributor Author

rymnc commented Sep 15, 2020

ah okay cool

@davidmurdoch
Copy link
Member

@aaryamannchallani Merged!

@rymnc
Copy link
Contributor Author

rymnc commented Sep 15, 2020

Awesome! let me know if I can help anywhere else

@surajsjain
Copy link

How do I use this now for unlocking all the accounts from a forked chain?

@davidmurdoch
Copy link
Member

You'll still need to unlock them individually before using each one. We don't yet have a way of unlocking all accounts.

// unlock an address
await provider.send("evm_addAccount", [address, passphrase] );
await provider.send("personal_unlockAccount", [address, passphrase] );

@MicaiahReid
Copy link
Contributor

To add some more detail for any future readers, see #3603

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants