Exemplo n.º 1
0
        public override void Execute()
        {
            // Obtain our value and exponent
            BigInteger value    = Stack.Pop();
            BigInteger exponent = Stack.Pop();

            // Calculate how much gas to deduct: the cost per exponent byte differs per Ethereum release
            byte[]     exponentBytes = BigIntegerConverter.GetBytesWithoutLeadingZeros(exponent);
            BigInteger extraGasCost  = exponentBytes.Length;

            if (Version < EthereumRelease.SpuriousDragon)
            {
                // Pre-Spurious Dragon
                extraGasCost *= GasDefinitions.GAS_EXP_BYTE;
            }
            else
            {
                // Spurious Dragon+
                extraGasCost *= GasDefinitions.GAS_EXP_BYTE_SPURIOUS_DRAGON;
            }

            // Deduct our gas
            GasState.Deduct(extraGasCost);

            // Perform an exponent operation on the two unsigned words off of the top of the stack.
            BigInteger result = BigInteger.ModPow(value, exponent, EVMDefinitions.UINT256_MAX_VALUE + 1);

            // Push the result onto the stack.
            Stack.Push(result);
        }
Exemplo n.º 2
0
Arquivo: RLP.cs Projeto: zutobg/Meadow
 // Type handling
 public static RLPByteArray FromInteger(BigInteger bigInteger, int byteCount = 32, bool removeLeadingZeros = false)
 {
     if (!removeLeadingZeros)
     {
         return(new RLPByteArray(BigIntegerConverter.GetBytes(bigInteger, byteCount)));
     }
     else
     {
         return(new RLPByteArray(BigIntegerConverter.GetBytesWithoutLeadingZeros(bigInteger, byteCount)));
     }
 }