Git Product home page Git Product logo

Comments (7)

kallewoof avatar kallewoof commented on May 26, 2024

I haven't, but that sounds very interesting. I was actually looking at Ivy the other day, wondering if some integration would be possible somehow.

I'll look at emscripten.

from btcdeb.

kallewoof avatar kallewoof commented on May 26, 2024

@danrobinson I tried emscripten, and it seems to sort of work. I pushed some tweaks to get it through the compilation process.

Some notes:

  • To convert into .js, it wants the file to have the extension .bc but the files end up without extension (on mac/linux). Simply renaming e.g. btcc to btcc.bc and then running emcc works.
  • libsecp256k1 seems to cause issues. Seeing a bunch of these:
WARNING:root:object /private/var/folders/b8/znqr8hj918772gfmd875gzgdd3ypz1/T/emscripten_temp_bAIT8q_archive_contents/libsecp256k1_02185e94.la is not valid, cannot link
  • btcc seems to work out of the box:
$ node btcc.js OP_1 OP_2 OP_ADD
515293
  • btcdeb does not get the prompt. Probably because of the libreadline use (the configure calls correctly notices no readline, so that's not it). emscripten doesn't seem to like dynamic libs.

from btcdeb.

kallewoof avatar kallewoof commented on May 26, 2024

I've gotten it mostly working, but I think the secp256k1 linking is not functional so any signing or ECDSA stuff will fail. The big issue that remains is that the command prompt for btcdeb is not functional. You can still "use" it by doing e.g.

$ echo -n -e "step\n\n\n\n" | node btcdeb.js '[OP_1 OP_2 OP_ADD]'
btcdeb -- type `btcdeb.js -h` for start up options
valid script
3 op script loaded. type `help` for usage information
script  |  stack
--------+--------
1       |
2       |
OP_ADD  |
#0001 1
		<> PUSH stack 01
btcdeb> script  |  stack
--------+--------
2       |      01
OP_ADD  |
#0002 2
		<> PUSH stack 02
btcdeb> script  |  stack
--------+--------
OP_ADD  |      02
        |      01
#0003 OP_ADD
		<> POP  stack
		<> POP  stack
		<> PUSH stack 03
btcdeb> script  |  stack
--------+--------
        |      03
btcdeb> script  |  stack
--------+--------
        |      03
$ 

Mastify seems to work fine:

$ node mastify --multisig=2 0375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c 03a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff=3045022100c56ab2abb17fdf565417228763bc9f2940a6465042fd62fbd9f4c7406345d7f702201cb1a56b45181f8347713627b325ec5df48fc1aee6bdaf937cbb804d7409b10c01 03c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f880=304402207f874ef00f11dcc9a621acad9354f3fca1bf90c43878f607b7e2d358088487e7022052a01b47b8eef5e1c96a6affdc3dac46fdc11b60612464dc8c5921a852090d2701
root: e2e72696520c01264ca5e1f96db6df6056dc99fc6701195973520e4045e5bbf8
branch: [
	be069fba729c054a93ecd25a5224b089e15321f28d870dd7313b91d304da95d7
]
path: 1
proof: 01c001be069fba729c054a93ecd25a5224b089e15321f28d870dd7313b91d304da95d7
unlocking script: TOALTSTACK TOALTSTACK e2e72696520c01264ca5e1f96db6df6056dc99fc6701195973520e4045e5bbf8 OP_2 OP_MERKLEBRANCHVERIFY 2DROP DROP
- script (hex): 6b6b20e2e72696520c01264ca5e1f96db6df6056dc99fc6701195973520e4045e5bbf852b36d75
stack:
- item #1:  6c6c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feffad2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f880ac
- item #2:  01c001be069fba729c054a93ecd25a5224b089e15321f28d870dd7313b91d304da95d7
- argument: 0x304402207f874ef00f11dcc9a621acad9354f3fca1bf90c43878f607b7e2d358088487e7022052a01b47b8eef5e1c96a6affdc3dac46fdc11b60612464dc8c5921a852090d2701
- argument: 0x3045022100c56ab2abb17fdf565417228763bc9f2940a6465042fd62fbd9f4c7406345d7f702201cb1a56b45181f8347713627b325ec5df48fc1aee6bdaf937cbb804d7409b10c01

Merklebranch seems to work:

$ node merklebranch --position=1 '[OP_FROMALTSTACK OP_1 OP_EQUAL]' '[OP_FROMALTSTACK OP_2 OP_EQUAL]'
leaves: [
	9e2232a0e2a41073464bdd218fa4ae9221b20ce93af704dceb0db1a0aa253fed
	f8a336fb07fd7b49da152135f5a1edea322d76b75c73f913c4aac7e8e6da3e31
]
root: 90658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c56598885e64d
branch: [
	9e2232a0e2a41073464bdd218fa4ae9221b20ce93af704dceb0db1a0aa253fed
]
path: 1
proof: 01c0019e2232a0e2a41073464bdd218fa4ae9221b20ce93af704dceb0db1a0aa253fed
unlocking proposal (1 parameter):
- script:       TOALTSTACK 90658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c56598885e64d OP_2 OP_MERKLEBRANCHVERIFY 2DROP DROP
- script (hex): 6b2090658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c56598885e64d52b36d75
stack:
- item #1:       [OP_FROMALTSTACK OP_2 OP_EQUAL]
- item #1 (hex): 6c5287
- item #2:       01c0019e2232a0e2a41073464bdd218fa4ae9221b20ce93af704dceb0db1a0aa253fed
- item #3+:      (argument to script at item #1)

Passing merklebranch into btcdeb works too.

$ echo -n -e "step\n\n\n\n\n\n" | node btcdeb $(node merklebranch --btcdeb --position=3 '[FROMALTSTACK OP_1 EQUAL]' '[FROMALTSTACK OP_2 EQUAL]' '[FROMALTSTACK OP_3 EQUAL]' '[FROMALTSTACK OP_4 EQUAL]' '[FROMALTSTACK OP_5 EQUAL]') 04
btcdeb -- type `/Users/karljohan-alm/workspace/btcdeb/btcdeb -h` for start up options
valid script
6 op script loaded. type `help` for usage information
script                                                           |                                                             stack
-----------------------------------------------------------------+-------------------------------------------------------------------
OP_TOALTSTACK                                                    |                                                                 04
4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4 | 037f000390658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c565...
2                                                                |                                                             6c5487
OP_MERKLEBRANCHVERIFY                                            |
OP_2DROP                                                         |
OP_DROP                                                          |
#0001 OP_TOALTSTACK
		<> PUSH altstack 04
		<> POP  stack
btcdeb> script                                                           |                                                             stack
-----------------------------------------------------------------+-------------------------------------------------------------------
4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4 | 037f000390658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c565...
2                                                                |                                                             6c5487
OP_MERKLEBRANCHVERIFY                                            |
OP_2DROP                                                         |
OP_DROP                                                          |
#0002 4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4
		<> PUSH stack 4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4
btcdeb> script                                                           |                                                             stack
-----------------------------------------------------------------+-------------------------------------------------------------------
2                                                                |   4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4
OP_MERKLEBRANCHVERIFY                                            | 037f000390658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c565...
OP_2DROP                                                         |                                                             6c5487
OP_DROP                                                          |
#0003 2
		<> PUSH stack 02
btcdeb> script                                                           |                                                             stack
-----------------------------------------------------------------+-------------------------------------------------------------------
OP_MERKLEBRANCHVERIFY                                            |                                                                 02
OP_2DROP                                                         |   4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4
OP_DROP                                                          | 037f000390658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c565...
                                                                 |                                                             6c5487
#0004 OP_MERKLEBRANCHVERIFY
[MBV] check: stack size 4 >= 3
[MBV] vchCount [1] = 02
[MBV] vchRoot  [32] = 4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4
[MBV] vchProof [100] = 037f000390658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c56598885e64d1d3b5bad759a6eeeb8e48dfcfc1b7b802a7256ec87a7b2e2c04d54c56487a22a256836c0cb68f9f3189cfff8e5f033ea7a5ee32148f377405e0971036c950f80
[MBV] count = 1 (prehashed = false)
[MBV] check: stack size 4 >= (3 + count 1)
[MBV] get leaf 0 = 6c5487
[MBV] leaf hash = 19edcbd43bbfbac53b960bc34e4609bae6655008193820ca12afa7dd4e0f96a8
merkle root hash = 4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4
given root hash  = 4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4
btcdeb> script                                                           |                                                             stack
-----------------------------------------------------------------+-------------------------------------------------------------------
OP_2DROP                                                         |                                                                 02
OP_DROP                                                          |   4cae2f5573c5728f37f1a610ff01f8f4adba6474e71d5a50c1354292d04e74a4
                                                                 | 037f000390658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c565...
                                                                 |                                                             6c5487
#0005 OP_2DROP
		<> POP  stack
		<> POP  stack
btcdeb> script                                                           |                                                             stack
-----------------------------------------------------------------+-------------------------------------------------------------------
OP_DROP                                                          | 037f000390658083c0751863dceb7f8874f170be082c70c8b282b7df2c0c565...
                                                                 |                                                             6c5487
#0006 OP_DROP
		<> POP  stack
btcdeb> script                                                           |                                                             stack
-----------------------------------------------------------------+-------------------------------------------------------------------
                                                                 |                                                             6c5487

from btcdeb.

kallewoof avatar kallewoof commented on May 26, 2024

Compilation steps:

$ make clean
$ emconfigure ./configure
$ emmake make
$ for i in btcdeb btcc mastify merklebranch; do mv $i $i.bc && emcc -O2 $i.bc libbitcoin.a -o $i.js; done

from btcdeb.

kallewoof avatar kallewoof commented on May 26, 2024

Update: I tried to verify a signature using btcdeb, and it actually works. I'm not sure what that warning about libsecp256k1 is about.

from btcdeb.

danrobinson avatar danrobinson commented on May 26, 2024

Works great! Thanks for going through the trouble. I'd suggest adding the build instructions to the Readme, then I think this issue is solved.

I'll take a look at adding it to Ivy in the next few days.

from btcdeb.

kallewoof avatar kallewoof commented on May 26, 2024

Yep, will do. Let me know if you need anything from my end.

from btcdeb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.