private void OpXor(ParsedOpCode op) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(a ^ b); }
private void OpHash160(ParsedOpCode obj) { var value = MainStack.Pop(); var hash = HashUtil.Ripemd160(HashUtil.Blake256(value)); MainStack.Push(hash); }
private void OpEqual(ParsedOpCode op) { var a = MainStack.Pop(); var b = MainStack.Pop(); MainStack.Push(a.SequenceEqual(b)); }
private void OpSub(ParsedOpCode obj) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(b - a); }
private void OpNumEqual(ParsedOpCode op) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(a == b ? 1 : 0); }
private void OpNumNotEqual(ParsedOpCode obj) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(a != b ? 1 : 0); }
/// <summary> /// Multiplies top two numbers on the stack. /// </summary> /// <param name="obj"></param> private void OpMul(ParsedOpCode obj) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(a * b); }
public void OpCheckSig(ParsedOpCode op, MsgTx transaction) { try { var rawPublicKey = MainStack.Pop(); var rawSignature = MainStack.Pop(); if (rawSignature.Length < 1) { MainStack.Push(false); return; } var signature = rawSignature.Take(rawSignature.Length - 1).ToArray(); var signatureType = (SignatureHashType)rawSignature.Last(); AssertSignatureHashType(signatureType); AssertSignatureEncoding(signature); AssertPublicKeyEncoding(rawPublicKey); var subScript = _script.GetOpCodesWithoutData(rawSignature); var hash = CalculateSignatureHash(subScript, signatureType, (MsgTx)transaction.Clone(), _txIndex); var ecSignature = new ECSignature(signature); var securityService = new ECPublicSecurityService(rawPublicKey); var isValidSignature = securityService.VerifySignature(hash, ecSignature); MainStack.Push(isValidSignature); } catch (ScriptException) { MainStack.Push(false); } }
private void OpLeft(ParsedOpCode op) { var high = MainStack.PopInt32(); var data = MainStack.Pop(); if (data.Length == 0 || high == 0) { MainStack.Push(new byte[0]); } else if (high < 0) { throw new ScriptIndexOutOfRangeException(op.Code, "upper boundary less than zero"); } else if (high > data.Length) { throw new ScriptIndexOutOfRangeException(op.Code, "upper boundary greater than array length"); } else if (high < 0) { throw new ScriptIndexOutOfRangeException(op.Code, "upper boundary less than zero"); } else { var bytes = data.Take(high).ToArray(); MainStack.Push(bytes); } }
private void OpLessThan(ParsedOpCode obj) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(b < a ? 1 : 0); }
private void OpGreaterThanOrEqual(ParsedOpCode obj) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(b > a ? 1 : 0); }
private void OpSubStr(ParsedOpCode op) { var startIndex = MainStack.PopInt32(); var endIndexExclusive = MainStack.PopInt32(); var array = MainStack.Pop(); if (array.Length == 0) { MainStack.Push(new byte[0]); } else if (startIndex < 0 || endIndexExclusive < 0) { throw new ScriptIndexOutOfRangeException(op.Code, "Negative substring index"); } else if (startIndex > array.Length || endIndexExclusive > array.Length) { throw new ScriptIndexOutOfRangeException(op.Code, "Substring index out of bounds"); } else if (startIndex > endIndexExclusive) { throw new ScriptIndexOutOfRangeException(op.Code, "Start index is greater than end index"); } else if (startIndex == endIndexExclusive) { MainStack.Push(new byte[0]); } else { var substr = array.Skip(startIndex).Take(endIndexExclusive - startIndex).ToArray(); MainStack.Push(substr); } }
private void OpMax(ParsedOpCode obj) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(Math.Max(a, b)); }
private void OpBoolOr(ParsedOpCode obj) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); MainStack.Push(a != 0 || b != 0 ? 1 : 0); }
private void OpRoll() { var n = MainStack.PopInt32(); var val = MainStack.Pop(n); MainStack.Push(val); }
private void OpSwap() { var a = MainStack.Pop(); var b = MainStack.Pop(); MainStack.Push(a); MainStack.Push(b); }
private void Op2Rot() { var a = MainStack.Pop(4); var b = MainStack.Pop(4); MainStack.Push(b); MainStack.Push(a); }
private void Op2Over() { var a = MainStack.Peek(2); var b = MainStack.Peek(3); MainStack.Push(b); MainStack.Push(a); }
private void Op2Dup() { var a = MainStack.Peek(0); var b = MainStack.Peek(1); MainStack.Push(b); MainStack.Push(a); }
private void OpWithin(ParsedOpCode obj) { var max = MainStack.PopInt32(); var min = MainStack.PopInt32(); var test = MainStack.PopInt32(); MainStack.Push(min <= test && test < max ? 1 : 0); }
private void OpCat(ParsedOpCode op) { var first = MainStack.Pop(); var second = MainStack.Pop(); var bytes = second.Concat(first).ToArray(); MainStack.Push(bytes); }
private void OpRot() { var a = MainStack.Pop(); var b = MainStack.Pop(); var c = MainStack.Pop(); MainStack.Push(b); MainStack.Push(a); MainStack.Push(c); }
private void Op3Dup() { var a = MainStack.Peek(0); var b = MainStack.Peek(1); var c = MainStack.Peek(2); MainStack.Push(c); MainStack.Push(b); MainStack.Push(a); }
private void Op2Swap() { var a = MainStack.Pop(); var b = MainStack.Pop(); var c = MainStack.Pop(); var d = MainStack.Pop(); MainStack.Push(b); MainStack.Push(a); MainStack.Push(d); MainStack.Push(c); }
private void OpPushData(ParsedOpCode op) { if (op.Code.IsOpN()) { var value = (op.Code - OpCode.OP_1) + 1; MainStack.Push(value); } else { MainStack.Push(op.Data); } }
private void OpMod(ParsedOpCode op) { var a = MainStack.PopInt32(); var b = MainStack.PopInt32(); if (a == 0) { throw new ArithemeticException(op.Code, "Division by zero"); } MainStack.Push(b % a); }
public void Push(int val) { MainStack.Push(val); if (MStack.Count > 0) { MStack.Push(FindMax(val, MStack.Peek())); } else { MStack.Push(val); } }
private void OpIfDup() { var shouldDuplicate = MainStack.PeekBool(); if (!shouldDuplicate) { return; } var bytes = MainStack.Peek(); MainStack.Push(bytes); }
private void OpSha256(ParsedOpCode op) { if (!Options.EnableSha256) { OpNop(op); return; } var data = MainStack.Pop(); var hash = HashUtil.Sha256(data); MainStack.Push(hash); }
public void Push(int input) { int newMax = input; if (AuxiliaryStack.Any()) { var currentMax = AuxiliaryStack.Peek(); if (input < currentMax) { newMax = currentMax; } } AuxiliaryStack.Push(newMax); MainStack.Push(input); }