Wednesday, May 30, 2018

The Ethereum's Proof of Work

Information about BitCoin proof of work is easily accessible in the whole internet, but what about the Ethreum Proof of Work? It has not been very easy for me to retrieve the technical information I was looking for and put them together in a way that could be easily understood.

Let's start at the beginning: what the proof of work is and why it is necessary.


Proof of work means that something satisfies the requirement of an expensive computer calculation. In fact, in a blockchain system as Ethereum, where the consensus is based on the proof of work, every transaction needs a lot of computer calculation to be done before it can be considered closed and "valid". The objective is to avoid DDoS (distributed denial of service) attacks to the network. In this specific scenario, the purpose is to avoid distributed attempts to close "forged" transactions. Given that, for closing a transaction a lot of calculation is needed, it would be really hard to execute a successful attack, where a lot of fake transactions should be closed (and received and spread) faster than any other node on the network. Considering that normally nodes which close transactions (the so called mining process) are remunerated with "ether" (the Ethereum's crypto currency), even if someone has the necessary calculation power, maybe it is more remunerative to close real transactions than to try to close the forged ones.

The Ethereum Proof of Work algorithm, Ethash


The algorithm used by the Ethereum blockchain, is known as Ethash, and is quite similar to the bitcoin one, but with some differences. For example, a lot more memory is needed and the majority of a miner's effort will be spent reading a great set of data then making changes to it. But let's go into details, and try to put it in a way which is easily understandable.

Everything starts with the seed. The seed is a 32 digit number and actually it is the basis of the mining process. It is calculated looping through the headers of the current block and applying a variant of the SHA3 algorithm. The results are joined together and combined into the 32 digit number mentioned before.

From the seed, a 32 MB random cache using a combination of the SHA3 algorithm and a random memory hash algorithm (Strict Memory Hard Hashing Functions) is then calculated. The SHA3 algorithm is applied repeatedly to the seed until we get a 32 MB memory string. This one is subsequently double passed by the random memory hash algorithm. The result is a set of 524288 64-byte values.

From the cache a 1 GB dataset combining data from 256 cache nodes is generated. The dataset is stored in miners and full clients and grows linearly during the time. This gives an idea of why the majority of a miner's effort will be reading the data (a big amount of).

The mining process consists of taking slices of the dataset (nounce) and combining them with a header until the algorithm gets a result value below a desired target. This is when the miner has succeeded in closing a block.
The header is the hash of a truncated block header that is keep fixed. The nounce is 128 bytes of sequencially read data from the dataset (taken from random nodes). The mining loop keeps the header fixed and tries to combine it with all the different nounces until calculating the desired result.

That's it, a quite simplified, but still technical, explanation of how the proof of work "works" inside the Ethereum network. More detailed information can be found on the official Ethreum wiki.

It is worth saying that the network wants to move from a process where consensus is based on the proof of work, to a system where the consensus is based on the proof of stake, and later we'll talk about that too.

Monday, June 23, 2014

IIS Could not load file or assembly 'App_Web_..., Version=0.0.0.0

Message

Could not load file or assembly 'App_Web_..., Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.


Context

Opening an ASP.NET page on a IIS web server.


Explanation

An unhandled exception occurred during the execution of the current web request. Precisely a System.IO.FileNotFoundException. This error may happen when the website is trying to load a custom web control that is displayed as needed. When the framework try to compile it, appends a random string at the end of the assemby. If another control referes to this one, at compile time the name of the newly compiled file and the previous version of the file cause a file name mismatch and therefore the parent control is looking for a file that no longer exists.


Solution

Setting the batch property of the compilation tag to false in the web.config file:

<compilation debug="false" batch="false" />


Thursday, January 3, 2013

Visual Studio Could not load file or assembly bug

Message

Could not load file or assembly ... or one of its dependencies.

Context

Opening a form in Design Mode in Visual Studio 2010

Explanation

The Copy Local property of a referenced DLL appears to be true, but actually it is not set to True in the XML project file.

Looking inside the XML file:

<Reference Include="...">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\C1.Win.C1FlexGrid.4.dll</HintPath>
<Private>True</Private>
</Reference>

We should see a code like this one, but the yellow line "<Private>True</Private>", that is the one corresponding to the Copy Local property value, is missing.

Solution

The line could be manually inserted, but better proceed this way:
  1. Right click on the DLL that is giving the problem.
  2. Set the Copy Local property to False.
  3. Save the projetct
  4. Set the Copy Local property back to True.
  5. Save the project again.
This will cause Visual Studio to add the missing line "<Private>True</Private>".

Wednesday, February 22, 2012

Access Denied even to SharePoint Administrator

Message
Access Denied.
Editing/Settings are NOT enabled even for administrators.

Context
SharePoint Site Collection, maybe after backup/restore a site collection

Explanation
The Site Collection is in "Read only" mode. Maybe due to a stsadm backup brutally interrupted.

Solution
Open the SharePoint Central Administration. Under Application Magement, click on the "Configure quotas and locks" link. Than have a look under the section "Site Lock Information" and be sure it is selected "Not locked" option.

Monday, February 20, 2012

UnauthorizedAccessException opening UNC path file with FileStream


Message
UnauthorizedAccessException: Access to the path '...' is denied.


Context
Executing the following line of code (C# ASP.NET under Visual Studio, localFile or UNC path)

FileStream fs = new FileStream(fileName, FileMode.Open);

Explanation
ND

Solution
Add the fileaccess mode option "FileAccess.Read":
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);

Monday, February 13, 2012

The Operation Could not be Completed

Message
Starting the debugger process (debugging) in Visual Studio after changing some settings (i.e. in the app.config file) it comes out a popup with the following message: The Operation Could not be completed. 

Context
Debugging on Visual Studio 2008 or Visual Studio 2010

Explanation
Visual Studio doesn't delete the vshost.exe files in the application folder after launching debug. It looks like a Visual Studio bug. The vshost.exe files needs to be manually killed after debugging, or we need to close and reload the project.

Solution
Go to the Property window of your project, open the de "Debug" tab, look for the "Enable the Visual Studio hosting process" option and uncheck/disable that option.

Friday, February 10, 2012

Enabling IntelliSense for Client Object Model script in Visual Studio

Message
A simple way to enable/activate IntelliSense in Visual Studio while writing ECMA script. It allows, for example,  to write your javascript or jQuery code for SharePoint saving you a lot of time.
Some references: http://msdn.microsoft.com/en-us/library/ff798328.aspx

Context
Visual Studio 2010, SharePoint 2010, Visual WebPart

Explanation
Following is the list of debug .js files present in _layouts folder and depending upon the objects you are working with, you may need to add a reference to any of them to get IntelliSense.
  • SP.debug.js (to get IntelliSense on list objects)
  • SP.Core.debug.js
  • SP.Ribbon.debug.js
  • SP.Runtime.debug.js
  • JsGrid.debug.js
  • JsGrid.Gantt.debug.js


Solution
Add following lines at the start of the .ascx file in a visual webpart.

<script type="text/javascript" src="/_layouts/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/SP.Debug.js"></script>
<script type="text/javascript" src="/_layouts/SP.Core.debug.js">

PS: Exclude these references while deploying the code to production environment.