Can one contract own tokens of another contract

0 votes

If I got it right smart contracts do not have a private key, so they can not sign transactions. The first transaction is signed buy the user and if a contract calls another contract and so on, those transactions are also signed buy the user. So, what if we have two ERC20 contracts A and B and B holds some A tokens.

contract A{
....
//balance of contract B
balanceOf[0xE4e5a16C8fx207a07f7df98e3a85e2067feacB9w]=500;

function transfer(address _to, uint256 _value) public {
        _transfer(msg.sender, _to, _value);
    }
....
}

contract B{
    //address this=0xE4e5a16C8fx207a07f7df98e3a85e2067feacB9w
}

What if some user pretend to to be a contract B calling contract A? I mean he will sign the sequence of transactions where the last one would not come from the contract B, but contract A will think so.

It will look like this:

{
  data: "0xa9059cbb000000000000000000000000cf2ee9c0dccd39aac2fd44b744270f50f8af13b00000000000000000000000000000000000000000000000000000000000000064",
  from: "0xE4e5a16C8fx207a07f7df98e3a85e2067feacB9w ",//address B
  gas: 210000,
  gasPrice: 1,
  nonce: "24",
  to: "0xa6d90569018967c5esc7d056f74eg4hc3j8ae93" //address A
}

If he do so, it is possible for him, using function transfer in contract A and passing in it his own address to steal tokens from contract B balance in contract A.

So am I right and this is really possible or I made a mistake somewhere? And if it is possible, how in this case a contract can own tokens of other contracts?

Oct 17, 2018 in Blockchain by sabby
• 4,370 points
1,449 views

1 answer to this question.

0 votes
Yes, contracts can own tokens.

The transaction you specified won't work; you can't just pick a fromaddress. A transaction is sent from an externally owned account (EOA), meaning an account that has a private key. And only the person with that private key can sign such a transaction.
answered Oct 17, 2018 by Christine
• 15,790 points

Related Questions In Blockchain

0 votes
1 answer

Can a hacker change data of a smart sontract without call contract function?

A contract's content cannot be changed internally. ...READ MORE

answered Apr 8, 2018 in Blockchain by Shashank
• 10,400 points
710 views
0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,100 points
3,626 views
0 votes
1 answer

How to call function in one contract from another contract in private blockchain?

Please check whether you have byzantiumBlock: 0 in your ...READ MORE

answered Oct 1, 2018 in Blockchain by digger
• 26,740 points
875 views
0 votes
1 answer

Transfer the gas value of contract to my own address

Works fine for me: pragma solidity ^0.4.0; contract Test ...READ MORE

answered Oct 10, 2018 in Blockchain by Omkar
• 69,220 points
591 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,947 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,473 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,220 points
1,489 views
+1 vote
2 answers

Hyperledger - Can I have some instances on one network while on a Virtual Box?

Yes, you can connect multiple instances to ...READ MORE

answered Aug 1, 2018 in Blockchain by Omkar
• 69,220 points
916 views
+1 vote
1 answer

Can we copy a smart contract?

While the contract is open-source, if you ...READ MORE

answered Apr 7, 2018 in Blockchain by Christine
• 15,790 points
2,150 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP