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

compiler: replace jump targets correctly #630

Closed
fyrchik opened this issue Jan 29, 2020 · 0 comments · Fixed by #643
Closed

compiler: replace jump targets correctly #630

fyrchik opened this issue Jan 29, 2020 · 0 comments · Fixed by #643
Labels
bug Something isn't working compiler Go smart contract compiler
Milestone

Comments

@fyrchik
Copy link
Contributor

fyrchik commented Jan 29, 2020

Currently JMP* targets are translated from relative to absolute numbers going byte-by-byte with script.
https://github.com/nspcc-dev/neo-go/blob/master/pkg/compiler/codegen.go#L1029

This is incorrect, as some bytes can be a part of other instructions and not a separate opcode.
E.g. this test fails (notice, that 0x62 == byte(opcode.JMP)):

func TestJumps(t *testing.T) {
	src := `
	package foo
	func Main() []byte {
		buf := []byte{0x62, 0x01, 0x00}
		return buf
	}
	`
	eval(t, src, []byte{0x62, 0x01, 0x00}) // will be []byte{0x62, 0x7, 0x0}
}

There are several ways to address this issue.
I propose implementing some richer intermediate representation (list of structs, not just a slice of bytes). This will also make it easier to implement byte-code level optimizations in future.

@roman-khimov roman-khimov added this to the v0.72.3 milestone Feb 12, 2020
roman-khimov added a commit that referenced this issue Feb 12, 2020
compiler: rewrite jump targets properly

Closes #630.
@roman-khimov roman-khimov modified the milestones: v0.72.3, v0.73.0 Feb 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Go smart contract compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants