Search in sources :

Example 1 with JumpOperation

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();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) JumpOperation(org.hyperledger.besu.evm.operation.JumpOperation) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) Test(org.junit.Test)

Example 2 with JumpOperation

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));
    }
}
Also used : NumberOperation(org.hyperledger.besu.evm.operation.NumberOperation) CallDataSizeOperation(org.hyperledger.besu.evm.operation.CallDataSizeOperation) TimestampOperation(org.hyperledger.besu.evm.operation.TimestampOperation) MSizeOperation(org.hyperledger.besu.evm.operation.MSizeOperation) PCOperation(org.hyperledger.besu.evm.operation.PCOperation) PushOperation(org.hyperledger.besu.evm.operation.PushOperation) JumpiOperation(org.hyperledger.besu.evm.operation.JumpiOperation) SwapOperation(org.hyperledger.besu.evm.operation.SwapOperation) DivOperation(org.hyperledger.besu.evm.operation.DivOperation) SDivOperation(org.hyperledger.besu.evm.operation.SDivOperation) CallCodeOperation(org.hyperledger.besu.evm.operation.CallCodeOperation) SDivOperation(org.hyperledger.besu.evm.operation.SDivOperation) XorOperation(org.hyperledger.besu.evm.operation.XorOperation) StaticCallOperation(org.hyperledger.besu.evm.operation.StaticCallOperation) DelegateCallOperation(org.hyperledger.besu.evm.operation.DelegateCallOperation) CallOperation(org.hyperledger.besu.evm.operation.CallOperation) MStoreOperation(org.hyperledger.besu.evm.operation.MStoreOperation) SelfDestructOperation(org.hyperledger.besu.evm.operation.SelfDestructOperation) JumpDestOperation(org.hyperledger.besu.evm.operation.JumpDestOperation) SGtOperation(org.hyperledger.besu.evm.operation.SGtOperation) GtOperation(org.hyperledger.besu.evm.operation.GtOperation) CodeSizeOperation(org.hyperledger.besu.evm.operation.CodeSizeOperation) ExtCodeSizeOperation(org.hyperledger.besu.evm.operation.ExtCodeSizeOperation) ExtCodeCopyOperation(org.hyperledger.besu.evm.operation.ExtCodeCopyOperation) LogOperation(org.hyperledger.besu.evm.operation.LogOperation) ExtCodeSizeOperation(org.hyperledger.besu.evm.operation.ExtCodeSizeOperation) LtOperation(org.hyperledger.besu.evm.operation.LtOperation) SLtOperation(org.hyperledger.besu.evm.operation.SLtOperation) JumpOperation(org.hyperledger.besu.evm.operation.JumpOperation) SModOperation(org.hyperledger.besu.evm.operation.SModOperation) ExpOperation(org.hyperledger.besu.evm.operation.ExpOperation) DifficultyOperation(org.hyperledger.besu.evm.operation.DifficultyOperation) DupOperation(org.hyperledger.besu.evm.operation.DupOperation) MulModOperation(org.hyperledger.besu.evm.operation.MulModOperation) StopOperation(org.hyperledger.besu.evm.operation.StopOperation) SLoadOperation(org.hyperledger.besu.evm.operation.SLoadOperation) ReturnOperation(org.hyperledger.besu.evm.operation.ReturnOperation) SLtOperation(org.hyperledger.besu.evm.operation.SLtOperation) Keccak256Operation(org.hyperledger.besu.evm.operation.Keccak256Operation) CoinbaseOperation(org.hyperledger.besu.evm.operation.CoinbaseOperation) CallDataCopyOperation(org.hyperledger.besu.evm.operation.CallDataCopyOperation) GasLimitOperation(org.hyperledger.besu.evm.operation.GasLimitOperation) BalanceOperation(org.hyperledger.besu.evm.operation.BalanceOperation) SelfBalanceOperation(org.hyperledger.besu.evm.operation.SelfBalanceOperation) AddOperation(org.hyperledger.besu.evm.operation.AddOperation) CallDataLoadOperation(org.hyperledger.besu.evm.operation.CallDataLoadOperation) MLoadOperation(org.hyperledger.besu.evm.operation.MLoadOperation) CallerOperation(org.hyperledger.besu.evm.operation.CallerOperation) BlockHashOperation(org.hyperledger.besu.evm.operation.BlockHashOperation) OriginOperation(org.hyperledger.besu.evm.operation.OriginOperation) GasPriceOperation(org.hyperledger.besu.evm.operation.GasPriceOperation) GasOperation(org.hyperledger.besu.evm.operation.GasOperation) MulOperation(org.hyperledger.besu.evm.operation.MulOperation) CallValueOperation(org.hyperledger.besu.evm.operation.CallValueOperation) IsZeroOperation(org.hyperledger.besu.evm.operation.IsZeroOperation) AddressOperation(org.hyperledger.besu.evm.operation.AddressOperation) MStore8Operation(org.hyperledger.besu.evm.operation.MStore8Operation) EqOperation(org.hyperledger.besu.evm.operation.EqOperation) CodeCopyOperation(org.hyperledger.besu.evm.operation.CodeCopyOperation) ExtCodeCopyOperation(org.hyperledger.besu.evm.operation.ExtCodeCopyOperation) NotOperation(org.hyperledger.besu.evm.operation.NotOperation) AndOperation(org.hyperledger.besu.evm.operation.AndOperation) InvalidOperation(org.hyperledger.besu.evm.operation.InvalidOperation) PopOperation(org.hyperledger.besu.evm.operation.PopOperation) SubOperation(org.hyperledger.besu.evm.operation.SubOperation) ModOperation(org.hyperledger.besu.evm.operation.ModOperation) SModOperation(org.hyperledger.besu.evm.operation.SModOperation) AddModOperation(org.hyperledger.besu.evm.operation.AddModOperation) MulModOperation(org.hyperledger.besu.evm.operation.MulModOperation) OrOperation(org.hyperledger.besu.evm.operation.OrOperation) CreateOperation(org.hyperledger.besu.evm.operation.CreateOperation) SStoreOperation(org.hyperledger.besu.evm.operation.SStoreOperation) ByteOperation(org.hyperledger.besu.evm.operation.ByteOperation) AddModOperation(org.hyperledger.besu.evm.operation.AddModOperation) SignExtendOperation(org.hyperledger.besu.evm.operation.SignExtendOperation) SGtOperation(org.hyperledger.besu.evm.operation.SGtOperation)

