0

This is a conceptual question about applying UML State Machine model for smart contracts in blockchain. I want to develop a smart contract framework in a bitcoin-like blockchain which is based on the state machine concept. It would allow to define state machine events, states and transitions as a smart contract configuration and execute it. So we would not need coding to implement many smart contract applications but just define an approriate state machine configuration.

I want to follow UML State Machine concepts as I believe it is well-defined and consistent. In short, UML State Machine supposes that there exist several kinds of events which trigger transitions from a state to state. If we try to apply UML StateMachine concepts on the blockchain ground we'll find that in blockchain most events would be transactions which spend or transfer coins from some addresses.

My problem is that the UML State Machine concepts are not sufficient for implementation of state machines in blockchain: UML allows to define a State Action so we could do something when a state machine transitions from a state to state. But I also need a state machine feature to prevent events to occur in the blockchain.

The simplest example is funds time locking. Let a StateMachine could be in two states: 'Coins Locked on Address' and 'Coins Unlocked on Address when Timeout Passed'.

So when it is in the first state I need to disable spending from that address where coins are locked. So I suppose this spending is a event which I need to either enable or disable, depending on the current state, but could not find in UML standard any support for event conditions.

The question is: Is there something in UML State Machine concepts that would allow for events to occur conditionally (when the StateMachine is in a pre-defined state).

Or maybe I'm wrong and I need to use another concept for this (that is, not the 'event' what I'm trying to use)?

New contributor
xdimy is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    Events in an UML state machine are things that happen in the "outside world". You can't prevent them from happening. If an event occurs that is not handled by the current state of the statemachine, the event has no effects. – Bart van Ingen Schenau Nov 7 at 17:49
  • @BartvanIngenSchenau I think that's just the answer. – qwerty_so Nov 7 at 20:04
  • I think you are right, thank you. That way, with UML we cannot model situations like that when states of a StateMachine affect event flow. To achieve this, seems, we need to add some extensions to UML. – xdimy Nov 7 at 21:33
2

You can't prevent an event from occurring, but you can ignore an event just by not specifying a transition or action to happen when the event occurs.

For example, if you want the system not to spend when the state is 'locked', then you just don't specify any action when the event 'spend request' occurs in that state, or you specify that the system generates an error upon receiving the event.

Remember, a state machine diagram represents the behavior of a particular subject (class, component, subsystem, whatever). Carefully choose and specify which subject that is. Sometimes, a problem may be solved by choosing a different subject, e.g. an overarching system.

  • This is a very interesting idea about spend request! I'm thinking how to implement it. First, I considered that events in blockchain could be transactions added to blocks, so they are 'change events'. But 'spend requests' are transactions that are in mempool and not added to the blockchain yet. So we might add state machine code into the consensus code and we can validate if such spending is allowed by checking state transition condition – xdimy Nov 8 at 7:21
  • Yes. A state machine diagram represents the behavior of a particular subject (class, component, subsystem, whatever). Carefully choose and specify which subject that is. Sometimes, a problem may be solved by choosing a different subject, e.g. an overarching system. – www.admiraalit.nl Nov 8 at 9:23
  • Please mark the answer as accepted if you are satisfied. – www.admiraalit.nl Nov 8 at 9:25
0

So I suppose this spending is a event which I need to either enable or disable, depending on the current state, but could not find in UML standard any support for event conditions.

I'm not sure about your states (the question is not detailed in that dimension), but you can use the abstraction of locked as a guard condition to prevent a transition:

State diagram with guard condition

  • Thank you for your response. I'm trying to use UML concepts to make blockchain smart contracts as a finite state machine. UML defines events as triggers for state transitions. For a state machine in blockchain events are caused by transactions. So events happen and trigger state transitions. A State Machine should be able to validate transations in consensus code (disable a transaction if it is not allowed in the current state) But if transactions are events, not transitions, seems guards do not help? As guards are for state transitions, not events. – xdimy Nov 10 at 12:55
  • @xdimy I updated my answer to emphasise the distinction between the request (event) and the transaction (action). I also show how an error action could be generated. – Fuhrmanator Nov 10 at 16:18
  • Thank you, for this case we might consider transactions in mempool as spend_requests and in UML terms they could be defined as 'message events' (more specifically like 'Call for Validation'). That way, we can use guards to validate transactions. – xdimy 2 days ago

Your Answer

xdimy is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.