Failed to execute script at block

It looks like you have an underflow somewhere, which means that you are trying to create a number that is below the minimum representation for the type you are using (UInt64). I would take a look at your arithmetic operations to make sure that is happening, or if you intend to have a negative number, use Int64 instead.