I am getting following issues:

compilation warning: [warning] Error in generated Michelson contract: previous error

deployment error: "TezosOperationError: (permanent) proto.016-PtMumbai.michelson_v1.bad_stack " issue while deploying a contract. I am using for loop in the elements of a set in a function as below:

self.data.link_names = self.data.link_names.add('btp://77.tezos/tz1e2HPzZWBsuExFSM4XDBtQiFnaUB5hiPnW')
sp.for item in self.data.link_names.elements():

In the above case if i use "if " instead of for it doesn’t give this error.

sp.if sp.len(self.data.list_link_names.elements()> 0:
  • Please share the minimal code with a scenario that produces this error.
    – Jordan_tez
    Commented Apr 6, 2023 at 6:48

2 Answers 2


I guess the issue might be the way you are adding elements to the set.

Instead of

self.data.link_names = self.data.link_names.add('btp://77.tezos/tz1e2HPzZWBsuExFSM4XDBtQiFnaUB5hiPnW')



This will solve the issue

  • Actually this alos didn't solve the issue, the issue is from lthe line sp.for. I if remove for statement it works.
    – theBatMan
    Commented Apr 6, 2023 at 4:05
  • @theBatMan I am assuming that link_names is of set data type. According to that you won't be able to iterate through set elements. I'll suggest you to use list. Commented Apr 6, 2023 at 17:23

The above issue was from sp.failwith("Empty list") and sp.failwith("Only one element") in the below function. When I commented out those lines it worked. I is a issue with sp.failwith() which i requested smartpy dev Jordan to investigate further.

def split_btp_address(self, base):
        Split the BTP Address format i.e. btp://1234.iconee/0x123456789
        into Network_address (1234.iconee) and Server_address (0x123456789)
        :param base: String base BTP Address format to be split
        :return: The resulting strings of Network_address and Server_address
        sp.set_type(base, sp.TString)
        # sep = sp.local("sep", "/")
        prev_idx = sp.local("prev_idx", 0)
        result = sp.local("result", [])
        sp.for idx in sp.range(0, sp.len(base)):
            sp.if sp.slice(base, idx, 1).open_some() == "/":
                result.value.push(sp.slice(base, prev_idx.value, sp.as_nat(idx - prev_idx.value)).open_some())
                prev_idx.value = idx + 1
        sp.if sp.len(base) > 0:
            result.value.push(sp.slice(base, prev_idx.value, sp.as_nat(sp.len(base) - prev_idx.value)).open_some())
        inverted_list = sp.local("my_list", result.value)
        last = sp.local("last", "")
        penultimate = sp.local("penultimate", "")
        with sp.match_cons(inverted_list.value) as l:
            last.value = l.head
            inverted_list.value = l.tail
        # with sp.else_():
        #     sp.failwith("Empty list")
        with sp.match_cons(inverted_list.value) as l:
            penultimate.value = l.head
        # with sp.else_():
        #     sp.failwith("Only one element")
        return sp.pair(last.value, penultimate.value)

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.