use of org.hyperledger.besu.evm.operation.JumpOperation in project besu by hyperledger.
the class JumpOperationTest method longContractsValidate.
@Test
public void longContractsValidate() {
final JumpOperation operation = new JumpOperation(gasCalculator);
final Bytes longCode = Bytes.fromHexString("0x60006000351461001157600050610018565b6101016020525b60016000351461002a5760005061002f565b326020525b60026000351461004157600050610046565b336020525b6003600035146100585760005061005d565b306020525b60046000351461006f57600050610075565b60016020525b60005160005260006020351461008d576000506100b6565b5a600052602051315060165a60005103036000555a600052602051315060165a60005103036001555b6001602035146100c8576000506100f1565b5a6000526020513b5060165a60005103036000555a6000526020513b5060165a60005103036001555b6002602035146101035760005061012c565b5a6000526020513f5060165a60005103036000555a6000526020513f5060165a60005103036001555b60036020351461013e5760005061017a565b6106a5610100525a600052602060006101006020513c60205a60005103036000555a600052602060006101006020513c60205a60005103036001555b00");
final MessageFrame longContract = createMessageFrameBuilder(100L).pushStackItem(UInt256.fromHexString("0x12c")).code(Code.createLegacyCode(longCode, Hash.hash(longCode))).build();
longContract.setPC(255);
final OperationResult result = operation.execute(longContract, evm);
assertThat(result.getHaltReason()).isEmpty();
}
use of org.hyperledger.besu.evm.operation.JumpOperation in project besu by hyperledger.
the class MainnetEVMs method registerFrontierOperations.
public static void registerFrontierOperations(final OperationRegistry registry, final GasCalculator gasCalculator) {
registry.put(new AddOperation(gasCalculator));
registry.put(new MulOperation(gasCalculator));
registry.put(new SubOperation(gasCalculator));
registry.put(new DivOperation(gasCalculator));
registry.put(new SDivOperation(gasCalculator));
registry.put(new ModOperation(gasCalculator));
registry.put(new SModOperation(gasCalculator));
registry.put(new ExpOperation(gasCalculator));
registry.put(new AddModOperation(gasCalculator));
registry.put(new MulModOperation(gasCalculator));
registry.put(new SignExtendOperation(gasCalculator));
registry.put(new LtOperation(gasCalculator));
registry.put(new GtOperation(gasCalculator));
registry.put(new SLtOperation(gasCalculator));
registry.put(new SGtOperation(gasCalculator));
registry.put(new EqOperation(gasCalculator));
registry.put(new IsZeroOperation(gasCalculator));
registry.put(new AndOperation(gasCalculator));
registry.put(new OrOperation(gasCalculator));
registry.put(new XorOperation(gasCalculator));
registry.put(new NotOperation(gasCalculator));
registry.put(new ByteOperation(gasCalculator));
registry.put(new Keccak256Operation(gasCalculator));
registry.put(new AddressOperation(gasCalculator));
registry.put(new BalanceOperation(gasCalculator));
registry.put(new OriginOperation(gasCalculator));
registry.put(new CallerOperation(gasCalculator));
registry.put(new CallValueOperation(gasCalculator));
registry.put(new CallDataLoadOperation(gasCalculator));
registry.put(new CallDataSizeOperation(gasCalculator));
registry.put(new CallDataCopyOperation(gasCalculator));
registry.put(new CodeSizeOperation(gasCalculator));
registry.put(new CodeCopyOperation(gasCalculator));
registry.put(new GasPriceOperation(gasCalculator));
registry.put(new ExtCodeCopyOperation(gasCalculator));
registry.put(new ExtCodeSizeOperation(gasCalculator));
registry.put(new BlockHashOperation(gasCalculator));
registry.put(new CoinbaseOperation(gasCalculator));
registry.put(new TimestampOperation(gasCalculator));
registry.put(new NumberOperation(gasCalculator));
registry.put(new DifficultyOperation(gasCalculator));
registry.put(new GasLimitOperation(gasCalculator));
registry.put(new PopOperation(gasCalculator));
registry.put(new MLoadOperation(gasCalculator));
registry.put(new MStoreOperation(gasCalculator));
registry.put(new MStore8Operation(gasCalculator));
registry.put(new SLoadOperation(gasCalculator));
registry.put(new SStoreOperation(gasCalculator, SStoreOperation.FRONTIER_MINIMUM));
registry.put(new JumpOperation(gasCalculator));
registry.put(new JumpiOperation(gasCalculator));
registry.put(new PCOperation(gasCalculator));
registry.put(new MSizeOperation(gasCalculator));
registry.put(new GasOperation(gasCalculator));
registry.put(new JumpDestOperation(gasCalculator));
registry.put(new ReturnOperation(gasCalculator));
registry.put(new InvalidOperation(gasCalculator));
registry.put(new StopOperation(gasCalculator));
registry.put(new SelfDestructOperation(gasCalculator));
registry.put(new CreateOperation(gasCalculator));
registry.put(new CallOperation(gasCalculator));
registry.put(new CallCodeOperation(gasCalculator));
// Register the PUSH1, PUSH2, ..., PUSH32 operations.
for (int i = 1; i <= 32; ++i) {
registry.put(new PushOperation(i, gasCalculator));
}
// Register the DUP1, DUP2, ..., DUP16 operations.
for (int i = 1; i <= 16; ++i) {
registry.put(new DupOperation(i, gasCalculator));
}
// Register the SWAP1, SWAP2, ..., SWAP16 operations.
for (int i = 1; i <= 16; ++i) {
registry.put(new SwapOperation(i, gasCalculator));
}
// Register the LOG0, LOG1, ..., LOG4 operations.
for (int i = 0; i < 5; ++i) {
registry.put(new LogOperation(i, gasCalculator));
}
}
use of org.hyperledger.besu.evm.operation.JumpOperation in project besu by hyperledger.
the class JumpOperationTest method shouldHaltWithInvalidJumDestinationWhenLocationIsOutsideOfCodeRange.
@Test
public void shouldHaltWithInvalidJumDestinationWhenLocationIsOutsideOfCodeRange() {
final JumpOperation operation = new JumpOperation(gasCalculator);
final Bytes jumpBytes = Bytes.fromHexString("0x6801000000000000000c565b00");
final MessageFrame frameDestinationGreaterThanCodeSize = createMessageFrameBuilder(100L).pushStackItem(UInt256.fromHexString("0xFFFFFFFF")).code(Code.createLegacyCode(jumpBytes, Hash.hash(jumpBytes))).build();
frameDestinationGreaterThanCodeSize.setPC(CURRENT_PC);
final OperationResult result = operation.execute(frameDestinationGreaterThanCodeSize, evm);
assertThat(result.getHaltReason()).contains(ExceptionalHaltReason.INVALID_JUMP_DESTINATION);
final Bytes badJump = Bytes.fromHexString("0x60045600");
final MessageFrame frameDestinationEqualsToCodeSize = createMessageFrameBuilder(100L).pushStackItem(UInt256.fromHexString("0x04")).code(Code.createLegacyCode(badJump, Hash.hash(badJump))).build();
frameDestinationEqualsToCodeSize.setPC(CURRENT_PC);
final OperationResult result2 = operation.execute(frameDestinationEqualsToCodeSize, evm);
assertThat(result2.getHaltReason()).contains(ExceptionalHaltReason.INVALID_JUMP_DESTINATION);
}
use of org.hyperledger.besu.evm.operation.JumpOperation in project besu by hyperledger.
the class JumpOperationTest method shouldJumpWhenLocationIsJumpDestAndAtEndOfCode.
@Test
public void shouldJumpWhenLocationIsJumpDestAndAtEndOfCode() {
final JumpOperation operation = new JumpOperation(gasCalculator);
final Bytes jumpBytes = Bytes.fromHexString("0x6003565b");
final MessageFrame frame = createMessageFrameBuilder(10_000L).pushStackItem(UInt256.fromHexString("0x03")).code(Code.createLegacyCode(jumpBytes, Hash.hash(jumpBytes))).build();
frame.setPC(CURRENT_PC);
final OperationResult result = operation.execute(frame, evm);
assertThat(result.getHaltReason()).isEmpty();
}
use of org.hyperledger.besu.evm.operation.JumpOperation in project besu by hyperledger.
the class JumpOperationTest method init.
@Before
public void init() {
blockchain = mock(Blockchain.class);
address = Address.fromHexString("0x18675309");
final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
worldStateUpdater = worldStateArchive.getMutable().updater();
worldStateUpdater.getOrCreate(address).getMutable().setBalance(Wei.of(1));
worldStateUpdater.commit();
final OperationRegistry registry = new OperationRegistry();
registry.put(new JumpOperation(gasCalculator));
registry.put(new JumpDestOperation(gasCalculator));
evm = new EVM(registry, gasCalculator, EvmConfiguration.DEFAULT);
}
Aggregations