Skip to content

Commit c412da4

Browse files
gtreptarv-jenkins
authored andcommitted
receiptsRoot (#539)
* RLP encoding of receipts * Build receiptsRoot * Add firefly_getReceiptsRoot * receiptsRoot tests
1 parent 061d899 commit c412da4

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"jsonrpc":"2.0","id":1,"result":true},{"jsonrpc":"2.0","id":2,"result":true},{"jsonrpc":"2.0","id":3,"result":"0x2c11d46cf3df0566ee4b6c49c8dcc1197ec796dbbf267b4d03eacd5ada85f469"},{"jsonrpc":"2.0","id":4,"result":{"receiptsRoot":"0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2"}}]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[{
2+
"jsonrpc":"2.0",
3+
"id":1,
4+
"method":"firefly_addAccount",
5+
"params":[{
6+
"key":"0xcdeac0dd5ec7c04072af48f2a4451e102a80ca5bb441a7b4d72c176cea61866e",
7+
"balance":"0x56bc75e2d63100000"
8+
}]
9+
},
10+
{
11+
"jsonrpc":"2.0",
12+
"id":2,
13+
"method":"firefly_addAccount",
14+
"params":[{
15+
"key":"0xf9eaf090058471f8ddb294ddeae71ff056b631420e6bdce27d90f3c1a8c74124",
16+
"balance":"0x56bc75e2d63100000"
17+
}]
18+
},
19+
{
20+
"jsonrpc": "2.0",
21+
"id": 3,
22+
"method": "eth_sendTransaction",
23+
"params": [
24+
{
25+
"from": "0x911392821a6B8a3e0bD8078fC7403E04C3ad2416",
26+
"to": "0x0093Ffb8D72408c1ab2547505A9914F0cF1F1298",
27+
"value": "0x500",
28+
"gasPrice": "0x4a817c800"
29+
}
30+
]
31+
},
32+
{
33+
"jsonrpc": "2.0",
34+
"id": 4,
35+
"method": "firefly_getReceiptsRoot",
36+
"params": []
37+
}]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"jsonrpc":"2.0","id":1,"result":true},{"jsonrpc":"2.0","id":2,"result":true},{"jsonrpc":"2.0","id":3,"result":"0xdb1def0efd9cf3bdceae1f04a32e92e0a84e921ef3a9cb22ea4a58f7836cd6fc"},{"jsonrpc":"2.0","id":4,"result":{"receiptsRoot":"0x86a171c58aac4ccaded4964d3c32649cd968d42b7fbf11cb10087e4bb65c5a6f"}}]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[{
2+
"jsonrpc":"2.0",
3+
"id":1,
4+
"method":"firefly_addAccount",
5+
"params":[{
6+
"key":"0xcdeac0dd5ec7c04072af48f2a4451e102a80ca5bb441a7b4d72c176cea61866e",
7+
"balance":"0x56bc75e2d63100000"
8+
}]
9+
},
10+
{
11+
"jsonrpc":"2.0",
12+
"id":2,
13+
"method":"firefly_addAccount",
14+
"params":[{
15+
"address":"0x116fe73b49c56e5e78f307e360a95760242d5fc1",
16+
"code":"0x60806040523480156100115760006000fd5b50600436106100305760003560e01c80636d4ce63c1461003657610030565b60006000fd5b61003e610060565b604051808263ffffffff1663ffffffff16815260200191505060405180910390f35b60007f82cce92e3ae3d5367097cf20110c99ac1345c871cec5df94c0438746d353480c3033602a604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390a1602a905061010b565b9056fea265627a7a723158205e68d0e49a57e24f791b1fb1ead9612a2759953757912fceda99b775f7f8b8e364736f6c634300050b0032"
17+
}]
18+
},
19+
{
20+
"jsonrpc": "2.0",
21+
"id": 3,
22+
"method": "eth_sendTransaction",
23+
"params": [
24+
{
25+
"from": "0x911392821a6B8a3e0bD8078fC7403E04C3ad2416",
26+
"to": "0x116fe73b49c56e5e78f307e360a95760242d5fc1",
27+
"data": "0x6d4ce63c",
28+
"gasPrice": "0x4a817c800"
29+
}
30+
]
31+
},
32+
{
33+
"jsonrpc": "2.0",
34+
"id": 4,
35+
"method": "firefly_getReceiptsRoot",
36+
"params": []
37+
}]

