15

Could I spend the money a contract owns if I had the private key that goes to the public address that a contract resides at? (I realize that I'd have a better chance of being struck by lightning several times in a row for years.) But if you forced it in code somehow as a test, would it actually allow you to spend the money a contract owns?

Or is the Ethereum core strict enough that it treats these as two separate things and it could never happen?

  • How can you generate the private key? – lixq May 22 '18 at 12:31
18

From my reading of the Yellow Paper (YP), Yes you would be able to spend the funds of the contract. But as you note, it is with extremely low probability of being able to find a contract's private key.

Spending money in Ethereum is done via a CALL opcode, passing it parameters such as the sender, recipient, value (being spent). Since you have the private key, you can create a valid signature for the transaction, which the network will accept. There is no special check on the sender apart from the validity of the signature. Below are the checks in the YP, and the others are easy to satisfy (for example, an account's transaction nonce is easily looked up).

  1. The transaction is well-formed RLP, with no ad- ditional trailing bytes.
  2. The transaction signature is valid.
  3. The transaction nonce is valid (equivalent to the sender account’s current nonce).
  4. The gas limit is no smaller than the intrinsic gas, g0, used by the transaction.
  5. The sender account balance contains at least the cost, v0, required in up-front payment.
  • according to your answer here there are no keys associated with a contract account address. Then how can a private key end up generating the same address as a contract's one that is created via "The sender and nonce are RLP encoded and then hashed with Keccak-256"? – the0roamer Apr 22 at 16:14
  • Usually contracts do not have keys, but it's technically possible to find that key by brute-forcing. Contracts and wallets (externally owned accounts) share the exact same address space, in that they produce addresses in the same range of numbers, so it's possible, but astronomically unlikely, to find the key for a contract by iterating over private keys until the wallet address matches the contract address. You could also do the opposite, iterating over the owner of a contract until the resulting contract would have an address the same as an existing wallet. – ihatecsv Aug 1 at 16:23

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.