Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requires a high-level opcode interface. #150

Open
hea9549 opened this issue Jan 18, 2019 · 1 comment
Open

Requires a high-level opcode interface. #150

hea9549 opened this issue Jan 18, 2019 · 1 comment

Comments

@hea9549
Copy link
Member

hea9549 commented Jan 18, 2019

koa have op codes in vm.go like

type add struct{}
type mul struct{}
type sub struct{}
type div struct{}
type mod struct{}
...

But I think there is a need for an upper interface that will contain a lot of information.

for example, in evm, there is operation struct to contain more information about opcode.

type operation struct {
	// execute is the operation function
	execute executionFunc
	// gasCost is the gas function and returns the gas required for execution
	gasCost gasFunc
	// validateStack validates the stack (size) for the operation
	validateStack stackValidationFunc
	// memorySize returns the memory size required for the operation
	memorySize memorySizeFunc

	halts   bool // indicates whether the operation should halt further execution
	jumps   bool // indicates whether the program counter should not increment
	writes  bool // determines whether this a state modifying operation
	valid   bool // indication whether the retrieved operation is valid and known
	reverts bool // determines whether the operation reverts state (implicitly halts)
	returns bool // determines whether the operations sets the return data content
}

ExecutionFunc equal to koa's opcode Do(~~~) Function

Evm also uses stackValidationFunc to check the number of pops and puts in the stack to solve the stack function problem.
In addition, evm uses an operation set called jumptable to limit the operation set allowed by the config.
As of now, we only need to fetch a function that validates the stack.

I would like to add a struct that owns an opCode rather than merely putting a validateStack function in the opcode. (For future expansion)

I want to ask your thoughts.

@hea9549 hea9549 mentioned this issue Jan 18, 2019
1 task
@hea9549
Copy link
Member Author

hea9549 commented Jan 18, 2019

한글로도 첨부합니다... 영어를 잘 못쓰겠어서 전달이 잘 안될까봐..ㅜㅜ
evm에서는 instructionSet이라는것을 만들어 opcode와 함께 부가정보를 담아둡니다.
해당 정보에서 이 opcode를 실행시킬때 현재 stack에서 문제가 발생하는지 검증하는 함수와 가스정보 등을 같이 둡니다.

koa에서는 간단하게 하기위해 opcode라는 구조체에 함께 담아둘 수 있지만, 확장성을위해 evm처럼 operation이라는 구조체를 하나 만들어 opcode를 excute할수있고 다른 검증기능(스택 오류 나는지 여부 등)도 수행하는 상위 구조체를 만들면 좋을 것 같습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant