algorand/pyteal

Source Mapper: possible conflict on Windows

CiottiGiorgio opened this issue · 1 comments

Reporting this on behalf of one of our users @ErikHasselwander.
Discord thread: https://discord.com/channels/491256308461207573/1143656409905504406
PyTeal source mapper seems to apparently generate incorrect mapping while on Windows but correct elsewhere.

Your environment

Windows and WSL.

Steps to reproduce

PyTeal code in both cases

from feature_gates import FeatureGates
FeatureGates.set_sourcemap_enabled(True)

import pyteal as pt


def approval_program() -> pt.Expr:
    def create() -> pt.Expr:
        return pt.Return(pt.Int(1))

    def call() -> pt.Expr:
        return pt.Seq(
            pt.Pop(pt.Sha256(pt.Txn.sender())),
            pt.Return(pt.Int(1))
        )

    return pt.Cond(
        [pt.Global.current_application_id() == pt.Int(0), create()],
        [pt.Int(1), call()]
    )


if __name__ == "__main__":
    print(pt.Compilation(approval_program(), pt.Mode.Application, version=4).compile(
        with_sourcemap=True,
        annotate_teal=True,
        pcs_in_sourcemap=True,
        annotate_teal_headers=True,
        annotate_teal_concise=True,
    ).sourcemap.annotated_teal)
python -m venv venv
./venv/bin/activate.ps1
pip install pyteal=0.25.0
python ./test.py

Expected behaviour (captured on WSL)

// GENERATED TEAL            //    PC    PYTEAL
#pragma version 4            //    (0)   pt.Compilation(approval_program(), pt.Mode.Application, version=4).compile(with_sourcemap=True, annotate_teal=True, pcs_in_sourcemap=True, annotate_teal_headers=True, annotate_teal_concise=True)
global CurrentApplicationID  //    (4)   pt.Global.current_application_id()
int 0                        //    (6)   pt.Int(0)
==                           //    (8)   pt.Global.current_application_id() == pt.Int(0)
bnz main_l4                  //    (9)
int 1                        //    (12)  pt.Int(1)
bnz main_l3                  //    (13)
err                          //    (16)  pt.Cond([pt.Global.current_application_id() == pt.Int(0), create()], [pt.Int(1), call()])
main_l3:                     //          pt.Int(1)
txn Sender                   //    (17)  pt.Txn.sender()
sha256                       //    (19)  pt.Sha256(pt.Txn.sender())
pop                          //    (20)  pt.Pop(pt.Sha256(pt.Txn.sender()))
int 1                        //    (21)  pt.Int(1)
return                       //    (22)  pt.Return(pt.Int(1))
main_l4:                     //          pt.Global.current_application_id() == pt.Int(0)
int 1                        //    (23)  pt.Int(1)
return                       //    (24)  pt.Return(pt.Int(1))

Actual behaviour (captured on Windows)

// GENERATED TEAL            //    PC    PYTEAL
#pragma version 4            //    (0)   super().__init__(None)
global CurrentApplicationID  //    (4)   super().__init__()
int 0                        //    (6)   super().__init__()
==                           //    (8)   super().__init__()
bnz main_l4                  //    (9)
int 1                        //    (12)  super().__init__()
bnz main_l3                  //    (13)
err                          //    (16)  super().__init__()
main_l3:                     //          super().__init__()
txn Sender                   //    (17)  super().__init__()
sha256                       //    (19)  super().__init__()
pop                          //    (20)
int 1                        //    (21)  super().__init__()
return                       //    (22)  super().__init__()
main_l4:                     //          super().__init__()
int 1                        //    (23)  super().__init__()
return                       //    (24)  super().__init__()

Thanks! This doesn't completely surprise me. We'll take a look.