-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merkle Tree structure * RLP Encoding of Merkle Trees * Add update logic for MerkleExtension * Add spec proof for Merkle Tree * Add update logic for .MerkleTree * Add update logic for MerkleLeaf * Add update logic for MerkleBranch * Fix change requests
- Loading branch information
1 parent
e3ea413
commit 9a1e580
Showing
3 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
requires "evm.k" | ||
|
||
module VERIFICATION | ||
imports EVM | ||
|
||
syntax StepSort ::= MerkleTree | String | ||
syntax KItem ::= runMerkle ( StepSort ) | ||
| doneMerkle( StepSort ) | ||
// ------------------------------------------ | ||
rule runMerkle( T ) => doneMerkle( T ) | ||
|
||
endmodule | ||
|
||
module MERKLE-SPEC | ||
imports VERIFICATION | ||
|
||
rule <k> runMerkle ( MerkleUpdate( .MerkleTree, .WordStack, VALUE ) ) | ||
=> doneMerkle( MerkleLeaf( .WordStack, VALUE ) ) </k> | ||
|
||
// Update on MerkleLeaf | ||
rule <k> runMerkle ( MerkleUpdate( MerkleLeaf( 6 : 7 : .WordStack, _ ), 6 : 7 : .WordStack, V ) ) | ||
=> doneMerkle( MerkleLeaf ( 6 : 7 : .WordStack, V ) ) </k> | ||
|
||
rule <k> runMerkle ( MerkleUpdate( MerkleLeaf( 6 : 7 : .WordStack, _ ), 6 : 8 : .WordStack, _ ) ) | ||
=> doneMerkle( MerkleExtension( 6 : .WordStack, _ ) ) </k> | ||
|
||
rule <k> runMerkle ( MerkleUpdate( MerkleLeaf( 5 : .WordStack, _ ), 6 : .WordStack, _ ) ) | ||
=> doneMerkle( MerkleBranch( _, _ ) ) </k> | ||
|
||
// Update on MerkleExtension | ||
rule <k> runMerkle ( MerkleUpdate( MerkleExtension( 6 : .WordStack, .MerkleTree ), 6 : .WordStack, V ) ) | ||
=> doneMerkle( MerkleExtension( 6 : .WordStack, MerkleLeaf( .WordStack, V ) ) ) </k> | ||
|
||
rule <k> runMerkle ( MerkleUpdate( MerkleExtension( 7 : .WordStack, _ ), 6 : .WordStack, _ ) ) | ||
=> doneMerkle( MerkleBranch( _, _ ) ) </k> | ||
|
||
rule <k> runMerkle ( MerkleUpdate( MerkleExtension( 7 : 8 : .WordStack, _ ), 7 : 9 : .WordStack, _ ) ) | ||
=> doneMerkle( MerkleExtension( 7 : .WordStack, MerkleBranch( _, _ ) ) ) </k> | ||
|
||
// Update on MerkleBranch | ||
rule <k> runMerkle ( MerkleUpdate( MerkleBranch( M, _ ), .WordStack, V ) ) | ||
=> doneMerkle( MerkleBranch( M, V ) ) </k> | ||
|
||
rule <k> runMerkle ( .MerkleBranch ) | ||
=> doneMerkle( MerkleBranch ( 0 |-> .MerkleTree 1 |-> .MerkleTree 2 |-> .MerkleTree 3 |-> .MerkleTree | ||
4 |-> .MerkleTree 5 |-> .MerkleTree 6 |-> .MerkleTree 7 |-> .MerkleTree | ||
8 |-> .MerkleTree 9 |-> .MerkleTree 10 |-> .MerkleTree 11 |-> .MerkleTree | ||
12 |-> .MerkleTree 13 |-> .MerkleTree 14 |-> .MerkleTree 15 |-> .MerkleTree | ||
, "" | ||
) | ||
) | ||
</k> | ||
|
||
// Concrete Test | ||
rule <k> runMerkle ( Keccak256( #rlpEncodeMerkleTree( MerkleUpdate( MerkleUpdate( MerkleUpdate( MerkleUpdate( .MerkleTree, "do", "verb" ), "horse", "stallion" ), "doge", "coin" ), "dog", "puppy" ) ) ) ) | ||
=> doneMerkle( "5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84" ) </k> | ||
|
||
endmodule |