Example 3 with JumpOperation

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);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) JumpOperation(org.hyperledger.besu.evm.operation.JumpOperation) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) Test(org.junit.Test)

Example 4 with JumpOperation

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();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) JumpOperation(org.hyperledger.besu.evm.operation.JumpOperation) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) Test(org.junit.Test)

Example 5 with JumpOperation

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);
}
Also used : InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) JumpOperation(org.hyperledger.besu.evm.operation.JumpOperation) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) JumpDestOperation(org.hyperledger.besu.evm.operation.JumpDestOperation) OperationRegistry(org.hyperledger.besu.evm.operation.OperationRegistry) EVM(org.hyperledger.besu.evm.EVM) Before(org.junit.Before)

Aggregations

JumpOperation (org.hyperledger.besu.evm.operation.JumpOperation)7 Bytes (org.apache.tuweni.bytes.Bytes)5 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)5 OperationResult (org.hyperledger.besu.evm.operation.Operation.OperationResult)4 Test (org.junit.Test)4 JumpDestOperation (org.hyperledger.besu.evm.operation.JumpDestOperation)2 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)1 InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive (org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive)1 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)1 Code (org.hyperledger.besu.evm.Code)1 EVM (org.hyperledger.besu.evm.EVM)1 AddModOperation (org.hyperledger.besu.evm.operation.AddModOperation)1 AddOperation (org.hyperledger.besu.evm.operation.AddOperation)1 AddressOperation (org.hyperledger.besu.evm.operation.AddressOperation)1 AndOperation (org.hyperledger.besu.evm.operation.AndOperation)1 BalanceOperation (org.hyperledger.besu.evm.operation.BalanceOperation)1 BlockHashOperation (org.hyperledger.besu.evm.operation.BlockHashOperation)1 ByteOperation (org.hyperledger.besu.evm.operation.ByteOperation)1 CallCodeOperation (org.hyperledger.besu.evm.operation.CallCodeOperation)1 CallDataCopyOperation (org.hyperledger.besu.evm.operation.CallDataCopyOperation)1