Java Code Examples for org.apache.tuweni.bytes.Bytes32#isZero()

The following examples show how to use org.apache.tuweni.bytes.Bytes32#isZero() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SDivOperation.java    From besu with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(final MessageFrame frame) {
  final Bytes32 value0 = frame.popStackItem();
  final Bytes32 value1 = frame.popStackItem();
  if (value1.isZero()) {
    frame.pushStackItem(Bytes32.ZERO);
  } else {
    BigInteger result = value0.toBigInteger().divide(value1.toBigInteger());
    Bytes resultBytes = Bytes.wrap(result.toByteArray());
    if (resultBytes.size() > 32) {
      resultBytes = resultBytes.slice(resultBytes.size() - 32, 32);
    }

    byte[] padding = new byte[32 - resultBytes.size()];
    Arrays.fill(padding, result.signum() < 0 ? (byte) 0xFF : 0x00);

    frame.pushStackItem(Bytes32.wrap(Bytes.concatenate(Bytes.wrap(padding), resultBytes)));
  }
}
 
Example 2
Source File: SModOperation.java    From besu with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(final MessageFrame frame) {
  final Bytes32 value0 = frame.popStackItem();
  final Bytes32 value1 = frame.popStackItem();

  if (value1.isZero()) {
    frame.pushStackItem(Bytes32.ZERO);
  } else {
    BigInteger b1 = value0.toBigInteger();
    BigInteger b2 = value1.toBigInteger();
    BigInteger result = b1.abs().mod(b2.abs());
    if (b1.signum() < 0) {
      result = result.negate();
    }

    Bytes resultBytes = Bytes.wrap(result.toByteArray());
    if (resultBytes.size() > 32) {
      resultBytes = resultBytes.slice(resultBytes.size() - 32, 32);
    }

    byte[] padding = new byte[32 - resultBytes.size()];
    Arrays.fill(padding, result.signum() < 0 ? (byte) 0xFF : 0x00);

    frame.pushStackItem(Bytes32.wrap(Bytes.concatenate(Bytes.wrap(padding), resultBytes)));
  }
}
 
Example 3
Source File: JumpiOperation.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(final MessageFrame frame) {
  final UInt256 jumpDestination = UInt256.fromBytes(frame.popStackItem());
  final Bytes32 condition = frame.popStackItem();

  if (!condition.isZero()) {
    frame.setPC(jumpDestination.intValue());
  } else {
    frame.setPC(frame.getPC() + getOpSize());
  }
}