Skip to content

Commit

Permalink
Merge pull request #409 from iotaledger/alias-state-transition-constr…
Browse files Browse the repository at this point in the history
…ained

Check whether a referenced AliasOutput through an AliasUnlock is state transitioning
  • Loading branch information
luca-moser authored Aug 26, 2022
2 parents f4d98ba + 7165175 commit 05bb3a5
Show file tree
Hide file tree
Showing 3 changed files with 460 additions and 4 deletions.
2 changes: 1 addition & 1 deletion signature_ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (e *Ed25519Signature) Valid(msg []byte, addr *Ed25519Address) error {
// an address is the Blake2b 256 hash of the public key
addrFromPubKey := Ed25519AddressFromPubKey(e.PublicKey[:])
if !bytes.Equal(addr[:], addrFromPubKey[:]) {
return fmt.Errorf("%w: address %s, address from public key %v", ErrEd25519PubKeyAndAddrMismatch, EncodeHex(addr[:]), addrFromPubKey)
return fmt.Errorf("%w: address %s, address from public key %v", ErrEd25519PubKeyAndAddrMismatch, EncodeHex(addr[:]), EncodeHex(addrFromPubKey[:]))
}
if valid := iotagoEd25519.Verify(e.PublicKey[:], msg, e.Signature[:]); !valid {
return fmt.Errorf("%w: address %s, public key %v, signature %v", ErrEd25519SignatureInvalid, EncodeHex(addr[:]), EncodeHex(e.PublicKey[:]), EncodeHex(e.Signature[:]))
Expand Down
16 changes: 15 additions & 1 deletion transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,23 @@ func TxSemanticInputUnlocks() TxSemanticValidationFunc {
if chainID.Empty() {
chainID = chainID.(UTXOIDChainID).FromOutputID(svCtx.WorkingSet.UTXOInputAtIndex(uint16(inputIndex)).Ref())
}

// for alias outputs which are not state transitioning, we do not add it to the set of unlocked chains
if currentAlias, ok := chainConstrOutput.(*AliasOutput); ok {
next, hasNextState := svCtx.WorkingSet.OutChains[chainID]
if !hasNextState {
continue
}
// note that isAlias should never be false in practice,
// but we add it anyway as an additional safeguard
nextAlias, isAlias := next.(*AliasOutput)
if !isAlias || (currentAlias.StateIndex+1 != nextAlias.StateIndex) {
continue
}
}

svCtx.WorkingSet.UnlockedIdents.AddUnlockedChain(chainID.ToAddress(), uint16(inputIndex))
}

}

return nil
Expand Down
Loading

0 comments on commit 05bb3a5

Please sign in to comment.