Skip to content

Commit e9c62f6

Browse files
committed
CR improvements
1 parent dce49c9 commit e9c62f6

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

algosdk/transaction.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,13 @@ def undictify(d):
25802580
lsig.lmsig = Multisig.undictify(d["lmsig"])
25812581
return lsig
25822582

2583+
def sig_count(self):
2584+
return (
2585+
int(self.sig is not None)
2586+
+ int(self.msig is not None)
2587+
+ int(self.lmsig is not None)
2588+
)
2589+
25832590
def verify(self, public_key):
25842591
"""
25852592
Verifies LogicSig against the transaction's sender address
@@ -2597,9 +2604,10 @@ def verify(self, public_key):
25972604
except error.InvalidProgram:
25982605
return False
25992606

2607+
if self.sig_count() > 1:
2608+
return False
2609+
26002610
if self.sig:
2601-
if self.msig or self.lmsig:
2602-
return False
26032611
verify_key = VerifyKey(public_key)
26042612
try:
26052613
to_sign = constants.logic_prefix + self.logic
@@ -2609,14 +2617,10 @@ def verify(self, public_key):
26092617
return False
26102618

26112619
if self.msig:
2612-
if self.sig or self.lmsig:
2613-
return False
26142620
to_sign = constants.logic_prefix + self.logic
26152621
return self.msig.verify(to_sign)
26162622

26172623
if self.lmsig:
2618-
if self.sig or self.msig:
2619-
return False
26202624
to_sign = (
26212625
constants.multisig_logic_prefix
26222626
+ self.lmsig.address_bytes()
@@ -2790,6 +2794,15 @@ def verify(self) -> bool:
27902794
addr = self.address()
27912795
return self.lsig.verify(encoding.decode_address(addr))
27922796

2797+
def sig_count(self) -> int:
2798+
"""
2799+
Returns the number of cryptographic signatures on the LogicSig
2800+
2801+
Returns:
2802+
int: The number of signatures. Should never exceed 1.
2803+
"""
2804+
return self.lsig.sig_count()
2805+
27932806
def address(self) -> str:
27942807
"""
27952808
Get the address of this LogicSigAccount.
@@ -2800,6 +2813,9 @@ def address(self) -> str:
28002813
If the LogicSig is not delegated to another account, this will return an
28012814
escrow address that is the hash of the LogicSig's program code.
28022815
"""
2816+
if self.sig_count() > 1:
2817+
raise error.LogicSigOverspecifiedSignature
2818+
28032819
if self.lsig.sig:
28042820
if not self.sigkey:
28052821
raise error.LogicSigSigningKeyMissing

tests/unit_tests/test_logicsig.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,17 @@ def test_LogicSig_single_delegated_different_sender(self):
472472
sender = TestLogicSigTransaction.otherAddr
473473
self._test_sign_txn(lsig, sender, None, False)
474474

475-
def test_LogicSig_msig_delegated(self):
475+
def test_LogicSig_lmsig_delegated(self):
476476
lsig = transaction.LogicSigAccount(sampleProgram, sampleArgs).lsig
477477
lsig.sign(sampleAccount1, sampleMsig)
478478
lsig.append_to_multisig(sampleAccount2)
479479

480-
print(base64.b64encode(lsig.lmsig.subsigs[0].signature))
481-
print(base64.b64encode(lsig.lmsig.subsigs[1].signature))
482480
sender = sampleMsig.address()
483481
# from: msgpacktool -e < tests/unit_tests/msig_delegated.txn | base64
484482
expected = "gqRsc2lng6NhcmeSxAEBxAICA6FsxAUBIAEBIqVsbXNpZ4Omc3Vic2lnk4KicGvEIBt+wLBL6mG3lpCX5sv0B+EIpwU1HQvJir6xIgmoq4F4oXPEQIwzZcSx0RNw8j9w13dGn+HZR3m/TY1kgXZJNe94TMx2V2zA4O/pwUb6YHba+s5V7przG3aOvDK07BosjD3AZwaConBrxCAJYzIJU3OJ8HVnEXc5kcfQPhtzyMT1K/av8BqiXPnCcaFzxEBPVtR92cCxahX1iGTp50PVMQkf969ssoHfNA0VOiNupdkXc9n/l2WO9+pj8Ddozf4ovorGgnrzca3ZhKc46uUNgaJwa8Qg5/D4TQaBHfnzHI2HixFV9GcdUaGFwgCQhmf0SVhwaKGjdGhyAqF2AaN0eG6Ko2FtdM0TiKNmZWXOAANPqKJmds4ADtbco2dlbq10ZXN0bmV0LXYzMS4womdoxCAmCyAJoJOohot5WHIvpeVG7eftF+TYXEx4r7BFJpDt0qJsds4ADtrEpG5vdGXECLRReTn8+tJxo3JjdsQgtMYiaKTDNVD1im3UuMojnJ8dELNBqn4aNuPOYfv8+Yqjc25kxCCNkrSJkAFzoE36Q1mjZmpq/OosQqBd2cH3PuulR4A36aR0eXBlo3BheQ=="
485483
self._test_sign_txn(lsig, sender, expected)
486484

487-
def test_LogicSig_msig_delegated_different_sender(self):
485+
def test_LogicSig_lmsig_delegated_different_sender(self):
488486
lsig = transaction.LogicSigAccount(sampleProgram, sampleArgs).lsig
489487
lsig.sign(sampleAccount1, sampleMsig)
490488
lsig.append_to_multisig(sampleAccount2)

0 commit comments

Comments
 (0)