tronprotocol / java-tron

Java implementation of the Tron whitepaper
GNU Lesser General Public License v3.0
3.64k stars 1.36k forks source link

Out of Memory when 'MSTORE' operation executing on tron private chain #5854

Open 0xarmaansidhu opened 3 weeks ago

0xarmaansidhu commented 3 weeks ago
This is a contract i deploy on a tron private chain , when i trigger the fucntion like this 
I get this error
->>Out of Memory when 'MSTORE' operation executing

TRIGGER

  await instance.storeAddresses([
    "<--ADDRESS-->",
    "<--ADDRESS-->",
  ])

CONTRACT

contract AddressArrayContract {
    address[] public addresses;

    // Function to accept an array of addresses and store them
    function storeAddresses(address[] memory _addresses) external {
        addresses = _addresses;
    }

    // Function to retrieve the stored addresses
    function getStoredAddresses() external view returns (address[] memory) {
        return addresses;
    }
}

COMPLETE ERROR

    "receipt": {
        "energy_usage": 150000000,
        "energy_usage_total": 150000000,
        "net_fee": 411,
        "result": "OUT_OF_MEMORY"
    },
    "result": "FAILED",
    "resMessage": "Out of Memory when 'MSTORE' operation executing"
yanghang8612 commented 3 weeks ago

Can you provide the parameters you passed in when calling the storeAddresses method?

yanghang8612 commented 3 weeks ago

Also please provide the version of your private chain, are you using the latest v4.7.5?

0xarmaansidhu commented 3 weeks ago

I am using 4.7.3 and the parameters pass were an array of address @yanghang8612

0xarmaansidhu commented 3 weeks ago

i find that the error mostly is when we take an array as an input and if i replace "memory" with "calldata" it works. @yanghang8612

yanghang8612 commented 3 weeks ago

OK got it. We need to know more detailed information about the transaction. Please use the /wallet/gettransactionbyid interface to query the transaction that generated your out of memory exception and provide the results.

0xarmaansidhu commented 3 weeks ago

i have provided it above

    "receipt": {
        "energy_usage": 150000000,
        "energy_usage_total": 150000000,
        "net_fee": 411,
        "result": "OUT_OF_MEMORY"
    },
    "result": "FAILED",
    "resMessage": "Out of Memory when 'MSTORE' operation executing"

@yanghang8612

0xarmaansidhu commented 3 weeks ago

also when i use a function such as, is there a bug or a problem in using "memory" data location?

    function ada(address[] calldata _addresses) external returns (address) {
        address[] memory addressesa = new address[](_addresses.length);
        return addressesa[0];
    }

wallet/gettransactioninfobyid

{
    "id": "c170dd49601b1605aec9afa9e03f4c5774d1a2e58c055cae0c2ef64eda7ad50c",
    "fee": 411,
    "blockNumber": 1539185,
    "blockTimeStamp": 1718092086000,
    "contractResult": [
        ""
    ],
    "contract_address": "PXoMJ2AaweRtij2c6PXmJ9yoiciW3d4rT2",
    "receipt": {
        "energy_usage": 150000000,
        "energy_usage_total": 150000000,
        "net_fee": 411,
        "result": "BAD_JUMP_DESTINATION"
    },
    "result": "FAILED",
    "resMessage": "Operation with pc isn't 'JUMPDEST': PC[96];"
}

@yanghang8612

yanghang8612 commented 3 weeks ago

Please use the /wallet/gettransactionbyid interface to query transactions

0xarmaansidhu commented 3 weeks ago

its literally that only, in the previous comment

yanghang8612 commented 3 weeks ago

Yes, I noticed. But you are using gettransactioninfobyid, not gettransactionbyid. Note that they are actually different.

0xarmaansidhu commented 3 weeks ago

OH my bad here is the result

