I got some questions about the code, I'll post replies here so other reviewers will see them too.
There are transactions in Iota and their bundles. A bundle = one or several transactions. Every transaction can be a message, an output or an input. A message doesn't change balances and can contain any data. An output is an operation that increases the balance of an address. An input is an operation that decreases the balance of an address.
A typical transaction bundle may look like this:
-500 XXX
+400 YYY
+100 ZZZ
0 For Neuropozyne (50mg)
Here we see that XXX sends 400 iotas to YYY and 100 iotas (change) back to himself. There are 4 transactions, -500 is input and +400 and +100 are outputs. So transactions with negative values are possible. 0-value transactions can be ignored when calculating balances.
SaM hashing function is my invention. I used the same principle as was used in Keccak aka SHA-3 and followed all advices that I found in papers analyzing security of other hash functions. It doesn't guarantee that SaM is
cryptographically secure, it's impossible to prove that a particular hashing function is secure (unless it's a balanced bent function which doesn't actually exist), only time can increase assurance that SaM is secure. There is no another trinary function which suits our needs, so not much choice here.
If we assume that SaM is
cryptographically secure then the rest is secure (to some degree defined by the signer), because Iota uses Winternitz one-time signature scheme which is well-studied.
We already contacted cryptographers asking them to review SaM but this process is long, also they, of course, are busy with their own stuff.