bsv-wasm icon indicating copy to clipboard operation
bsv-wasm copied to clipboard

Support Script interpreter

Open xhliu opened this issue 2 years ago • 15 comments

to speed up Bitcoin VM.

xhliu avatar Mar 22 '22 05:03 xhliu

In the works :)

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

Firaenix avatar Mar 22 '22 05:03 Firaenix

ceo of testnet approved

utxo-detective avatar Mar 22 '22 06:03 utxo-detective

@xhliu You're gonna love this ;)

deanmlittle avatar Mar 22 '22 06:03 deanmlittle

Can't wait, CEO/CTO.

xhliu avatar Mar 23 '22 05:03 xhliu

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

xhliu avatar Jul 04 '22 07:07 xhliu

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

Firaenix avatar Jul 06 '22 10:07 Firaenix

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

zhfnjust avatar Aug 01 '22 06:08 zhfnjust

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

Firaenix avatar Aug 01 '22 19:08 Firaenix

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

Firaenix avatar Aug 02 '22 12:08 Firaenix

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 .

zhfnjust avatar Aug 02 '22 16:08 zhfnjust

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

Firaenix avatar Aug 03 '22 14:08 Firaenix

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 avatar Aug 05 '22 14:08 zhfnjust

image

zhfnjust avatar Aug 05 '22 14:08 zhfnjust

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

Firaenix avatar Aug 05 '22 14:08 Firaenix

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

Firaenix avatar Aug 05 '22 14:08 Firaenix

@Firaenix any. update

zhfnjust avatar Sep 05 '22 05:09 zhfnjust

@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!

torusJKL avatar Sep 29 '22 22:09 torusJKL

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

Firaenix avatar Oct 02 '22 03:10 Firaenix

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

Firaenix avatar Oct 03 '22 03:10 Firaenix

@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.

torusJKL avatar Oct 05 '22 20:10 torusJKL

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

Firaenix avatar Oct 06 '22 02:10 Firaenix

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.

trgsv avatar Oct 10 '22 13:10 trgsv

@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.

torusJKL avatar Oct 10 '22 19:10 torusJKL

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

Firaenix avatar Oct 13 '22 05:10 Firaenix