{
    "ret": [
        {
            "contractRet": "BAD_JUMP_DESTINATION"
        }
    ],
    "signature": [
        "a48226208628582087828363325fb5d83580254a4737eb4045ffe218f5d052f260e3929846511b71a89cb6eeb8837c3d295be0a81681dbb58906d51707c4e1ef1c"
    ],
    "txID": "c170dd49601b1605aec9afa9e03f4c5774d1a2e58c055cae0c2ef64eda7ad50c",
    "raw_data": {
        "contract": [
            {
                "parameter": {
                    "value": {
                        "data": "8e94bc0100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000ce7ae2271e3d76aa2cc739db92ca0e81ec068fac000000000000000000000000179fd8d0739795e9059c0dfa8ead06fee02cf23e",
                        "owner_address": "PAeBgr7KWDg2hCCcABqCW3Uvm1PDXCzYMk",
                        "contract_address": "PXoMJ2AaweRtij2c6PXmJ9yoiciW3d4rT2"
                    },
                    "type_url": "type.googleapis.com/protocol.TriggerSmartContract"
                },
                "type": "TriggerSmartContract"
            }
        ],
        "ref_block_bytes": "7c70",
        "ref_block_hash": "9689b27092a4c1a8",
        "expiration": 1718092143000,
        "fee_limit": 150000000,
        "timestamp": 1718092085712
    },
    "raw_data_hex": "0a027c7022089689b27092a4c1a84098b396b280325af001081f12eb010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412b5010a15371681f19d768097d9327ee3825f57380f7af722fc121537fe985914dec94201e1d279456367fca8d147a8592284018e94bc0100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000ce7ae2271e3d76aa2cc739db92ca0e81ec068fac000000000000000000000000179fd8d0739795e9059c0dfa8ead06fee02cf23e70d0f392b28032900180a3c347"
}
yanghang8612 commented 3 weeks ago

Okay, please check the deployment contract information via /wallet/getcontractinfo. Contract address is PXoMJ2AaweRtij2c6PXmJ9yoiciW3d4rT2 in your previous comment. In addition, which version of Solidity compiler you used?

0xarmaansidhu commented 3 weeks ago

/getcontractinfo

