How can I verify if the block added to the Klaytn Blockchain was actually validated by 2/3 of the committee members? If somebody could suggest on what APIs I could potentially use that would be of great help.
How can i re-calculate a block hash and what are the fields involved?
I am aware that a random committee is chosen by VRF for consensus, but how are those members chosen, is it an entirely random process or depends on the staked KLAYs ? What increases the chances of a member to be selected in a committee ?
First, you can find our consensus mechanism in Klaytn Docs
There are 2/3 or more signatures from the committee members in the block header. You can find the source code related to this here. We don’t have such an API that shows the addresses and signature validation results for the committee members. Sorry for that.
You can find the source code related to calculate the block hash here. In short, all the fields in the header are involved. You can find the header fields here.
The chances to be selected as a proposer are related to the number of KLAY staked. But, the chances to be selected as a committee member is just random based on the previous block hash.
Hope this helps. If you have more questions, please let us know.
Thanks.
Sorry for that, we don’t have existing tool for that right now.
Could you tell me why you need this? Making the tool is not that difficult using the code references, though.
We are in process of evaluating the reliability of Klaytn blockchain. We see the protocol requires 2/3 of the committee members to sign/validate before the block can be appended to the ledger. This is an important control to preserve the integrity of the information being recorded in the blockchain. Hence, we would like to validate that the protocol is working as intended and as designed.
We don’t have a tool for that currently. To validate all the blocks with the committee information, it is somewhat complicated. Basically we should validate two things:
Find the committee members of every block.
Validate 2/3 members are signed to the block.
Each block contains 2/3 or more signatures in the committed seal in the extra field of the block header, but the whole committee members are not recorded in the block. You can find committee members by executing the same algorithm coded in Klaytn.
Thank you for the information. It was quite helpful.
I’m following the link shared above for the block hash calculation, and because I’m not well versed in the GO language, I have trouble debugging it.
Is there any other way to re-calculate the hash to validate it with the actual block hash? Are there any caver.js functions that could be of help?
Also, I learned that one of the major differences between ethhash and IBFT hash is that we replace the committed seal information with an empty array of bytes in the extradata field. Does Klaytn have any existing functions/ API to do this? Please help me with the links if so.
Is there any other way to re-calculate the hash to validate it with the actual block hash? Are there any caver.js functions that could be of help?
Sorry for that. caver-js does not have such a function. It is not a common usage of caver-js.
To make sure, is this what you want?
Calculate the block hash based on the given fields of a block.
Does Klaytn have any existing functions/ API to do this?
We have the function in Klaytn, but it is not exposed as an API, which is not a common usage. I can give you a command so that you can execute above two functions If needed. Before that, please give the exact input/output for the function you want.
Yes, your understanding is correct and that is the sole purpose of my test. I am trying to re-calculate the block hash based on the fields of the block and validate it against the actual block hash recorded on Klaytn Blockchain (the “hash” field)
This will help a lot, Please find the input/output below :
For Block Hash calculation : Input : Fields in the block (response of klay.getBlock() function) [attached screenshot]
Output : Re-calculated Block Hash based on the input
For Istanbul Extra : Input : The “extradata” field extracted from the response of klay.getBlock() [attached above with 1] Output : Decoded IstanbulExtra struct
I am trying to convert the data fields from GetBlock into the Header struct data types for all the required fields and running into errors when extracting Istanbul extradata.
These are the type conversions i am doing to map these to actual Header struct fields :