The Token challenge on Ethernaut - function returning Arrays in console - why?
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract Token {
mapping(address => uint) balances;
uint public totalSupply;
constructor(uint _initialSupply) public {
balances[msg.sender] = totalSupply = _initialSupply;
}
function transfer(address _to, uint _value) public returns (bool) {
require(balances[msg.sender] - _value >= 0);
balances[msg.sender] -= _value;
balances[_to] += _value;
return true;
}
function balanceOf(address _owner) public view returns (uint balance) {
return balances[_owner];
}
}
Before sending a transfer function to the contract in the console await contract.balanceOf("our address")
, it returned this object:
o {negative: 0, words: Array(2), length: 1, red: null}
length: 1
negative: 0
red: null
words: Array(2)
0: 20
length: 2
[[Prototype]]: Array(0)
After calling await contract.transfer(instance, 21000000)
, the same call to that BalanceOf(our address) function await contract.balanceOf("our address")
now returns an array of many more elements:
o {negative: 0, words: Array(11), length: 10, red: null}
length: 10
negative: 0
red: null
words: Array(11)
0: 46108884
1: 67108863
2: 67108863
3: 67108863
4: 67108863
5: 67108863
6: 67108863
7: 67108863
8: 67108863
9: 4194303
length: 11
[[Prototype]]: Array(0)
I was expecting to see a single number of 21000000 as per the function call, but seeing an array of numbers for some reason.
Can anyone explain why this is happening? Is the number being split across multiple entries in an array? How should one reason about this array and how to retrieve the new balance of an address?
To reproduce, just check out the contract in level 5 on https://ethernaut.openzeppelin.com/