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

Support Script interpreter #53

Closed
xhliu opened this issue Mar 22, 2022 · 24 comments
Closed

Support Script interpreter #53

xhliu opened this issue Mar 22, 2022 · 24 comments

Comments

@xhliu
Copy link

xhliu commented Mar 22, 2022

to speed up Bitcoin VM.

@Firaenix
Copy link
Owner

In the works :)

Will be a separate package but will leverage all of bsv-wasm

@utxo-detective
Copy link
Collaborator

ceo of testnet approved

@deanmlittle
Copy link
Collaborator

@xhliu You're gonna love this ;)

@xhliu
Copy link
Author

xhliu commented Mar 23, 2022

Can't wait, CEO/CTO.

@xhliu
Copy link
Author

xhliu commented Jul 4, 2022

Gents, any update on this? Would love to switch to WASM to speed up.

@Firaenix
Copy link
Owner

Firaenix commented Jul 6, 2022

Hey @xhliu I'm aiming to have something usable for you in about 2 weeks time. I'll keep you posted

@Firaenix Firaenix mentioned this issue Jul 6, 2022
3 tasks
@zhfnjust
Copy link

zhfnjust commented Aug 1, 2022

hello, how to use Interpreter ?
my code below:

	const bsvwasm = require("bsv-wasm");

	const s = bsvwasm.Script.from_hex("5b0000005754615179547a75537a537a537a0079537a75527a527a7575615279008763537952795279615179517993517a75517a75619c77777777675279518763537952795279949c7777777767006868");
	
	const bm = bsvwasm.Interpreter.from_script(s);

	try {
		Loggging.log(`state: ${bm.run()}`);
	} catch (error) {
		Loggging.log(`wasm error: ${error}`);
	}

but got a error when call bm.run() :

wasm error: RuntimeError: unreachable

@Firaenix
Copy link
Owner

Firaenix commented Aug 1, 2022

I think there is a bug with OP_PICK, I will look into it

@Firaenix
Copy link
Owner

Firaenix commented Aug 2, 2022

Thanks for the issue, here's a new build for you to try out.
I'll aim to get a release pipeline for 2.0 out eventually.

https://github.com/Firaenix/bsv-wasm/blob/split-modules/packages/bsv-wasm/pkg/bsv-wasm%20node%202.0.0%20alpha.zip

@zhfnjust
Copy link

zhfnjust commented Aug 2, 2022

an other error when call bsvwasm.Script.from_hex(snark);

Error when deserialising Script: OP_IF statement requires an OP_ELSE code
snark.hex.zip
.

@Firaenix
Copy link
Owner

Firaenix commented Aug 3, 2022

I was under the impression that any OP_IF must have an OP_ELSE followed by an OP_ENDIF, according to the BSV Wiki https://wiki.bitcoinsv.io/index.php/Opcodes_used_in_Bitcoin_Script

If this is untrue, I can change this

@zhfnjust
Copy link

zhfnjust commented Aug 5, 2022

i can run this with js bsv.

i think OP_IF must followed by an OP_ENDIF, but OP_ELSE is not must be.

@zhfnjust
Copy link

zhfnjust commented Aug 5, 2022

image

@Firaenix
Copy link
Owner

Firaenix commented Aug 5, 2022

I'm not 100% certain, but it's worth checking against the Bitcoin SV node interpreter so get it 100% correct

@Firaenix
Copy link
Owner

Firaenix commented Aug 5, 2022

Alright I've found further documentation about OP_IF, etc.

https://wiki.bitcoinsv.io/index.php/Scripts_with_Flow_Control_(Conditional_Clauses)

I will fix up the library when I get a chance, thanks for raising this

@zhfnjust
Copy link

zhfnjust commented Sep 5, 2022

@Firaenix any. update

@torusJKL
Copy link

@Firaenix we would like to use bsv-wasm for powchess.com but we encounter the OP_IF OP_ELSE bug.
Can you give an estimate when you will be able to fix this?
Thanks!

@Firaenix
Copy link
Owner

Firaenix commented Oct 2, 2022

Sorry for the delay all, been very busy with Bitping work. I will have a look at getting it fixed this week

@Firaenix
Copy link
Owner

Firaenix commented Oct 3, 2022

Hi all, I've pushed a change to the split-modules branch, you can find the build for that branch below. Please let me know how you get on.

I still have to do some significant changes before I can get a release out onto npm, but this zip should get you by for now

https://github.com/Firaenix/bsv-wasm/raw/split-modules/packages/bsv-wasm/pkg/node.zip

@torusJKL
Copy link

torusJKL commented Oct 5, 2022

@Firaenix the types for the new version (from the above linked zip file) have changed.
e.g. Transaction.toHex() is now Transaction.to_hex()

Before I completely change all the function calls in our code I wanted to check if these new function names will persist in the new version.

@Firaenix
Copy link
Owner

Firaenix commented Oct 6, 2022

Yes they've changed significantly, I expect the new function signatures to be stable for the next release, which is 2.0.0

@trgsv
Copy link

trgsv commented Oct 10, 2022

Hey @Firaenix,
I'm currently running some tests with your new version and experienced a RuntimeError: unreachable when using Transaction.add_outputs().
Adding them all manually with Transaction.add_output() works as expected.

@torusJKL
Copy link

@Firaenix we have tested the new version with our scripts and we don't reproduce the OP_IF OP_ELSE errors anymore.
Looking forward to using the new release in production.

@Firaenix
Copy link
Owner

I have released this Feature to npm, deno.land and crates.io on Version 2.0.0.

https://crates.io/crates/bsv
https://www.npmjs.com/package/bsv-wasm

I'm going to close this issue

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

7 participants