Search in sources :

Example 1 with InvalidPermissionException

use of com.radixdlt.constraintmachine.exceptions.InvalidPermissionException in project radixdlt by radixdlt.

the class RadixEngineStateComputerTest method preparing_system_update_from_vertex_should_fail.

@Test
public void preparing_system_update_from_vertex_should_fail() throws TxBuilderException {
    // Arrange
    var txn = radixEngine.construct(new NextRound(1, false, 0, i -> proposerElection.getProposer(View.of(i)).getKey())).buildWithoutSignature();
    var illegalTxn = TxLowLevelBuilder.newBuilder(currentForkView.currentForkConfig().engineRules().serialization()).down(SubstateId.ofSubstate(txn.getId(), 1)).up(new RoundData(2, 0)).end().build();
    var v = UnverifiedVertex.create(mock(QuorumCertificate.class), View.of(1), List.of(illegalTxn), proposerElection.getProposer(View.of(1)));
    var vertex = new VerifiedVertex(v, mock(HashCode.class));
    // Act
    var result = sut.prepare(ImmutableList.of(), vertex, 0);
    // Assert
    assertThat(result.getSuccessfulCommands()).hasSize(1);
    assertThat(result.getFailedCommands()).hasValueSatisfying(new Condition<>(e -> {
        var ex = (RadixEngineException) e;
        var cmException = (ConstraintMachineException) ex.getCause();
        return cmException.getCause() instanceof InvalidPermissionException;
    }, "Is invalid_execution_permission error"));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Module(com.google.inject.Module) SimpleLedgerAccumulatorAndVerifier(com.radixdlt.ledger.SimpleLedgerAccumulatorAndVerifier) TxAction(com.radixdlt.atom.TxAction) NoOpCommittedReader(com.radixdlt.sync.NoOpCommittedReader) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) RadixEngineException(com.radixdlt.engine.RadixEngineException) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) TypedMocks(com.radixdlt.utils.TypedMocks) DefaultSerialization(com.radixdlt.DefaultSerialization) Hasher(com.radixdlt.crypto.Hasher) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RoundData(com.radixdlt.application.system.state.RoundData) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) ByzantineQuorumException(com.radixdlt.ledger.ByzantineQuorumException) CurrentForkView(com.radixdlt.statecomputer.forks.CurrentForkView) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) HashUtils(com.radixdlt.crypto.HashUtils) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) SystemCounters(com.radixdlt.counters.SystemCounters) NoOpForksEpochStore(com.radixdlt.statecomputer.forks.NoOpForksEpochStore) REEvent(com.radixdlt.constraintmachine.REEvent) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) EngineStore(com.radixdlt.store.EngineStore) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) Collectors(java.util.stream.Collectors) ForksEpochStore(com.radixdlt.statecomputer.forks.ForksEpochStore) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) CommittedReader(com.radixdlt.sync.CommittedReader) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) Amount(com.radixdlt.application.tokens.Amount) TypeLiteral(com.google.inject.TypeLiteral) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) Mockito.mock(org.mockito.Mockito.mock) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Serialization(com.radixdlt.serialization.Serialization) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) com.radixdlt.atom(com.radixdlt.atom) ProposerElection(com.radixdlt.hotstuff.liveness.ProposerElection) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) View(com.radixdlt.hotstuff.bft.View) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) MempoolConfig(com.radixdlt.mempool.MempoolConfig) AccumulatorState(com.radixdlt.ledger.AccumulatorState) RadixEngineCheckpointModule(com.radixdlt.statecomputer.checkpoint.RadixEngineCheckpointModule) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) BFTHeader(com.radixdlt.hotstuff.BFTHeader) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) InMemoryEngineStore(com.radixdlt.store.InMemoryEngineStore) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) Ignore(org.junit.Ignore) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) HashCode(com.google.common.hash.HashCode) RoundData(com.radixdlt.application.system.state.RoundData) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 2 with InvalidPermissionException

use of com.radixdlt.constraintmachine.exceptions.InvalidPermissionException in project radixdlt by radixdlt.

the class ConstraintMachine method callProcedure.

/**
 * Executes a transition procedure given the next spun particle and a current validation state.
 */
private ReducerState callProcedure(Procedure procedure, Object procedureParam, ReducerState reducerState, Resources immutableAddrs, ExecutionContext context) throws SignedSystemException, InvalidPermissionException, AuthorizationException, MeterException, ProcedureException {
    // System permissions don't require additional authorization
    var authorization = procedure.authorization(procedureParam);
    var requiredLevel = authorization.permissionLevel();
    context.verifyPermissionLevel(requiredLevel);
    if (context.permissionLevel() != PermissionLevel.SYSTEM) {
        try {
            if (requiredLevel == PermissionLevel.USER) {
                this.meter.onUserProcedure(procedure.key(), procedureParam, context);
            } else if (requiredLevel == PermissionLevel.SUPER_USER) {
                this.meter.onSuperUserProcedure(procedure.key(), procedureParam, context);
            }
        } catch (Exception e) {
            throw new MeterException(e);
        }
        if (!context.skipAuthorization()) {
            try {
                authorization.authorizer().verify(immutableAddrs, context);
            } catch (Exception e) {
                throw new AuthorizationException(e);
            }
        }
    }
    return procedure.call(procedureParam, reducerState, immutableAddrs, context).state();
}
Also used : MeterException(com.radixdlt.constraintmachine.exceptions.MeterException) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) MeterException(com.radixdlt.constraintmachine.exceptions.MeterException) ProcedureException(com.radixdlt.constraintmachine.exceptions.ProcedureException) MissingProcedureException(com.radixdlt.constraintmachine.exceptions.MissingProcedureException) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) SignedSystemException(com.radixdlt.constraintmachine.exceptions.SignedSystemException) SubstateNotFoundException(com.radixdlt.constraintmachine.exceptions.SubstateNotFoundException) NotAResourceException(com.radixdlt.constraintmachine.exceptions.NotAResourceException) VirtualSubstateAlreadyDownException(com.radixdlt.constraintmachine.exceptions.VirtualSubstateAlreadyDownException) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) LocalSubstateNotFoundException(com.radixdlt.constraintmachine.exceptions.LocalSubstateNotFoundException) TrailingBytesException(com.radixdlt.engine.parser.exceptions.TrailingBytesException) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Aggregations

ConstraintMachineException (com.radixdlt.constraintmachine.exceptions.ConstraintMachineException)2 InvalidPermissionException (com.radixdlt.constraintmachine.exceptions.InvalidPermissionException)2 ImmutableList (com.google.common.collect.ImmutableList)1 HashCode (com.google.common.hash.HashCode)1 AbstractModule (com.google.inject.AbstractModule)1 Guice (com.google.inject.Guice)1 Inject (com.google.inject.Inject)1 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 DefaultSerialization (com.radixdlt.DefaultSerialization)1 RoundData (com.radixdlt.application.system.state.RoundData)1 Amount (com.radixdlt.application.tokens.Amount)1 com.radixdlt.atom (com.radixdlt.atom)1 TxAction (com.radixdlt.atom.TxAction)1 PermissionLevel (com.radixdlt.constraintmachine.PermissionLevel)1 REEvent (com.radixdlt.constraintmachine.REEvent)1 AuthorizationException (com.radixdlt.constraintmachine.exceptions.AuthorizationException)1 LocalSubstateNotFoundException (com.radixdlt.constraintmachine.exceptions.LocalSubstateNotFoundException)1 MeterException (com.radixdlt.constraintmachine.exceptions.MeterException)1 MissingProcedureException (com.radixdlt.constraintmachine.exceptions.MissingProcedureException)1