{
    "runtimecode": "608060405234801561001057600080fd5b506004361061004c5760003560e01c80630bc1f4861461005157806339e343ac146100b05780638e94bc0114610168578063edf26d9b1461020b575b600080fd5b610059610263565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561009c578082015181840152602081019050610081565b505050509050019250505060405180910390f35b610166600480360360208110156100c657600080fd5b81019080803590602001906401000000008111156100e357600080fd5b8201836020820111156100f557600080fd5b8035906020019184602083028401116401000000008311171561011757600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506102f1565b005b6101df6004803603602081101561017e57600080fd5b810190808035906020019064010000000081111561019b57600080fd5b8201836020820111156101ad57600080fd5b803590602001918460208302840111640100000000831117156101cf57600080fd5b909192939192939050505061030b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102376004803603602081101561022157600080fd5b8101908080359060200190929190505050610379565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b606060008054806020026020016040519081016040528092919081815260200182805480156102e757602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161029d575b5050505050905090565b80600090805190602001906103079291906103b5565b5050565b600060608383905067ffffffffffffffff8111801561032957600080fd5b506040519080825280602002602001820160405280156103585781602001602082028036833780820191505090505b5090508060008151811061036857fe5b602002602001015191505092915050565b6000818154811061038657fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b82805482825590600052602060002090810192821561042e579160200282015b8281111561042d5782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550916020019190600101906103d5565b5b50905061043b919061043f565b5090565b5b8082111561047657600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905550600101610440565b509056fea26469706673582212200aa203e8e41916d08979677ac270f3577e83ad1b2112c547236b8b77b40fb59f64736f6c63430007000033",
    "smart_contract": {
        "bytecode": "608060405234801561001057600080fd5b506104b0806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80630bc1f4861461005157806339e343ac146100b05780638e94bc0114610168578063edf26d9b1461020b575b600080fd5b610059610263565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561009c578082015181840152602081019050610081565b505050509050019250505060405180910390f35b610166600480360360208110156100c657600080fd5b81019080803590602001906401000000008111156100e357600080fd5b8201836020820111156100f557600080fd5b8035906020019184602083028401116401000000008311171561011757600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506102f1565b005b6101df6004803603602081101561017e57600080fd5b810190808035906020019064010000000081111561019b57600080fd5b8201836020820111156101ad57600080fd5b803590602001918460208302840111640100000000831117156101cf57600080fd5b909192939192939050505061030b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102376004803603602081101561022157600080fd5b8101908080359060200190929190505050610379565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b606060008054806020026020016040519081016040528092919081815260200182805480156102e757602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161029d575b5050505050905090565b80600090805190602001906103079291906103b5565b5050565b600060608383905067ffffffffffffffff8111801561032957600080fd5b506040519080825280602002602001820160405280156103585781602001602082028036833780820191505090505b5090508060008151811061036857fe5b602002602001015191505092915050565b6000818154811061038657fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b82805482825590600052602060002090810192821561042e579160200282015b8281111561042d5782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550916020019190600101906103d5565b5b50905061043b919061043f565b5090565b5b8082111561047657600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905550600101610440565b509056fea26469706673582212200aa203e8e41916d08979677ac270f3577e83ad1b2112c547236b8b77b40fb59f64736f6c63430007000033",
        "consume_user_resource_percent": 100,
        "origin_address": "PAeBgr7KWDg2hCCcABqCW3Uvm1PDXCzYMk",
        "abi": {
            "entrys": [
                {
                    "outputs": [
                        {
                            "type": "address"
                        }
                    ],
                    "inputs": [
                        {
                            "name": "_addresses",
                            "type": "address[]"
                        }
                    ],
                    "name": "aa",
                    "stateMutability": "Nonpayable",
                    "type": "Function"
                },
                {
                    "outputs": [
                        {
                            "type": "address"
                        }
                    ],
                    "inputs": [
                        {
                            "type": "uint256"
                        }
                    ],
                    "name": "addresses",
                    "stateMutability": "View",
                    "type": "Function"
                },
                {
                    "outputs": [
                        {
                            "type": "address[]"
                        }
                    ],
                    "name": "getStoredAddresses",
                    "stateMutability": "View",
                    "type": "Function"
                },
                {
                    "inputs": [
                        {
                            "name": "_addresses",
                            "type": "address[]"
                        }
                    ],
                    "name": "storeAddresses",
                    "stateMutability": "Nonpayable",
                    "type": "Function"
                }
            ]
        },
        "origin_energy_limit": 10000000,
        "contract_address": "PXoMJ2AaweRtij2c6PXmJ9yoiciW3d4rT2",
        "code_hash": "96a2bde99ce9d51d33bf13c409ca68f2e2df5f70b83c51c12ec01ded6e4c3626"
    },
    "contract_state": {
        "update_cycle": 4734
    }
}

solidity compiler version 0.7.0

yanghang8612 commented 3 weeks ago

We were unable to reproduce this BAD_JUMP_DESTINATION error. Below is the transaction I sent on the private chain and the result of the execution.

---[Tx]---
{
    "ret":[
        {
            "contractRet":"SUCCESS"
        }
    ],
    "signature":[
        "0ece065dc4395cbdcc1299191a300f81e4f00c0d606a423af25db76ee61626384e3df590b32b918562b3bcedaadda980d5c423a6cb2eb1535873d9c0dfbc047201"
    ],
    "txID":"259e88213dc57b6a0aa69fd419df2230d568ff8610d16bbd93ba3e133ba621e8",
    "raw_data":{
        "contract":[
            {
                "parameter":{
                    "value":{
                        "data":"8e94bc0100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000ce7ae2271e3d76aa2cc739db92ca0e81ec068fac000000000000000000000000179fd8d0739795e9059c0dfa8ead06fee02cf23e",
                        "owner_address":"PL7NRg2x4bujTKVLQ56EuCngFom6mgRsHH",
                        "contract_address":"PUL8cMHkEtfBnHTQbsw4bQJmPUuaP1HnPY"
                    },
                    "type_url":"type.googleapis.com/protocol.TriggerSmartContract"
                },
                "type":"TriggerSmartContract"
            }
        ],
        "ref_block_bytes":"0044",
        "ref_block_hash":"3525c4f133b57e1b",
        "expiration":1718181425961,
        "fee_limit":1000000000,
        "timestamp":1718159825948
    }
}
---[TxInfo]---
{
    "id": "259e88213dc57b6a0aa69fd419df2230d568ff8610d16bbd93ba3e133ba621e8",
    "fee": 69500,
    "blockNumber": 70,
    "blockTimeStamp": 1718159829000,
    "contractResult": [
        "0000000000000000000000000000000000000000000000000000000000000000"
    ],
    "contract_address": "PUL8cMHkEtfBnHTQbsw4bQJmPUuaP1HnPY",
    "receipt": {
        "energy_fee": 69500,
        "energy_usage_total": 695,
        "net_usage": 412,
        "result": "SUCCESS"
    }
}

