Ethernaut Preservation(Lvl 16) - Different output while using testnet and local network

Here is my solution to Preservation problem.

pragma solidity ^0.8.0;
contract Hack {
    address public timeZone1Library; 
    address public timeZone2Library;
    address public owner;          
    uint storedTime;                

  function setTime(uint256 _time) public {
      owner = msg.sender;
  function getInt() view public returns(uint160) {
      return uint160(bytes20(address(this)));

:computer: Environment
When I am running this on a local network or remix’s JS VM. It works fine.
But when I am using a different network like ropsten or rinkeby. For some reason it does not work. I have written a hardhat script to deploy and make all the transactions.

This is the hardhat script:

  [deployer, acc1] = await ethers.getSigners();
  const LibraryContract = await ethers.getContractFactory("LibraryContract");
  const timezone1 = await LibraryContract.deploy();
  await timezone1.deployed();
  const timezone2 = await LibraryContract.deploy();
  await timezone2.deployed();
  console.log("Timezone 1",timezone1.address);
  console.log("Timezone 2",timezone2.address);

  const Preservation = await ethers.getContractFactory("Preservation");
  let preservation = await Preservation.connect(acc1).deploy(timezone1.address, timezone2.address);
  await preservation.deployed();
  preservation = preservation.connect(deployer);

  const Contract = await ethers.getContractFactory("Hack");
  let contract = await Contract.deploy();
  await contract.deployed();

  console.log("Contract address", contract.address);
  let int = String(await contract.getInt())
  console.log("Int", int)

  console.log("Timezone1 before",await preservation.timeZone1Library())
  let tx = await preservation.setFirstTime(int);
  await tx.wait()
  console.log("Timezone1 after",await preservation.timeZone1Library())
  console.log("deployer", deployer.address);
  console.log("owner before",await preservation.owner());
  tx = await preservation.setFirstTime(int);
  await tx.wait()
  console.log("owner after",await preservation.owner());

Output when I running it on hardhat’s local test network.

Timezone 1 0x5FbDB2315678afecb367f032d93F642f64180aa3
Timezone 2 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
Contract address 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
Int 912823093544680850579175995568783282090442467040
Timezone1 before 0x5FbDB2315678afecb367f032d93F642f64180aa3
Timezone1 after 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
deployer 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
owner before 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
owner after 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

Output when I am running it on ropsten or rinkeby.

Timezone 1 0xD2f776dE54747A8a276d870bC785101AD1147FD9
Timezone 2 0xcF8Cf2f190512DFa5889567f19e2b275d427fDc6
Contract address 0x2F4CEAA209D18B03Aa200437d8254E2c21e6db5a
Int 270037862277511319638229442075343562614885505882
Timezone1 before 0xD2f776dE54747A8a276d870bC785101AD1147FD9
Timezone1 after 0x2F4CEAA209D18B03Aa200437d8254E2c21e6db5a
deployer 0x9CC14A288BB5cb9Ec0e85b606Cb6585BB7ca6a8E
owner before 0x580a28388E292adBB6fCf83fbdb56d5b313D04dA
owner after 0x580a28388E292adBB6fCf83fbdb56d5b313D04dA

Can anyone explain why there is a difference when I change the network.

Thanks in advance

For those who are facing the same issue,
This problem is solved now. The problem was with eth_estimateGas, infuria and other rpc provider where estimating less gas, because of this setFirstTime ran out of gas it never got executed, when I increased the gas manually the function was executed successfully.

1 Like