Last active
February 13, 2017 18:27
-
-
Save yaronvel/07655c8ffea9e5d144038a19d392e741 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function verifyAgt( uint leaf32BytesHash, | |
| uint leafCounter, | |
| uint branchIndex, | |
| uint[] countersBranch, | |
| uint[] hashesBranch ) constant returns(bool) { | |
| uint currentHash = leaf32BytesHash & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; | |
| uint leftCounterMin; | |
| uint leftCounterMax; | |
| uint leftHash; | |
| uint rightCounterMin; | |
| uint rightCounterMax; | |
| uint rightHash; | |
| uint min = leafCounter; | |
| uint max = leafCounter; | |
| for( uint i = 0 ; i < countersBranch.length ; i++ ) { | |
| if( branchIndex & 0x1 > 0 ) { | |
| leftCounterMin = countersBranch[i] & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; | |
| leftCounterMax = countersBranch[i] >> 128; | |
| leftHash = hashesBranch[i]; | |
| rightCounterMin = min; | |
| rightCounterMax = max; | |
| rightHash = currentHash; | |
| } | |
| else { | |
| leftCounterMin = min; | |
| leftCounterMax = max; | |
| leftHash = currentHash; | |
| rightCounterMin = countersBranch[i] & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; | |
| rightCounterMax = countersBranch[i] >> 128; | |
| rightHash = hashesBranch[i]; | |
| } | |
| currentHash = uint(sha3(leftCounterMin + (leftCounterMax << 128), | |
| leftHash, | |
| rightCounterMin + (rightCounterMax << 128), | |
| rightHash)) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; | |
| if( (leftCounterMin >= leftCounterMax) || (rightCounterMin >= rightCounterMax) ) { | |
| if( i > 0 ) return false; | |
| if( leftCounterMin < leftCounterMax ) return false; | |
| if( rightCounterMin < rightCounterMax ) return false; | |
| } | |
| if( leftCounterMax >= rightCounterMin ) return false; | |
| min = leftCounterMin; | |
| max = rightCounterMax; | |
| branchIndex = branchIndex / 2; | |
| } | |
| if( min != rootMin ) return false; | |
| if( max != rootMax ) return false; | |
| if( currentHash != rootHash ) return false; | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment