0

Ethereum Yellow Paper states:

nonce: A scalar value equal to the number of transactions sent from this address or, in the case of accounts with associated code, the number of contract-creations made by this account. For account of address a in state σ, this would be formally denoted σ[a]n.

This statement does not describe situation where there is a private key for address with code. Also, I haven't found any statements to forbid existence of private key for a contract. Intuition says that in both cases nonce just incremented but I need to know this for sure from an authorized source.

  • So if I understand correctly your question is basically "if I happened to have a private key for a contract address and I was creating transactions and the contract was creating contracts, how should the nonce reflect this"? I hope you do realize this is a very theoretical question, I doubt anyone has ever found a private key for a contract – Lauri Peltonen Mar 21 at 16:39
  • Yep, that's theorizing about if someone occasionally will find a key of contract. – Iva Kam Mar 21 at 22:47
1

It will work as both.

  • When a transaction is signed by the private key it will act as an EOA. Nonce will increase with each transaction.

  • When it is invoked as a contract it will act as a contract. Nonce will increase when it creates a new contract.

The nonce will start at 1 like other smart contracts.

| improve this answer | |
1

In ethereum there are two types of accounts:

  1. Externally Owned Accounts (EOA)
  2. Contract Account

An EOA has a public key and private key associated with it whereas a contract account does not have a private key associated with it.

A contract address has a nonce which is incremented only when the contract creates another contract else the nonce is not incremented.

A transaction can only be submitted by an EOA and not a contract address. A contract address can invoke some other contract's function via message calls and not through transactions.

More details can be found here about contract nonce

| improve this answer | |
0

If an address has nonempty code, then it is not an externally-owned account but a contract account.

An externally-owned account is generated by choosing a private key and then hashing it.

So the owner of an externally-owned knows its private key and can submit transactions with it.

A contract account, on the other hand, is generated by hashing the concatenation of the account which deploys it and the current nonce of that account.

So the owner (deployer) of a contract account does not know its private key and cannot submit transactions with it, and the probability of someone (owner or not) guessing its private key (and subsequently being able to submit transactions on behalf of that account) is around 1 / 2 ^ 256.

Note: do not confuse "submitting a transaction with a contract account" and "submitting a transaction which executes a contract function"; the former refers to the transaction sender (the from field in web3.js), while the latter refers to the transaction details (the data field in web3.js).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.