Solidity: Struct getter (public variable of struct) cannot handle more than 9 members

Created on 28 Mar 2017  路  10Comments  路  Source: ethereum/solidity

I'm trying to add more then 9 data in public struct it's showing me below error

Internal compiler error: Stack too deep, try removing local variables.

enter image description here

if I removed the public keyword from User public user; then works fine or I maintain 9 data in struct then works fine.

contract UserIndendity{

    struct User {
        address userAccount;
        address photo;
        string fName;
        string lName;
        address signature;
        string email;
        uint mno;
        string street;
        string city;
        string state;
        string country;
    }

    User public user;

    function UserIndendity(address _userAccount,address _photo,string _fName,string _lName,address _signature,string _email,uint _mno,string _street,string _city,string _state,string _country){

        user.userAccount=_userAccount;
        user.photo=_photo;
        user.fName=_fName;
        user.lName=_lName;
        user.signature=_signature;
        user.email=_email;
        user.mno=_mno;
        user.street=_street;
        user.city=_city;
        user.state=_state;
        user.country=_country;
    }
}

any one have solution for above issue?

bug

Most helpful comment

string is too heavy due to variable length. Switch everything to bytes32 and will compile.

All 10 comments

string is too heavy due to variable length. Switch everything to bytes32 and will compile.

This is a limitation of the compiler that will hopefully be resolved once we have structs as part of the ABI. Until then, please try the workaround mentioned by @rob-Hitchens . On the other hand: Are you sure that you need separate fields for all the different information as part of the contract? It will be less expensive if you just store everything e.g. json-encoded. Does the smart contract have to access some fields individually?

@chriseth is there any example for json-encoded?

@thackerronak what I meant was the following:

contract UserIdentity{
    string public user;

    function UserIdentity(string _user) {
        user = _user;
    }
}

so you encode everything to json off-chain and send the string to the smart contract. When you want to use the information, you retrieve it and decode it again. This of course prevents you from using the data on chain, unless you implement a json-decoder in solidity.

Marked this as a bug as it shouldn't be an ICE, but an unimplementedFeatureAssert.

has there been a resolution to stack too deep issue?

Documentation tracked in #4261.

@axic unimplemented because the new ABI will solve the issue?

@thackerronak btw, you can now do this if you use the experimental encoder:

pragma experimental ABIEncoderV2;

The stack too deep issue is currently not a bug, but a limitation of the architecture. This won't change until the new code generator is written.
Closing as discussed in https://github.com/ethereum/solidity/pull/6363

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ddeclerck picture ddeclerck  路  3Comments

chriseth picture chriseth  路  4Comments

chriseth picture chriseth  路  3Comments

bshastry picture bshastry  路  3Comments

AnthonyAkentiev picture AnthonyAkentiev  路  3Comments