-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into yellow_paper
- Loading branch information
Showing
14 changed files
with
898 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BasedOnStyle: Google | ||
IndentWidth: 4 | ||
TabWidth: 4 | ||
UseTab: Never | ||
ColumnLimit: 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,6 @@ build/ | |
_build/ | ||
_static/ | ||
_templates/ | ||
docs/api/ | ||
docs/api/ | ||
*.o | ||
cuEVM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${workspaceFolder}/**" | ||
], | ||
"defines": [], | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "c11", | ||
"cppStandard": "gnu++14", | ||
"intelliSenseMode": "linux-gcc-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef CUEVM_TEST_H | ||
#define CUEVM_TEST_H | ||
#include "stack.cuh" | ||
|
||
|
||
void test_arithmetic_operations(); | ||
void test_stack(); | ||
|
||
#endif // CUEVM_TEST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef OPCODE_H | ||
#define OPCODE_H | ||
|
||
#define ADD 0x01 | ||
#define MUL 0x02 | ||
#define SUB 0x03 | ||
|
||
|
||
#define POP 0x50 | ||
#define PUSH1 0x60 | ||
#define PUSH2 0x61 | ||
|
||
#define SWAP1 0x90 | ||
|
||
#define DUP1 0x80 | ||
|
||
#define JUMP 0x56 | ||
#define JUMPI 0x57 | ||
#define JUMPDEST 0x5b | ||
|
||
|
||
#define RETURN 0xf3 | ||
// Add other opcode definitions here as your VM expands | ||
|
||
#endif // OPCODE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef PROCESSOR_CUH | ||
#define PROCESSOR_CUH | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <ctype.h> | ||
#include "uint256.cuh" | ||
#include "stack.cuh" | ||
#define EVM_VERSION "petersburg" // hardcode to only one version ! | ||
|
||
typedef struct { | ||
base_uint origin; | ||
base_uint block_numer; | ||
base_uint block_difficulty; | ||
// other fields | ||
} environment; | ||
|
||
// Struct to represent a call frame | ||
// Not implemented yet (cross contract) | ||
// typedef struct { | ||
// base_uint caller; | ||
// base_uint callValue; | ||
// base_uint gasLimit; // not supported | ||
// uint8_t* inputData; | ||
// size_t inputDataSize; | ||
// } CallFrame; | ||
|
||
// Struct for the EVM processor | ||
typedef struct { | ||
// other fields as new functionality is added | ||
// base_uint gasRemaining; not implemented | ||
// CallFrame* callStack; // not implemented yet | ||
base_uint_stack stack; | ||
base_uint caller; | ||
uint32_t programCounter; | ||
// uint8_t* bytecode; temporarily not needed in single contract | ||
} processor; | ||
// util functions | ||
|
||
#endif // PROCESSOR_CUH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef STACK_CUH | ||
#define STACK_CUH | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <ctype.h> | ||
#include "uint256.cuh" | ||
#define STACK_SIZE 100 // For example, temporarily set the stack size of 100 | ||
|
||
typedef struct { | ||
base_uint items[STACK_SIZE]; | ||
int top; | ||
} base_uint_stack; | ||
|
||
__host__ __device__ void init_stack(base_uint_stack* stack); | ||
|
||
__host__ __device__ bool push(base_uint_stack* stack, base_uint item); | ||
|
||
__host__ __device__ bool pop(base_uint_stack* stack, base_uint* item); | ||
|
||
__host__ __device__ bool swap_with_top(base_uint_stack* stack, int i); | ||
|
||
__host__ __device__ void print_stack(base_uint_stack* stack); | ||
|
||
|
||
#endif // STACK_CUH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// base_uint256.cuh | ||
|
||
#ifndef BASE_UINT256_CUH | ||
#define BASE_UINT256_CUH | ||
|
||
#include <ctype.h> | ||
#include <cuda_runtime.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#define BITS 256 | ||
#define WIDTH (BITS / 32) | ||
|
||
typedef struct { | ||
uint32_t pn[WIDTH]; | ||
} base_uint; | ||
|
||
// utility functions | ||
__host__ int hexToInt(const char *hex); | ||
|
||
__host__ void intToHex(int num, char *hex); | ||
|
||
__host__ bool hex_to_decimal(const char *hex_str, char *dec_str); | ||
|
||
__host__ __device__ void print_base_uint(const base_uint *val); | ||
|
||
// conversion operations | ||
__host__ bool base_uint_set_hex(base_uint *val, const char *hex); | ||
|
||
__host__ void base_uint_to_string(const base_uint *val, char *out_str); | ||
|
||
__host__ bool int_to_base_uint(int int_val, base_uint *val); | ||
|
||
__host__ __device__ void base_uint_get_hex(const base_uint *val, char *hex); | ||
|
||
// comparison operations | ||
__host__ __device__ bool is_zero(const base_uint *num); | ||
|
||
// bitwise operations | ||
__host__ __device__ base_uint bitwise_not(const base_uint *num); | ||
|
||
__host__ __device__ void base_uint_set_bit(base_uint *value, uint32_t bitpos); | ||
|
||
// arithmetic operations | ||
|
||
__host__ __device__ void base_uint_add(const base_uint *a, const base_uint *b, base_uint *result); | ||
|
||
__host__ __device__ bool base_uint_sub(const base_uint *a, const base_uint *b, base_uint *result); | ||
|
||
__host__ __device__ void base_uint_mul(const base_uint *a, const base_uint *b, base_uint *result); | ||
|
||
__host__ __device__ void base_uint_shift_left(base_uint *a, size_t bits); | ||
|
||
__host__ __device__ void base_uint_div(const base_uint *a, const base_uint *b, base_uint *quotient, | ||
base_uint *remainder); | ||
|
||
#endif // BASE_UINT256_CUH |
Oops, something went wrong.