I am trying to to do a sort of block-validator for bitcoin(and alike chains), in it I need to depending on chain and block-height only allow certain operators in the transactions scripts. One thought I had was that this might be something that LISA should be good for. (I might be wrong in this) but shouldn't something like a rule engine be a good fit for that? What I want is a good way to defines the rules for my validator on how to validate that a block and its transactions adhere to the consensus rules?
I am sort of getting to this point
(defpackage #:chain-validator
(:shadowing-import-from #:lisa #:assert)
(:use #:lisa
#:cl))
(in-package :chain-validator)
(defclass chain-fundamental () ())
(defclass chain-block (chain-fundamental)
((height :initarg :height :initform 1)
(chain :initarg :chain :initform :bitcoin)))
(defclass chain-tx (chain-fundamental)
((in-block :initarg :block :initform 'nil)
(pk-script :initarg :pk-script)
(is-coinbase-tx :initarg :coinbase :initform 'f)))
(defclass chain-OP (chain-fundamental)
((name :initarg :name)
(op-code :initarg :op-code)))
(defrule dont-allow-op-mul-after-height-1000
;;; how to write this one?????
;; but if I only want to allow mul on a certain chain after height
;; 2000?
)
(defrule startup ()
=>
(assert-instance
(make-instance 'chain-OP :name :PUSHDATA4 :op-code #x4e))
(assert-instance
(make-instance 'chain-OP :name :EQUAL :op-code #x87))
(assert-instance
(make-instance 'chain-OP :name :MUL :op-code #x95))
(let* ((genesis-blk (make-instance 'chain-block))
(later-blk (make-instance 'chain-block :height 2500))
(first-coinbase-tx (make-instance 'chain-tx :block genesis-blk))
(later-coinbase-tx (make-instance 'chain-tx :block later-blk)))
(assert-instance genesis-blk)
(assert-instance later-blk)
(assert-instance first-coinbase-tx)
(assert-instance later-coinbase-tx)))
;; how can I use LISA to get the chain-OPs that are allowed for a
;; transaction belonging to a specific block at some height, I sort of
;; want to find them all so i later can verify that the pk-script part
;; only contains those OPs. Could I write rules that would acctually
;; do the validation for me? that would check if chain-tx.pk-script
;; only contains certain OPs. And if we have multiple chains, how do I
;; write the rules to take account for that?
But after that I don't know how to proceed, the questions I want LISA to answer for me are things like
- What are the valid script operations for a certain block, or transaction?
- Is this block or transaction valid?
Maybe what I need is primer on rule engines or a good tutorial. I just can't really get my head around how to write the rules.