Bitcoin Forum
December 15, 2024, 01:07:32 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Creating a Bitcoin suite for...... Excel VBA!  (Read 3692 times)
dabura667 (OP)
Sr. Member
****
Offline Offline

Activity: 475
Merit: 252


View Profile
August 23, 2014, 10:52:28 AM
 #1

Hi All.

As a method of studying VBA's ins and outs, I set out to build a Bitcoin suite that would perform some of the basic operations necessary for Bitcoin usage.

I currently have the following things (very poorly) implemented:

1. SHA256 class module (borrowed from Phil Fresle http://www.frez.co.uk)
2. RIPEMD160 class module (coded myself, used some Functions from SHA256 class)
3. A crypto module with a simple, super-inefficient implementation of SECP256K1 curve of EC math. (Add, Double, Multiply, Inverse Mod, etc.)
4. I have a simple sheet that will generate a "random" new address and show both compressed and uncompressed forms. AND it allows input for a brainwallet.

Goals:

1. Learn more about VBA and coding methodology for it. (for work...)
2. Make the crypto as efficient as possible. (Currently takes anywhere from 1 to 2 minutes (depending on PC specs) to perform one EC multiply with a 256 bit scalar.)
3. Implement BIP38, BIP32, and BIP39. (These will require writing/finding class modules for SHA512, HMAC, Scrypt, etc.)

Note:

- I am doing this with the intent of learning what VBA is possible of, and in the process gain the skills to implement macros etc. at my company to increase efficiency.
- Anyone else who thinks this is a fun little hobby-esque project and would like to help out, I would be more than happy if someone gave me pointers.
- The goal #3 probably won't go anywhere until I can clear #2.


Current Implementation:
https://www.dropbox.com/s/6meu983y0busbng/Bitcoin_Address_gen.xlsm
(All protected sheets etc. are protected with the password "password")

I will put the classes and modules separately up on Github if someone else wants to contribute.

Any pointers, musings at my horrible coding, trolls, etc. are welcome! But I would definitely appreciate any tips to make EC Multiplying faster.

Thank you all in advanced!

My Tip Address:
1DXcHTJS2DJ3xDoxw22wCt11FeAsgfzdBU
2112
Legendary
*
Offline Offline

Activity: 2128
Merit: 1073



View Profile
August 23, 2014, 07:05:03 PM
 #2

1. SHA256 class module (borrowed from Phil Fresle http://www.frez.co.uk)

1. Learn more about VBA and coding methodology for it. (for work...)
2. Make the crypto as efficient as possible. (Currently takes anywhere from 1 to 2 minutes (depending on PC specs) to perform one EC multiply with a 256 bit scalar.)
frez.co.uk is a quite awful source for coding examples, unless your goal is to make it work on non-Windows platforms (e.g. Microsoft Office for Macintosh or ASP emulators like Chilisoft, etc.).

I suggest that you learn how to use VBA as a "glue language" to invoke Windows Cryptographic Service Providers and then implement your own CSP or generic DCOM object in C/C++ and invoke it from VBA.

Following the examples from frez.co.uk is a sure way of developing substandard software for special purposes, e.g. milking consulting billable hours, creating fake benchmark baselines, etc. It still may be a viable business model though.

Please comment, critique, criticize or ridicule BIP 2112: https://bitcointalk.org/index.php?topic=54382.0
Long-term mining prognosis: https://bitcointalk.org/index.php?topic=91101.0
dabura667 (OP)
Sr. Member
****
Offline Offline

Activity: 475
Merit: 252


View Profile
August 23, 2014, 07:39:54 PM
 #3

I suggest that you learn how to use VBA as a "glue language" to invoke Windows Cryptographic Service Providers and then implement your own CSP or generic DCOM object in C/C++ and invoke it from VBA.

Sounds interesting. I'll have to look into it.

My Tip Address:
1DXcHTJS2DJ3xDoxw22wCt11FeAsgfzdBU
cloverme
Legendary
*
Offline Offline

Activity: 1512
Merit: 1057


SpacePirate.io


View Profile WWW
August 24, 2014, 12:20:19 AM
 #4

If you got a simple method for displaying the current BTC/USD price in a cell, that would be helpful for at least half a dozen people Cheesy

Samperio
Member
**
Offline Offline

Activity: 82
Merit: 10

Picture this: Francisco de Quevedo.


View Profile
August 24, 2014, 09:17:35 AM
 #5

Well, it's true what 2112 sats about the inefficiency of such implementation and sources consulted.

Then again, dabura667 already knew that and it's a quick way to get help people get the basics of coding and bitcoin. It's fun to browse the project and have a peek while, say, doing other office chores, (i.e. side-by-side with a boring accounting document... whenever it gets dumb and slow, I press alt f11 and get to tinker with the code! =D ). I just downloaded the spreadsheet and am getting my kicks while browsing the vbaproject!   -- not to mention it would be a motivation to open Visual Studio finally and try to do some interesting interfaces and integration.

This does remind me of a "project" I once wrote in one night for college, a 'database' implemented with excel worksheet and VBA precisely. Back then VBA was the novelty after the .XLM files.

So anyway, I'll be browsing the code as well as this thread. Eventually, this could be adapted as a learning aid, a tutorial, etc. I suppose it could go wherever we wanted for learning purposes.

S.

Bitcoin SPORTS BOOK .^. Poker .^. Casino .^.  NITROGENSPORTS
*-Join Here-* https://nitrogensports.eu/r/71524
dabura667 (OP)
Sr. Member
****
Offline Offline

Activity: 475
Merit: 252


View Profile
August 24, 2014, 01:09:32 PM
 #6

Found a couple bad bugs. Fixed one.

1. (Fixed, and updated the file on Dropbox) If the private key works out to a hex number less than 64 digits (32 bytes) long, it tries to add it in to the WIF privkey without adding any padding 0s, causing incorrect WIF private keys to be made. I added a parameter to the IntoHex function to set a length that will be padded if too short, and display a message box and terminate the process if too large (shouldn't be too large in the Sub there, because I mod it by the curve order)

2. Some times...... LargeMod somehow gets a "-" negative sign stuck in the middle of its numbers and throws errors in the other functions... I set up some traps with "DoEvent" so that I can set breakpoints on those problem areas... but I messed up and deleted the private key which was causing the bug... and now I've tried about 500 different private keys (each key having hundreds of LargeMod passes in its calculations) and still haven't been able to find another instance of this bug... Seems very rare.

Again, this is NOT for serious use.

I just came here looking for VBA pointers, AND to share what I did with the community in case someone can polish it up into a super beefy efficient machine of an Excel book.

If anyone has any good resources for using VBA as a "gluing language" (ie. how would I implement calls to C+/C code / Windows libraries? Would those all be bundled up in the excel book? etc.) any links or advice would be appreciated.

My Tip Address:
1DXcHTJS2DJ3xDoxw22wCt11FeAsgfzdBU
Samperio
Member
**
Offline Offline

Activity: 82
Merit: 10

Picture this: Francisco de Quevedo.


View Profile
August 24, 2014, 03:23:00 PM
 #7

Right. So, to start with, you could see how windows standard libraries (DLLs in this case) are called.

(I believe there are no declarations like that in your code, otherwise you'd already know; so this might or might not be helpful as a start).

Take a look at some declarations for some API calls I call directly from a VB (or VBA) project.

"user32" refers to user32.dll

----------------

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10

Bitcoin SPORTS BOOK .^. Poker .^. Casino .^.  NITROGENSPORTS
*-Join Here-* https://nitrogensports.eu/r/71524
dabura667 (OP)
Sr. Member
****
Offline Offline

Activity: 475
Merit: 252


View Profile
August 27, 2014, 10:27:50 AM
 #8

Right. So, to start with, you could see how windows standard libraries (DLLs in this case) are called.

(I believe there are no declarations like that in your code, otherwise you'd already know; so this might or might not be helpful as a start).

Take a look at some declarations for some API calls I call directly from a VB (or VBA) project.

"user32" refers to user32.dll

----------------

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10


Thanks for the tip.

Do you know any source that can explain these types of libraries that are default on a windows machine? (we use Windows 7)

Also if you could point me to BigInt classes and/or any crypto libraries that can perform calcs with SECP256K1 that'd be awesome!

Thanks for the pointers!

My Tip Address:
1DXcHTJS2DJ3xDoxw22wCt11FeAsgfzdBU
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!