Here is the information about the contract created using the same code.

{
    "smart_contract": {
        "origin_address": "PL7NRg2x4bujTKVLQ56EuCngFom6mgRsHH",
        "contract_address": "PUL8cMHkEtfBnHTQbsw4bQJmPUuaP1HnPY",
        "bytecode": "608060405234801561001057600080fd5b506104b0806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80630bc1f4861461005157806339e343ac146100b05780638e94bc0114610168578063edf26d9b1461020b575b600080fd5b610059610263565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561009c578082015181840152602081019050610081565b505050509050019250505060405180910390f35b610166600480360360208110156100c657600080fd5b81019080803590602001906401000000008111156100e357600080fd5b8201836020820111156100f557600080fd5b8035906020019184602083028401116401000000008311171561011757600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506102f1565b005b6101df6004803603602081101561017e57600080fd5b810190808035906020019064010000000081111561019b57600080fd5b8201836020820111156101ad57600080fd5b803590602001918460208302840111640100000000831117156101cf57600080fd5b909192939192939050505061030b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102376004803603602081101561022157600080fd5b8101908080359060200190929190505050610379565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b606060008054806020026020016040519081016040528092919081815260200182805480156102e757602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161029d575b5050505050905090565b80600090805190602001906103079291906103b5565b5050565b600060608383905067ffffffffffffffff8111801561032957600080fd5b506040519080825280602002602001820160405280156103585781602001602082028036833780820191505090505b5090508060008151811061036857fe5b602002602001015191505092915050565b6000818154811061038657fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b82805482825590600052602060002090810192821561042e579160200282015b8281111561042d5782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550916020019190600101906103d5565b5b50905061043b919061043f565b5090565b5b8082111561047657600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905550600101610440565b509056fea26469706673582212200aa203e8e41916d08979677ac270f3577e83ad1b2112c547236b8b77b40fb59f64736f6c63430007000033",
        "consume_user_resource_percent": 100,
        "name": "Test",
        "origin_energy_limit": 1,
        "code_hash": "96a2bde99ce9d51d33bf13c409ca68f2e2df5f70b83c51c12ec01ded6e4c3626"
    },
    "runtimecode": "608060405234801561001057600080fd5b506004361061004c5760003560e01c80630bc1f4861461005157806339e343ac146100b05780638e94bc0114610168578063edf26d9b1461020b575b600080fd5b610059610263565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561009c578082015181840152602081019050610081565b505050509050019250505060405180910390f35b610166600480360360208110156100c657600080fd5b81019080803590602001906401000000008111156100e357600080fd5b8201836020820111156100f557600080fd5b8035906020019184602083028401116401000000008311171561011757600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506102f1565b005b6101df6004803603602081101561017e57600080fd5b810190808035906020019064010000000081111561019b57600080fd5b8201836020820111156101ad57600080fd5b803590602001918460208302840111640100000000831117156101cf57600080fd5b909192939192939050505061030b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102376004803603602081101561022157600080fd5b8101908080359060200190929190505050610379565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b606060008054806020026020016040519081016040528092919081815260200182805480156102e757602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161029d575b5050505050905090565b80600090805190602001906103079291906103b5565b5050565b600060608383905067ffffffffffffffff8111801561032957600080fd5b506040519080825280602002602001820160405280156103585781602001602082028036833780820191505090505b5090508060008151811061036857fe5b602002602001015191505092915050565b6000818154811061038657fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b82805482825590600052602060002090810192821561042e579160200282015b8281111561042d5782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550916020019190600101906103d5565b5b50905061043b919061043f565b5090565b5b8082111561047657600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905550600101610440565b509056fea26469706673582212200aa203e8e41916d08979677ac270f3577e83ad1b2112c547236b8b77b40fb59f64736f6c63430007000033",
    "contract_state": {
        "energy_usage": 1666
    }
}
yanghang8612 commented 3 weeks ago

