everx-labs/evernode-se

Unobvious operation of these states when updating a smart contract.

Closed this issue · 3 comments

There are two of the easiest smart contracts firstContract and secondContract.
Deploy 'firstContract' smart contract and calling external method contract "setValue", set value a,b=12.
Data state contract: m_value = 24, version = 1. Calling 'updateContractCode' and set code from 'secondContract'. After update smart contract check values version=2 but m_value=0.
Waiting that m_value=24,, because tvm.resetStorage don't calling.
This is inappropriate behavior on upgraded data states to default value.

firstContract code:
`pragma ton-solidity >= 0.57.0;

pragma AbiHeader time;
pragma AbiHeader expire;
pragma AbiHeader pubkey;

contract firstContract {

uint32 nonce_;
uint public m_version = 1;
uint public m_value;

address owner;

constructor(address owner_ ) public {
	tvm.accept();
	owner = owner_;
}

modifier checkOwnerAndAccept {
	require(msg.sender == owner, 120);
	tvm.accept();
	_;
}

function setValue(uint a, uint b) external {
	tvm.rawReserve(1 ton, 0);
	m_value = a + b; 
}

function getOwner() external view responsible returns (address) {
	return {value: 0, flag: 64, bounce: false} owner;

}

function updateContractCode(TvmCell newcode) public view checkOwnerAndAccept {
	tvm.setcode(newcode);
	tvm.setCurrentCode(newcode);
	
	TvmCell stateVars = abi.encode(m_version);
    onCodeUpgrade(stateVars);
}

function onCodeUpgrade(TvmCell stateVars) private pure {}

}`

secondContract code:
`pragma ton-solidity >= 0.57.0;

pragma AbiHeader time;
pragma AbiHeader expire;
pragma AbiHeader pubkey;

contract secondContract {

uint32 nonce_;
uint public m_version; 
uint public m_value;

address owner;

modifier checkOwnerAndAccept {
	require(msg.sender == owner, 110);
	tvm.accept();
	_;
}

function setValue(uint a, uint b) external {
	tvm.rawReserve(1 ton, 0);
	m_value = a + b; 
}

function getOwner() external view responsible returns (address) {
	return {value: 0, flag: 64, bounce: false} owner;

}

function updateContractCode(TvmCell newcode) public checkOwnerAndAccept {
	tvm.setcode(newcode);
	tvm.setCurrentCode(newcode);
	TvmCell stateVars = abi.encode(m_version);

	onCodeUpgrade(stateVars);
}

function onCodeUpgrade(TvmCell stateVars) private {
	(uint version) = abi.decode(stateVars, (uint));
	m_version = version + 1;
}

}`

This bug is not reproducible - code and version was changed but value was not dropped.
Also contract1.setValue should not work regarding accept absence for external message.

@markgenuine please close this PR if this bug does not exist any more. We can not reproduce it.

Ok. I closed it PR and test after, if produce it open yet.