Giter Site home page Giter Site logo

xorgx304 / rcpu_symbolic_execution Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redfast00/rcpu_symbolic_execution

0.0 1.0 0.0 7.7 MB

Symbolic execution of RCPU assembly using Prolog

Prolog 75.38% Python 18.53% Shell 3.44% Assembly 2.66%

rcpu_symbolic_execution's Introduction

Project proposal

Description

RCPU is a 16-bit fantasy CPU architecture (that has however been implemented in real hardware). The goal of this project is to explore symbolic execution using Prolog. The goal of this project is to either find inputs satisfying constraints on arbitrary RCPU programs or to prove that there are no possible inputs satisfying the constraints. The constraints can be on the internal state of the RCPU machine, on the input and on the output.

Goals

The following goals will be evaluated at the end of the project and will be used in order to grade the project. Note that all example programs can be replaced by arbitrary RPCU programs (this means that manual extraction of constraints is impossible).

Find an input for a program that results in an output of an even number

Example:

LDV A, 0
PSH A
SYS
POP A  ;; move char that was put in to the A register
LDV D, 1 ;; load 1 into D
ADD A, D ;; A = A + D
PUSH A
LDV A, 1
PSH A
SYS ;; output from stack to output
HLT ;; halt the machine

A possible input tape is here: (5 (2 ())): only the first character on the input tape will be consumed by the program and will result in an output tape of (6 ())

Find an input for a program that results in a certain configuration of the registers at program end

Example:

Constraints:

A = 2*B, A > 1, C = 5, D = A + 1

Program:

LDV A, 0
PSH A
SYS
PSH A
SYS
PSH A
SYS
PSH A
SYS
POP A
POP B
POP C
POP D
SUB D, A ;; D = D - A
HLT

Possible input:

(2 (1 (5 (5 ()))))

Find an input for the program that results in the execution of a certain instruction.

Example:

Find an input that results in the :win label getting reached

Program:

LDV A, 5
LDV B, 0
PSH B
SYS
POP B
LDV C, good:
JLT B, C ;; jumps to C if A < B
JMP bad:

good:

win:
ADD C, D
HLT

bad:
HLT

Find an input that results in certain configuration of values on the stack at program end

Example:

Constraints:

TOS[0] (top of stack)
TOS[1] (second item on stack)
...

TOS[0] = TOS[1], TOS[2] > 1

Program:

LDV A, 0
LDV C, 0
PSH A
SYS
PSH A
SYS
PSH A
SYS
PSH A
SYS
POP D
LDV A, 1
ADD D, A ;; D = D + A
JMP label:
PSH C
SYS ;; unreachable
label:
PSH C
SYS
PSH D
HLT

Possible input:

(x (x (2 (4 (5 ()))))) where x isn't constrained

Find an input that results in the RCPU-machine crashing

Example program will input a number that will be on the stack. It will then return to that address.

LDV A, 0
PSH A
SYS
RET
HLT
HLT
HLT

Here, any input bigger than 7 will result in the RCPU machine jumping to undefined memory and crashing.

Differences from official RCPU specs

  • For input and output, only the getc and putc syscalls will be implemented: this will allow setting constraints on input and output, without having to implement complex routines like printf.
  • It won't be possible to write self-modifying code: the instructions and data will live in a different address space.
  • Machine arithmetic is hard in Prolog without adding a lot of mod predicates, negatively affecting performance. For this reason, machine arithmetic was not implemented

Some examples of the RCPU machine crashing

Undefined behavior will also be seen as a crash

  • Jumping to memory where there aren't any instructions
  • Dividing by zero
  • Popping from an empty stack
  • ...

rcpu_symbolic_execution's People

Contributors

redfast00 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.