CRYPTO NEWS

Problems when trying to initialize array of tokenIDs. Remix stuck "pending"

I would like to initialize an array of custom token IDs (uint32) in my Solidity smart contract.

I tried these two options, but none of them worked:

(1) Calling a function at deployment that would return a memory array of the correct size. Remix gets stuck in "pending" mode.

// SPDX-License-Identifier: MIT  pragma solidity ^0.8.2;  import "@openzeppelin/contracts/token/ERC721/ERC721.sol";  contract TestStackOverflow is ERC721{     constructor() ERC721("Test", "T") {}          uint32 [] public twinsListA = [ 2, 5, 8, 12, 15, 19, 25, 29, 32, 35, 39, 43, 45, 47 ];     uint32 [] public twinsListB = [ 3, 6, 9, 13, 16, 20, 26, 30, 33, 36, 40, 44, 46, 48 ];      uint32 [] public tokenIDs_BW = buildArrays(96, 12, 2, 1);          function buildArrays(uint32 length, uint32 cols, uint32 tot_colourVars, uint32 tot_versions) public returns(uint32[] memory){         uint32 twinNumber;         uint32 tokenID;         uint32 [] memory tokenIDsArray = new uint32[](length);         uint32 counter = 0;                  for (uint32 colourVar=1; colourVar <= tot_colourVars; colourVar++) {             for (uint32 m=1; m <= 48; m++) {                 twinNumber = 0;                 for (uint8 i=0; i<14; i++){                     if (m == twinsListA[i] || m == twinsListB[i]) {                         twinNumber = 1;                         break;                     }                 }                 for (uint32 version=1; version <= tot_versions; version++) {                     tokenID = cols*1000000 + colourVar*10000 + m*100 + twinNumber*10 + version;                     tokenIDsArray[counter] = cols;                     counter++;                 }                }         }             return tokenIDsArray;     }      } 

(2) Calling a function after deployment that would push the custom IDs one by one. But again, if I call buildArrays with e.g. parameters (12, 2, 1), Remix gets stuck in “pending”.

// SPDX-License-Identifier: MIT  pragma solidity ^0.8.2;  import "@openzeppelin/contracts/token/ERC721/ERC721.sol";  contract Test is ERC721 {     constructor() ERC721("Test", "T") {}          uint32 [] public twinsListA = [ 2, 5, 8, 12, 15, 19, 25, 29, 32, 35, 39, 43, 45, 47 ];     uint32 [] public twinsListB = [ 3, 6, 9, 13, 16, 20, 26, 30, 33, 36, 40, 44, 46, 48 ];              uint32 [] public tokenIDs_BW;          function buildArrays(uint8 cols, uint8 tot_colourVars, uint8 tot_versions) public {                  uint8 twinNumber;         uint32 tokenID;                  for (uint8 colourVar=1; colourVar <= tot_colourVars; colourVar++) {             for (uint32 m=1; m <= 48; m++) {                 twinNumber = 0;                 for (uint8 i=0; i<14; i++){                     if (m == twinsListA[i] || m == twinsListB[i]) {                         twinNumber = 1;                         break;                     }                 }                 for (uint8 version=1; version <= tot_versions; version++) {                     tokenID = cols*1000000 + colourVar*10000 + m*100 + twinNumber*10 + version;                     tokenIDs_BW.push(tokenID);                 }                }         }      } } 

The test arrays are actually very small… why this happens and how can I solve the problem? Does the problem depend on the nested loops to build the encoded IDs?

Just got my contract drained- how?

I just got my contract drained, and am trying to understand how. Obviously I’m a noob, played with fire and got burned bad (shouldn’t have big sums of money on contracts). I SHOULD have transferred my funds in every transaction from my EOA. I’m still in shock and numb. Can anyone please help me identify::Listen

I just got my contract drained, and am trying to understand how. Obviously I’m a noob, played with fire and got burned bad (shouldn’t have big sums of money on contracts). I SHOULD have transferred my funds in every transaction from my EOA. I’m still in shock and numb. Can anyone please help me identify the vulnerability? I want to grow past this, I have to. I’m also happy for any input on how I can improve this contract in general, thank you!

The attacker used a different contract he created, he didn’t call my contract directly. The logs show an approval for the total amount from my contract to his, a single transfer to a third address (from my contract), and an approval of 0 from my contract to his (the logs are in this order).

contract arb {  ICurve constant curve = ICurve(0xxxx);  Itest constant test = Itest(0xxxx);  address owner;      constructor() {            IERC20 token1 = IERC20(0xxxx);            IERC20 token2 = IERC20(0xxxx);            token1.approve(0xxxx, 115792089237316195423570985008687907853269984665640564039457584007913129639935);            token1.approve(0xxxx, 115792089237316195423570985008687907853269984665640564039457584007913129639935);            token2.approve(0xxxx, 115792089237316195423570985008687907853269984665640564039457584007913129639935);            token2.approve(0xxxx, 115792089237316195423570985008687907853269984665640564039457584007913129639935);            owner = msg.sender; }  modifier onlyOwner(){     require(msg.sender == owner, "You know why");     _; }  function approve(address token, address spender, uint amount) public returns (bool success){     IERC20 t = IERC20(token);     return t.approve(spender, amount); } function transfer(address token, uint amount) public onlyOwner returns (bool success){     IERC20 t = IERC20(token);     return t.transfer(msg.sender, amount); } function arb1(uint amt) public{     uint amt_out = curve.exchange(0, 1, amt, 0);     uint amt_out2 = test.xxx1(amt_out, 0);     require(amt_out2 > amt, "Lost in arb"); } function arb2(uint amt) public{     uint amt_out = test.xxx2(amt, 0);     uint amt_out2 = curve.exchange(1, 0, amt_out, 0);     require(amt_out2 > amt, "Lost in arb"); } }  interface IERC20 { function transfer(address to, uint tokens) external returns (bool success); function approve(address spender, uint tokens) external returns (bool success); }  interface ICurve { function exchange(uint i, uint j, uint dx, uint min_dy) payable external returns (uint dy); } interface Itest { function xxx1(uint in, uint min_out) external returns (uint out); function xxx2(uint in, uint min_out) external returns (uint out); } 

Thank you for any help.

Problems when trying to initialize array of tokenIDs. Remix stuck "pending"

Shopping cart
There are no products in the cart!
Continue shopping
0