As for the out of memory exception, please use the /wallet/gettransactionbyid interface to query the transaction that generated the exception and provide the query result for our analysis.

yanghang8612 commented 3 weeks ago

The version of java-tron you are using is v4.7.3, are you using the official release version? If not, please retry deploying and calling the contract again using the official release version.

0xarmaansidhu commented 3 weeks ago

We cannot redeploy as the chain is already live, can you give me other alternative?

yanghang8612 commented 3 weeks ago

Have you made certain code changes on the private chain?

0xarmaansidhu commented 3 weeks ago

Just the small changes like address generation hex, but not much .

1)Can you tell me one thing, if i have a network with around 40 nodes and 27 sr nodes can i still change the build(.jar file) on each sr?

2) Will it effect the network if i restart each node with the new build?

yanghang8612 commented 3 weeks ago

If you have important test data on the private chain, then we recommend you to backup the data and then use the official jar file to replace and restart the private chain. Since we have no way to know what code you have modified on the private chain, there is no way to assess the impact of restarting the private chain with the official jar file. If you can provide the code changes, it will be very helpful for us to follow up your issue.

0xarmaansidhu commented 3 weeks ago

So you mean to say that i have a backup for the output directory and then start the chain again with new build and past the output directory,will this work?

yanghang8612 commented 3 weeks ago

We tried to reproduce your faulty transaction but were unsuccessful.

We have not yet been able to locate the problem. Since you have made some code changes on the private chain, to rule out the possibility that this may be a factor, we recommend that you restart the private chain with the official jar file and send the same transaction again to see if the same issue occurs.

yanghang8612 commented 3 weeks ago

Or you can resend the same transaction now to see if the BAD_JUMP_DESTINATION exception is still generated to confirm if the exception can be reproduced on your current private chain.

0xarmaansidhu commented 3 weeks ago

yea i retried the transaction , the error still persists. Can you help me with this? Just assume i fix this in our code and then want to restart the chain, we create a build file, so to run it with the same database what will be the process?

yanghang8612 commented 3 weeks ago

You can try deploying this contract on the nile testnet and sending the same transactions to test if the exception still occurs.

0xarmaansidhu commented 3 weeks ago

No it doesn't, but i am concerned about my private chain,can you pls answer my above query Just assume i fix this in our code and then want to restart the chain, we create a build file, so to run it with the same database what will be the process?

zeusoo001 commented 3 weeks ago

@0xarmaansidhu It is possible that your modification did not take into account compatibility, which may cause data unavailability. If you want to keep the current private chain, you can copy the database and then test it with the copied database.

0xarmaansidhu commented 3 weeks ago

@zeusoo001 can you guide my how to do that,any doc which might be present? Cause it is very important for us and our protocol.

0xarmaansidhu commented 2 weeks ago

@zeusoo001 @yanghang8612 anything on this?

tomatoishealthy commented 2 weeks ago

Just the small changes like address generation hex, but not much .

1)Can you tell me one thing, if i have a network with around 40 nodes and 27 sr nodes can i still change the build(.jar file) on each sr?

  1. Will it effect the network if i restart each node with the new build?
  1. Yes, for safety reasons, it is recommended that you replace one node first, observe whether it is normal, and then replace all nodes in sequence. In addition, to ensure that the data is not damaged, it is recommended to back up the database.

  2. No, but it is recommended not to restart more than 1/3 of the SR nodes at one time

0xarmaansidhu commented 1 week ago

@tomatoishealthy can you look into the original issue where "address[] memory _addresses" doesnot compile and reverts with a "BAD_JUMP_DESTINATION" error

yanghang8612 commented 1 week ago

Perhaps you could refer to this comment.