web3.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ WEB3 JSON RPC
321321
<method> "firefly_getStateRoot" </method>
322322
rule <k> #runRPCCall => #firefly_getTxRoot ... </k>
323323
<method> "firefly_getTxRoot" </method>
324+
rule <k> #runRPCCall => #firefly_getReceiptsRoot ... </k>
325+
<method> "firefly_getReceiptsRoot" </method>
324326
325327
rule <k> #runRPCCall => #sendResponse( "error": {"code": -32601, "message": "Method not found"} ) ... </k> [owise]
326328
@@ -1222,6 +1224,51 @@ Helper Funcs
12221224
<sigS> S </sigS>
12231225
<sigV> V </sigV>
12241226
</message>
1227+
1228+
syntax String ::= #rlpEncodeReceipt( Int ) [function]
1229+
| #rlpEncodeReceiptAux( String ) [function]
1230+
// -----------------------------------------------------------
1231+
rule #rlpEncodeReceipt( I ) => #rlpEncodeReceiptAux( "0x" +String #hashSignedTx( I ) )
1232+
rule [[ #rlpEncodeReceiptAux( TXHASH ) =>
1233+
#rlpEncodeLength( #rlpEncodeWord( STATUS )
1234+
+String #rlpEncodeWord( CGAS )
1235+
+String #rlpEncodeString( #asString( BLOOM ) )
1236+
+String #rlpEncodeLogs( LOGS )
1237+
, 192
1238+
)
1239+
]]
1240+
<txReceipt>
1241+
<txHash> TXHASH </txHash>
1242+
<txCumulativeGas> CGAS </txCumulativeGas>
1243+
<logSet> LOGS </logSet>
1244+
<bloomFilter> BLOOM </bloomFilter>
1245+
<txStatus> STATUS </txStatus>
1246+
</txReceipt>
1247+
1248+
syntax String ::= #rlpEncodeLogs ( List ) [function]
1249+
| #rlpEncodeLogsAux( List ) [function]
1250+
// ------------------------------------------------------
1251+
rule #rlpEncodeLogs( .List ) => "\xc0"
1252+
rule #rlpEncodeLogs( LOGS ) => #rlpEncodeLength( #rlpEncodeLogsAux( LOGS ), 192 )
1253+
requires LOGS =/=K .List
1254+
1255+
rule #rlpEncodeLogsAux( .List ) => ""
1256+
rule #rlpEncodeLogsAux( ListItem({ ACCT | TOPICS | DATA }) LOGS )
1257+
=> #rlpEncodeLength( #rlpEncodeBytes( ACCT, 20 )
1258+
+String #rlpEncodeTopics( TOPICS )
1259+
+String #rlpEncodeString( #asString( DATA ) )
1260+
, 192 )
1261+
+String #rlpEncodeLogsAux( LOGS )
1262+
1263+
syntax String ::= #rlpEncodeTopics ( List ) [function]
1264+
| #rlpEncodeTopicsAux( List ) [function]
1265+
// --------------------------------------------------------
1266+
rule #rlpEncodeTopics( .List ) => "\xc0"
1267+
rule #rlpEncodeTopics( TOPICS ) => #rlpEncodeLength( #rlpEncodeTopicsAux( TOPICS ), 192 )
1268+
requires TOPICS =/=K .List
1269+
1270+
rule #rlpEncodeTopicsAux( .List ) => ""
1271+
rule #rlpEncodeTopicsAux( ListItem( X:Int ) TOPICS ) => #rlpEncodeWord( X ) +String #rlpEncodeTopicsAux( TOPICS )
12251272
```
12261273

12271274
State Root
@@ -1267,6 +1314,29 @@ Transactions Root
12671314
syntax KItem ::= "#firefly_getTxRoot"
12681315
// -------------------------------------
12691316
rule <k> #firefly_getTxRoot => #sendResponse("result": { "transactionsRoot" : "0x" +String Keccak256( #rlpEncodeMerkleTree( #transactionsRoot ) ) } ) ... </k>
1317+
```
1318+
1319+
Receipts Root
1320+
-------------
1321+
1322+
```k
1323+
syntax MerkleTree ::= "#receiptsRoot" [function]
1324+
// ------------------------------------------------
1325+
rule #receiptsRoot => MerkleUpdateMap( .MerkleTree, #receiptsMap )
1326+
1327+
syntax Map ::= "#receiptsMap" [function]
1328+
| #receiptsMapAux( Int ) [function]
1329+
// ------------------------------------------------
1330+
rule #receiptsMap => #receiptsMapAux( 0 )
1331+
1332+
rule #receiptsMapAux( _ ) => .Map [owise]
1333+
rule [[ #receiptsMapAux( I ) => #parseByteStackRaw( #rlpEncodeWord( I ) )[0 .. 1] |-> #rlpEncodeReceipt( { TXLIST[ I ] }:>Int ) #receiptsMapAux( I +Int 1 ) ]]
1334+
<txOrder> TXLIST </txOrder>
1335+
requires size(TXLIST) >Int I
1336+
1337+
syntax KItem ::= "#firefly_getReceiptsRoot"
1338+
// -------------------------------------------
1339+
rule <k> #firefly_getReceiptsRoot => #sendResponse("result": { "receiptsRoot" : "0x" +String Keccak256( #rlpEncodeMerkleTree( #receiptsRoot ) ) } ) ... </k>
12701340
12711341
endmodule
12721342
```

0 commit comments

Comments
 (0)