0

I'm working on Ethernaut challenge lvl 1

follow the link or scroll below for the smartcontract code.

I check my addresse in the "contributions" mapping, I add some eth, and I recheck.

what are thoses numbers ? 24035328, 4470348 32047104, 5960464

where is my deposit amount ?

(and what is this "weird" parameter, "red" ?)

img

here's the smartcontract below

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import '@openzeppelin/contracts/math/SafeMath.sol';

contract Fallback {

  using SafeMath for uint256;
  mapping(address => uint) public contributions;
  address payable public owner;

  constructor() public {
    owner = msg.sender;
    contributions[msg.sender] = 1000 * (1 ether);
  }

  modifier onlyOwner {
        require(
            msg.sender == owner,
            "caller is not the owner"
        );
        _;
    }

  function contribute() public payable {
    require(msg.value < 0.001 ether);
    contributions[msg.sender] += msg.value;
    if(contributions[msg.sender] > contributions[owner]) {
      owner = msg.sender;
    }
  }

  function getContribution() public view returns (uint) {
    return contributions[msg.sender];
  }

  function withdraw() public onlyOwner {
    owner.transfer(address(this).balance);
  }

  receive() external payable {
    require(msg.value > 0 && contributions[msg.sender] > 0);
    owner = msg.sender;
  }
}

1 Answer 1

0

Ok, understood a lof of things :

If I just push await contract.contribute({value: 1}), the value handled in the mapping is 1.

With some examples, I understood that await contract.contribute({value: 99999999}) is stored with [32891135, 1] in the mapping, appearing that js is storing 99999999 = 99 999 999 = 32 891 135 + 2^26 x 1

Everything is clear rn.

1
  • Except the red parameter :/
    – Fabien
    Commented Jun 30, 2022 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.