diff --git a/beacon_chain/libnimbus_lc/libnimbus_lc.h b/beacon_chain/libnimbus_lc/libnimbus_lc.h index dab050c64..9014fdf71 100644 --- a/beacon_chain/libnimbus_lc/libnimbus_lc.h +++ b/beacon_chain/libnimbus_lc/libnimbus_lc.h @@ -870,14 +870,14 @@ const ETHRoot *ETHExecutionPayloadHeaderGetReceiptsRoot( const ETHExecutionPayloadHeader *execution); /** - * Execution logs bloom. + * Execution logs Bloom. */ typedef struct { uint8_t bytes[256]; } ETHLogsBloom; /** - * Obtains the logs bloom of a given execution payload header. + * Obtains the logs Bloom of a given execution payload header. * * - The returned value is allocated in the given execution payload header. * It must neither be released nor written to, and the execution payload @@ -885,7 +885,7 @@ typedef struct { * * @param execution Execution payload header. * - * @return Execution logs bloom. + * @return Execution logs Bloom. */ ETH_RESULT_USE_CHECK const ETHLogsBloom *ETHExecutionPayloadHeaderGetLogsBloom( @@ -957,27 +957,15 @@ int ETHExecutionPayloadHeaderGetTimestamp( * It must neither be released nor written to, and the execution payload * header must not be released while the returned value is in use. * - * - Use `ETHExecutionPayloadHeaderGetNumExtraDataBytes` - * to obtain the length of the buffer. - * * @param execution Execution payload header. + * @param[out] numBytes Length of buffer. * * @return Buffer with execution block extra data. */ ETH_RESULT_USE_CHECK const void *ETHExecutionPayloadHeaderGetExtraDataBytes( - const ETHExecutionPayloadHeader *execution); - -/** - * Obtains the extra data buffer's length of a given execution payload header. - * - * @param execution Execution payload header. - * - * @return Length of execution block extra data. - */ -ETH_RESULT_USE_CHECK -int ETHExecutionPayloadHeaderGetNumExtraDataBytes( - const ETHExecutionPayloadHeader *execution); + const ETHExecutionPayloadHeader *execution, + int *numBytes); /** * UInt256 (little-endian) @@ -1500,6 +1488,283 @@ const void *ETHTransactionGetBytes( const ETHTransaction *transaction, int *numBytes); +/** + * Receipt sequence. + */ +typedef struct ETHReceipts ETHReceipts; + +/** + * Verifies that JSON receipts data is valid and that it matches + * the given `receiptsRoot`. + * + * - The JSON-RPC `eth_getTransactionReceipt` may be used to obtain + * receipts data for a given transaction hash. For verification, it is + * necessary to obtain the receipt for _all_ transactions within a block. + * Pass a JSON array containing _all_ receipt's `result` as `receiptsJson`. + * The receipts need to be in the same order as the `transactions`. + * + * - The receipt sequence must be destroyed with `ETHReceiptsDestroy` + * once no longer needed, to release memory. + * + * @param receiptsRoot Execution receipts root. + * @param receiptsJson Buffer with JSON receipts list. NULL-terminated. + * @param transactions Transaction sequence. + * + * @return Pointer to an initialized receipt sequence - If successful. + * @return `NULL` - If the given `receiptsJson` is malformed or incompatible. + * + * @see https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt + */ +ETH_RESULT_USE_CHECK +ETHReceipts *ETHReceiptsCreateFromJson( + const ETHRoot *receiptsRoot, + const char *receiptsJson, + const ETHTransactions *transactions); + +/** + * Destroys a receipt sequence. + * + * - The receipt sequence must no longer be used after destruction. + * + * @param receipts Receipt sequence. + */ +void ETHReceiptsDestroy(ETHReceipts *receipts); + +/** + * Indicates the total number of receipts in a receipt sequence. + * + * - Individual receipts may be investigated using `ETHReceiptsGet`. + * + * @param receipts Receipt sequence. + * + * @return Number of available receipts. + */ +ETH_RESULT_USE_CHECK +int ETHReceiptsGetCount(const ETHReceipts *receipts); + +/** + * Receipt. + */ +typedef struct ETHReceipt ETHReceipt; + +/** + * Obtains an individual receipt by sequential index + * in a receipt sequence. + * + * - The returned value is allocated in the given receipt sequence. + * It must neither be released nor written to, and the receipt + * sequence must not be released while the returned value is in use. + * + * @param receipts Receipt sequence. + * @param receiptIndex Sequential receipt index. + * + * @return Receipt. + */ +ETH_RESULT_USE_CHECK +const ETHReceipt *ETHReceiptsGet( + const ETHReceipts *receipts, + int receiptIndex); + +/** + * Indicates whether or not a receipt has a status code. + * + * @param receipt Receipt. + * + * @return Whether or not the receipt has a status code. + * + * @see https://eips.ethereum.org/EIPS/eip-658 + */ +ETH_RESULT_USE_CHECK +bool ETHReceiptHasStatus(const ETHReceipt *receipt); + +/** + * Obtains the intermediate post-state root of a receipt with no status code. + * + * - If the receipt has a status code, this function returns a zero hash. + * + * - The returned value is allocated in the given receipt. + * It must neither be released nor written to, and the receipt + * must not be released while the returned value is in use. + * + * @param receipt Receipt. + * + * @return Intermediate post-state root. + */ +ETH_RESULT_USE_CHECK +const ETHRoot *ETHReceiptGetRoot(const ETHReceipt *receipt); + +/** + * Obtains the status code of a receipt with a status code. + * + * - If the receipt has no status code, this function returns true. + * + * @param receipt Receipt. + * + * @return Status code. + * + * @see https://eips.ethereum.org/EIPS/eip-658 + */ +ETH_RESULT_USE_CHECK +bool ETHReceiptGetStatus(const ETHReceipt *receipt); + +/** + * Obtains the gas used of a receipt. + * + * - The returned value is allocated in the given receipt. + * It must neither be released nor written to, and the receipt + * must not be released while the returned value is in use. + * + * @param receipt Receipt. + * + * @return Gas used. + */ +ETH_RESULT_USE_CHECK +const uint64_t *ETHReceiptGetGasUsed(const ETHReceipt *receipt); + +/** + * Obtains the logs Bloom of a receipt. + * + * - The returned value is allocated in the given receipt. + * It must neither be released nor written to, and the receipt + * must not be released while the returned value is in use. + * + * @param receipt Receipt. + * + * @return Logs Bloom. + */ +ETH_RESULT_USE_CHECK +const ETHLogsBloom *ETHReceiptGetLogsBloom(const ETHReceipt *receipt); + +/** + * Log sequence. + */ +typedef struct ETHLogs ETHLogs; + +/** + * Obtains the logs of a receipt. + * + * - The returned value is allocated in the given receipt. + * It must neither be released nor written to, and the receipt + * must not be released while the returned value is in use. + * + * @param receipt Receipt. + * + * @return Log sequence. + */ +ETH_RESULT_USE_CHECK +const ETHLogs *ETHReceiptGetLogs(const ETHReceipt *receipt); + +/** + * Indicates the total number of logs in a log sequence. + * + * - Individual logs may be investigated using `ETHLogsGet`. + * + * @param logs Log sequence. + * + * @return Number of available logs. + */ +ETH_RESULT_USE_CHECK +int ETHLogsGetCount(const ETHLogs *logs); + +/** + * Log. + */ +typedef struct ETHLog ETHLog; + +/** + * Obtains an individual log by sequential index in a log sequence. + * + * - The returned value is allocated in the given log sequence. + * It must neither be released nor written to, and the log sequence + * must not be released while the returned value is in use. + * + * @param logs Log sequence. + * @param logIndex Sequential log index. + * + * @return Log. + */ +ETH_RESULT_USE_CHECK +const ETHLog *ETHLogsGet( + const ETHLogs *logs, + int logIndex); + +/** + * Obtains the address of a log. + * + * - The returned value is allocated in the given log. + * It must neither be released nor written to, and the log + * must not be released while the returned value is in use. + * + * @param log Log. + * + * @return Address. + */ +ETH_RESULT_USE_CHECK +const ETHExecutionAddress *ETHLogGetAddress(const ETHLog *log); + +/** + * Indicates the total number of topics in a log. + * + * - Individual topics may be investigated using `ETHLogGetTopic`. + * + * @param log Log. + * + * @return Number of available topics. + */ +ETH_RESULT_USE_CHECK +int ETHLogGetNumTopics(const ETHLog *log); + +/** + * Obtains an individual topic by sequential index in a log. + * + * - The returned value is allocated in the given log. + * It must neither be released nor written to, and the log + * must not be released while the returned value is in use. + * + * @param log Log. + * @param topicIndex Sequential topic index. + * + * @return Topic. + */ +ETH_RESULT_USE_CHECK +const ETHRoot *ETHLogGetTopic( + const ETHLog *log, + int topicIndex); + +/** + * Obtains the data of a log. + * + * - The returned value is allocated in the given log. + * It must neither be released nor written to, and the log + * must not be released while the returned value is in use. + * + * @param log Log. + * @param[out] numBytes Length of buffer. + * + * @return Buffer with data. + */ +ETH_RESULT_USE_CHECK +const void *ETHLogGetDataBytes( + const ETHLog *log, + int *numBytes); + +/** + * Obtains the raw byte representation of a receipt. + * + * - The returned value is allocated in the given receipt. + * It must neither be released nor written to, and the receipt + * must not be released while the returned value is in use. + * + * @param receipt Receipt. + * @param[out] numBytes Length of buffer. + * + * @return Buffer with raw receipt data. + */ +ETH_RESULT_USE_CHECK +const void *ETHReceiptGetBytes( + const ETHReceipt *receipt, + int *numBytes); + #if __has_feature(nullability) #pragma clang assume_nonnull end #endif diff --git a/beacon_chain/libnimbus_lc/libnimbus_lc.nim b/beacon_chain/libnimbus_lc/libnimbus_lc.nim index 36572a9c2..82c16514b 100644 --- a/beacon_chain/libnimbus_lc/libnimbus_lc.nim +++ b/beacon_chain/libnimbus_lc/libnimbus_lc.nim @@ -1038,7 +1038,7 @@ func ETHExecutionPayloadHeaderGetReceiptsRoot( func ETHExecutionPayloadHeaderGetLogsBloom( execution: ptr ExecutionPayloadHeader): ptr BloomLogs {.exported.} = - ## Obtains the logs bloom of a given execution payload header. + ## Obtains the logs Bloom of a given execution payload header. ## ## * The returned value is allocated in the given execution payload header. ## It must neither be released nor written to, and the execution payload @@ -1048,7 +1048,7 @@ func ETHExecutionPayloadHeaderGetLogsBloom( ## * `execution` - Execution payload header. ## ## Returns: - ## * Execution logs bloom. + ## * Execution logs Bloom. addr execution[].logs_bloom func ETHExecutionPayloadHeaderGetPrevRandao( @@ -1111,35 +1111,27 @@ func ETHExecutionPayloadHeaderGetTimestamp( execution[].timestamp.cint func ETHExecutionPayloadHeaderGetExtraDataBytes( - execution: ptr ExecutionPayloadHeader -): ptr UncheckedArray[byte] {.exported.} = + execution: ptr ExecutionPayloadHeader, + numBytes #[out]#: ptr cint): ptr UncheckedArray[byte] {.exported.} = ## Obtains the extra data buffer of a given execution payload header. ## ## * The returned value is allocated in the given execution payload header. ## It must neither be released nor written to, and the execution payload ## header must not be released while the returned value is in use. ## - ## * Use `ETHExecutionPayloadHeaderGetNumExtraDataBytes` - ## to obtain the length of the buffer. - ## ## Parameters: ## * `execution` - Execution payload header. + ## * `numBytes` [out] - Length of buffer. ## ## Returns: ## * Buffer with execution block extra data. + numBytes[] = execution[].extra_data.len.cint + if execution[].extra_data.len == 0: + # https://github.com/nim-lang/Nim/issues/22389 + const defaultExtraData: cstring = "" + return cast[ptr UncheckedArray[byte]](defaultExtraData) cast[ptr UncheckedArray[byte]](addr execution[].extra_data[0]) -func ETHExecutionPayloadHeaderGetNumExtraDataBytes( - execution: ptr ExecutionPayloadHeader): cint {.exported.} = - ## Obtains the extra data buffer's length of a given execution payload header. - ## - ## Parameters: - ## * `execution` - Execution payload header. - ## - ## Returns: - ## * Length of execution block extra data. - execution[].extra_data.len.cint - func ETHExecutionPayloadHeaderGetBaseFeePerGas( execution: ptr ExecutionPayloadHeader): ptr UInt256 {.exported.} = ## Obtains the base fee per gas of a given execution payload header. @@ -1974,3 +1966,428 @@ func ETHTransactionGetBytes( const defaultBytes: cstring = "" return cast[ptr UncheckedArray[byte]](defaultBytes) cast[ptr UncheckedArray[byte]](addr distinctBase(transaction[].bytes)[0]) + +type + ETHLog = object + address: ExecutionAddress + topics: seq[Eth2Digest] + data: seq[byte] + + ReceiptStatusType {.pure.} = enum + Root, + Status # EIP-658 + + ETHReceipt = object + statusType: ReceiptStatusType + root: Eth2Digest + status: bool + gasUsed: uint64 + logsBloom: BloomLogs + logs: seq[ETHLog] + bytes: seq[byte] + +proc ETHReceiptsCreateFromJson( + receiptsRoot: ptr Eth2Digest, + receiptsJson: cstring, + transactions: ptr seq[ETHTransaction]): ptr seq[ETHReceipt] {.exported.} = + ## Verifies that JSON receipts data is valid and that it matches + ## the given `receiptsRoot`. + ## + ## * The JSON-RPC `eth_getTransactionReceipt` may be used to obtain + ## receipts data for a given transaction hash. For verification, it is + ## necessary to obtain the receipt for _all_ transactions within a block. + ## Pass a JSON array containing _all_ receipt's `result` as `receiptsJson`. + ## The receipts need to be in the same order as the `transactions`. + ## + ## * The receipt sequence must be destroyed with `ETHReceiptsDestroy` + ## once no longer needed, to release memory. + ## + ## Parameters: + ## * `receiptsRoot` - Execution receipts root. + ## * `receiptsJson` - Buffer with JSON receipts list. NULL-terminated. + ## * `transactions` - Transaction sequence. + ## + ## Returns: + ## * Pointer to an initialized receipt sequence - If successful. + ## * `NULL` - If the given `receiptsJson` is malformed or incompatible. + ## + ## See: + ## * https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt + let node = + try: + parseJson($receiptsJson) + except Exception: + return nil + var datas: seq[ReceiptObject] + try: + fromJson(node, argName = "", datas) + except KeyError, ValueError: + return nil + if datas.len != ETHTransactionsGetCount(transactions): + return nil + + var + recs = newSeqOfCap[ETHReceipt](datas.len) + cumulativeGasUsed = 0'u64 + logIndex = uint64.high + for i, data in datas: + # Sanity check + if distinctBase(data.transactionIndex) != i.uint64: + return nil + + # Check fork consistency + static: doAssert totalSerializedFields(ReceiptObject) == 15, + "Only update this number once code is adjusted to check new fields!" + static: doAssert totalSerializedFields(LogObject) == 9, + "Only update this number once code is adjusted to check new fields!" + let txType = + case data.`type`.get(0.Quantity): + of 0.Quantity: + TxLegacy + of 1.Quantity: + TxEip2930 + of 2.Quantity: + TxEip1559 + of 3.Quantity: + TxEip4844 + else: + return nil + if data.root.isNone and data.status.isNone or + data.root.isSome and data.status.isSome: + return nil + if data.status.isSome and distinctBase(data.status.get) > 1: + return nil + if distinctBase(data.cumulativeGasUsed) != + cumulativeGasUsed + distinctBase(data.gasUsed): + return nil + cumulativeGasUsed = distinctBase(data.cumulativeGasUsed) + for log in data.logs: + if log.removed: + return nil + if distinctBase(log.logIndex) != logIndex + 1: + return nil + logIndex = distinctBase(log.logIndex) + if log.transactionIndex != data.transactionIndex: + return nil + if log.transactionHash != data.transactionHash: + return nil + if log.blockHash != data.blockHash: + return nil + if log.blockNumber != data.blockNumber: + return nil + if log.data.len mod 32 != 0: + return nil + if log.topics.len > 4: + return nil + + # Construct receipt + static: + doAssert sizeof(int64) == sizeof(data.cumulativeGasUsed) + if distinctBase(data.cumulativeGasUsed) > int64.high.uint64: + return nil + let + rec = ExecutionReceipt( + receiptType: txType, + isHash: data.root.isSome, + status: distinctBase(data.status.get(1.Quantity)) != 0'u64, + hash: + if data.root.isSome: + ExecutionHash256(data: distinctBase(data.root.get)) + else: + default(ExecutionHash256), + cumulativeGasUsed: distinctBase(data.cumulativeGasUsed).GasInt, + bloom: distinctBase(data.logsBloom), + logs: data.logs.mapIt(Log( + address: distinctBase(it.address), + topics: it.topics.mapIt(distinctBase(it)), + data: it.data))) + rlpBytes = + try: + rlp.encode(rec) + except RlpError: + raiseAssert "Unreachable" + + recs.add ETHReceipt( + statusType: + if rec.isHash: + ReceiptStatusType.Root + else: + ReceiptStatusType.Status, + root: rec.hash, + status: rec.status, + gasUsed: distinctBase(data.gasUsed), # Validated during sanity checks. + logsBloom: BloomLogs(data: rec.bloom), + logs: rec.logs.mapIt(ETHLog( + address: ExecutionAddress(data: it.address), + topics: it.topics.mapIt(Eth2Digest(data: it)), + data: it.data)), + bytes: rlpBytes) + + var tr = initHexaryTrie(newMemoryDB()) + for i, rec in recs: + try: + tr.put(rlp.encode(i), rec.bytes) + except RlpError: + raiseAssert "Unreachable" + if tr.rootHash() != receiptsRoot[]: + return nil + + let receipts = seq[ETHReceipt].new() + receipts[] = recs + receipts.toUnmanagedPtr() + +proc ETHReceiptsDestroy( + receipts: ptr seq[ETHReceipt]) {.exported.} = + ## Destroys a receipt sequence. + ## + ## * The receipt sequence must no longer be used after destruction. + ## + ## Parameters: + ## * `receipts` - Receipt sequence. + receipts.destroy() + +func ETHReceiptsGetCount( + receipts: ptr seq[ETHReceipt]): cint {.exported.} = + ## Indicates the total number of receipts in a receipt sequence. + ## + ## * Individual receipts may be investigated using `ETHReceiptsGet`. + ## + ## Parameters: + ## * `receipts` - Receipt sequence. + ## + ## Returns: + ## * Number of available receipts. + receipts[].len.cint + +func ETHReceiptsGet( + receipts: ptr seq[ETHReceipt], + receiptIndex: cint): ptr ETHReceipt {.exported.} = + ## Obtains an individual receipt by sequential index + ## in a receipt sequence. + ## + ## * The returned value is allocated in the given receipt sequence. + ## It must neither be released nor written to, and the receipt + ## sequence must not be released while the returned value is in use. + ## + ## Parameters: + ## * `receipts` - Receipt sequence. + ## * `receiptIndex` - Sequential receipt index. + ## + ## Returns: + ## * Receipt. + addr receipts[][receiptIndex.int] + +func ETHReceiptHasStatus( + receipt: ptr ETHReceipt): bool {.exported.} = + ## Indicates whether or not a receipt has a status code. + ## + ## Parameters: + ## * `receipt` - Receipt. + ## + ## Returns: + ## * Whether or not the receipt has a status code. + ## + ## See: + ## * https://eips.ethereum.org/EIPS/eip-658 + case receipt[].statusType + of ReceiptStatusType.Root: + false + of ReceiptStatusType.Status: + true + +func ETHReceiptGetRoot( + receipt: ptr ETHReceipt): ptr Eth2Digest {.exported.} = + ## Obtains the intermediate post-state root of a receipt with no status code. + ## + ## * If the receipt has a status code, this function returns a zero hash. + ## + ## * The returned value is allocated in the given receipt. + ## It must neither be released nor written to, and the receipt + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `receipt` - Receipt. + ## + ## Returns: + ## * Intermediate post-state root. + addr receipt[].root + +func ETHReceiptGetStatus( + receipt: ptr ETHReceipt): bool {.exported.} = + ## Obtains the status code of a receipt with a status code. + ## + ## * If the receipt has no status code, this function returns true. + ## + ## Parameters: + ## * `receipt` - Receipt. + ## + ## Returns: + ## * Status code. + ## + ## See: + ## * https://eips.ethereum.org/EIPS/eip-658 + receipt[].status + +func ETHReceiptGetGasUsed( + receipt: ptr ETHReceipt): ptr uint64 {.exported.} = + ## Obtains the gas used of a receipt. + ## + ## * The returned value is allocated in the given receipt. + ## It must neither be released nor written to, and the receipt + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `receipt` - Receipt. + ## + ## Returns: + ## * Gas used. + addr receipt[].gasUsed + +func ETHReceiptGetLogsBloom( + receipt: ptr ETHReceipt): ptr BloomLogs {.exported.} = + ## Obtains the logs Bloom of a receipt. + ## + ## * The returned value is allocated in the given receipt. + ## It must neither be released nor written to, and the receipt + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `receipt` - Receipt. + ## + ## Returns: + ## * Logs Bloom. + addr receipt[].logsBloom + +func ETHReceiptGetLogs( + receipt: ptr ETHReceipt): ptr seq[ETHLog] {.exported.} = + ## Obtains the logs of a receipt. + ## + ## * The returned value is allocated in the given receipt. + ## It must neither be released nor written to, and the receipt + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `receipt` - Receipt. + ## + ## Returns: + ## * Log sequence. + addr receipt[].logs + +func ETHLogsGetCount( + logs: ptr seq[ETHLog]): cint {.exported.} = + ## Indicates the total number of logs in a log sequence. + ## + ## * Individual logs may be investigated using `ETHLogsGet`. + ## + ## Parameters: + ## * `logs` - Log sequence. + ## + ## Returns: + ## * Number of available logs. + logs[].len.cint + +func ETHLogsGet( + logs: ptr seq[ETHLog], + logIndex: cint): ptr ETHLog {.exported.} = + ## Obtains an individual log by sequential index in a log sequence. + ## + ## * The returned value is allocated in the given log sequence. + ## It must neither be released nor written to, and the log sequence + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `logs` - Log sequence. + ## * `logIndex` - Sequential log index. + ## + ## Returns: + ## * Log. + addr logs[][logIndex.int] + +func ETHLogGetAddress( + log: ptr ETHLog): ptr ExecutionAddress {.exported.} = + ## Obtains the address of a log. + ## + ## * The returned value is allocated in the given log. + ## It must neither be released nor written to, and the log + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `log` - Log. + ## + ## Returns: + ## * Address. + addr log[].address + +func ETHLogGetNumTopics( + log: ptr ETHLog): cint {.exported.} = + ## Indicates the total number of topics in a log. + ## + ## * Individual topics may be investigated using `ETHLogGetTopic`. + ## + ## Parameters: + ## * `log` - Log. + ## + ## Returns: + ## * Number of available topics. + log[].topics.len.cint + +func ETHLogGetTopic( + log: ptr ETHLog, + topicIndex: cint): ptr Eth2Digest {.exported.} = + ## Obtains an individual topic by sequential index in a log. + ## + ## * The returned value is allocated in the given log. + ## It must neither be released nor written to, and the log + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `log` - Log. + ## * `topicIndex` - Sequential topic index. + ## + ## Returns: + ## * Topic. + addr log[].topics[topicIndex.int] + +func ETHLogGetDataBytes( + log: ptr ETHLog, + numBytes #[out]#: ptr cint): ptr UncheckedArray[byte] {.exported.} = + ## Obtains the data of a log. + ## + ## * The returned value is allocated in the given log. + ## It must neither be released nor written to, and the log + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `log` - Log. + ## * `numBytes` [out] - Length of buffer. + ## + ## Returns: + ## * Buffer with data. + numBytes[] = log[].data.len.cint + if log[].data.len == 0: + # https://github.com/nim-lang/Nim/issues/22389 + const defaultData: cstring = "" + return cast[ptr UncheckedArray[byte]](defaultData) + cast[ptr UncheckedArray[byte]](addr log[].data[0]) + +func ETHReceiptGetBytes( + receipt: ptr ETHReceipt, + numBytes #[out]#: ptr cint): ptr UncheckedArray[byte] {.exported.} = + ## Obtains the raw byte representation of a receipt. + ## + ## * The returned value is allocated in the given receipt. + ## It must neither be released nor written to, and the receipt + ## must not be released while the returned value is in use. + ## + ## Parameters: + ## * `receipt` - Receipt. + ## * `numBytes` [out] - Length of buffer. + ## + ## Returns: + ## * Buffer with raw receipt data. + numBytes[] = distinctBase(receipt[].bytes).len.cint + if distinctBase(receipt[].bytes).len == 0: + # https://github.com/nim-lang/Nim/issues/22389 + const defaultBytes: cstring = "" + return cast[ptr UncheckedArray[byte]](defaultBytes) + cast[ptr UncheckedArray[byte]](addr distinctBase(receipt[].bytes)[0]) diff --git a/beacon_chain/libnimbus_lc/test_files/receipts.json b/beacon_chain/libnimbus_lc/test_files/receipts.json new file mode 100644 index 000000000..1f1d2f59f --- /dev/null +++ b/beacon_chain/libnimbus_lc/test_files/receipts.json @@ -0,0 +1,360 @@ +[ + { + "blockHash": "0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd", + "blockNumber": "0xb443", + "contractAddress": null, + "cumulativeGasUsed": "0x5208", + "effectiveGasPrice": "0x2d79883d2000", + "from": "0xa1e4380a3b1f749673e270229993ee55f35663b4", + "gasUsed": "0x5208", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "root": "0x96a8e009d2b88b1483e6941e6812e32263b05683fac202abc622a3e31aed1957", + "to": "0x5df9b87991262f6ba471f09758cde1c0fc1de734", + "transactionHash": "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060", + "transactionIndex": "0x0", + "type": "0x0" + }, + { + "blockHash": "0x8e38b4dbf6b11fcc3b9dee84fb7986e29ca0a02cecd8977c161ff7333329681e", + "blockNumber": "0xf4240", + "contractAddress": null, + "cumulativeGasUsed": "0xa410", + "effectiveGasPrice": "0xdf8475800", + "from": "0x32be343b94f860124dc4fee278fdcbd38c102d88", + "gasUsed": "0x5208", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "status": "0x1", + "to": "0xdf190dc7190dfba737d7777a163445b7fff16133", + "transactionHash": "0xe9e91f1ee4b56c0df2e9f06c2b8c27c6076195a88a7b8537ba8313d80e6f124e", + "transactionIndex": "0x1", + "type": "0x0" + }, + { + "blockHash": "0xe380e7cf640a646ef901b6a5db4d3076fdcad5ac2a922ca098f639d2b762df4f", + "blockNumber": "0x10fa02b", + "contractAddress": null, + "cumulativeGasUsed": "0x1a93e", + "effectiveGasPrice": "0x9839089a0", + "from": "0xbe49bd130e126a917ddb5fabf7cdeb6dd9887f40", + "gasUsed": "0x1052e", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "status": "0x1", + "to": "0x84654be796dad370032391d5479f8f1fd9ddd14e", + "transactionHash": "0xdc81918bf78322ce017c592e81c855f40bb96bd82da9779167de1de109962be6", + "transactionIndex": "0x2", + "type": "0x0" + }, + { + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "blockNumber": "0xc35000", + "contractAddress": null, + "cumulativeGasUsed": "0x64f13", + "effectiveGasPrice": "0x0", + "from": "0x1fd34033240c95aabf73e186a94b9576c6dab81b", + "gasUsed": "0x4a5d5", + "logs": [ + { + "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640", + "0x0000000000000000000000003765521db364ee269e9540970fd21e5a3e825699" + ], + "data": "0x00000000000000000000000000000000000000000000000034b819a76c9101dd", + "blockNumber": "0xc35000", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "logIndex": "0x0", + "removed": false + }, + { + "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000006a9850e46518231b23e50467c975fa94026be5d5", + "0x00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640" + ], + "data": "0x00000000000000000000000000000000000000000000000000000001dac7be33", + "blockNumber": "0xc35000", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "logIndex": "0x1", + "removed": false + }, + { + "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000003765521db364ee269e9540970fd21e5a3e825699", + "0x000000000000000000000000f1f85b2c54a2bd284b1cf4141d64fd171bd85539" + ], + "data": "0x00000000000000000000000000000000000000000000000034a2e5498f6f66f8", + "blockNumber": "0xc35000", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "logIndex": "0x2", + "removed": false + }, + { + "address": "0x57ab1ec28d129707052df4df418d58a2d46d5f51", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000f1f85b2c54a2bd284b1cf4141d64fd171bd85539", + "0x0000000000000000000000006a9850e46518231b23e50467c975fa94026be5d5" + ], + "data": "0x0000000000000000000000000000000000000000000001ade409ce94c21807e0", + "blockNumber": "0xc35000", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "logIndex": "0x3", + "removed": false + }, + { + "address": "0xf1f85b2c54a2bd284b1cf4141d64fd171bd85539", + "topics": [ + "0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1" + ], + "data": "0x0000000000000000000000000000000000000000000444ae3b74db3b9d4e6c6800000000000000000000000000000000000000000000008597e1b00a2ca3cb8b", + "blockNumber": "0xc35000", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "logIndex": "0x4", + "removed": false + }, + { + "address": "0xf1f85b2c54a2bd284b1cf4141d64fd171bd85539", + "topics": [ + "0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822", + "0x0000000000000000000000003765521db364ee269e9540970fd21e5a3e825699", + "0x0000000000000000000000006a9850e46518231b23e50467c975fa94026be5d5" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034a2e5498f6f66f80000000000000000000000000000000000000000000001ade409ce94c21807e00000000000000000000000000000000000000000000000000000000000000000", + "blockNumber": "0xc35000", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "logIndex": "0x5", + "removed": false + }, + { + "address": "0x6a9850e46518231b23e50467c975fa94026be5d5", + "topics": [ + "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67", + "0x0000000000000000000000003765521db364ee269e9540970fd21e5a3e825699", + "0x00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640" + ], + "data": "0x0000000000000000000000000000000000000000000001ade409ce94c21807e0fffffffffffffffffffffffffffffffffffffffffffffffffffffffe253841cd0000000000000000000000000000000000000000000010d1979907b2b7b44fb8000000000000000000000000000000000000000000000020160626e11f50affdfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbc8cd", + "blockNumber": "0xc35000", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "logIndex": "0x6", + "removed": false + }, + { + "address": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640", + "topics": [ + "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67", + "0x0000000000000000000000003765521db364ee269e9540970fd21e5a3e825699", + "0x0000000000000000000000003765521db364ee269e9540970fd21e5a3e825699" + ], + "data": "0x00000000000000000000000000000000000000000000000000000001dac7be33ffffffffffffffffffffffffffffffffffffffffffffffffcb47e658936efe23000000000000000000000000000000000000555373cbb17fb17a13909e0f3a3b00000000000000000000000000000000000000000000000066d5e9eea910e5ef0000000000000000000000000000000000000000000000000000000000030ca3", + "blockNumber": "0xc35000", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "blockHash": "0x802f1f5a7575098ce5e716cfc6817e24d6944fde8e32eb95dbc178931b11baea", + "logIndex": "0x7", + "removed": false + } + ], + "logsBloom": "0x0020000001000000000020008000000000000000000000000000000004000000000000000000000000000800000800000a0000000800200000000000400000000000080000100008080000080010002000000000000000000000010000000000000000000000000000000000000000000000000000000000000000100008000000000000000000000000000000000000000000000100000800000040000000000000000000002010000000000000000000000000000000000020000000080000000000020000000000000000000000000008000000000010000000000000000000002800000004000000100000000000000000000420008000000a0000000000", + "status": "0x1", + "to": "0x3765521db364ee269e9540970fd21e5a3e825699", + "transactionHash": "0x8135b5403ea5528341d661cdadd8eb67983909fc1644b0a133de708b13e10937", + "transactionIndex": "0x3", + "type": "0x1" + }, + { + "blockHash": "0xe380e7cf640a646ef901b6a5db4d3076fdcad5ac2a922ca098f639d2b762df4f", + "blockNumber": "0x10fa02b", + "contractAddress": null, + "cumulativeGasUsed": "0x7ff02", + "effectiveGasPrice": "0x64a2d5a95", + "from": "0xae2fc483527b8ef99eb5d9b44875f005ba1fae13", + "gasUsed": "0x1afef", + "logs": [ + { + "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000006b75d8af000000e20b7a7ddf000ba900b4009a80", + "0x000000000000000000000000397217ae1de4a6e543858b0191c9213aadbcc4ed" + ], + "data": "0x00000000000000000000000000000000000000000000000003e168d700000000", + "blockNumber": "0x10fa02b", + "transactionHash": "0xba363483b992ef59342094ab98b8523ed6c055b5788e6726140d2badf27bf6d6", + "transactionIndex": "0x4", + "blockHash": "0xe380e7cf640a646ef901b6a5db4d3076fdcad5ac2a922ca098f639d2b762df4f", + "logIndex": "0x8", + "removed": false + }, + { + "address": "0x4ecfc56672c7630b84dac9c1f7407579715de155", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000397217ae1de4a6e543858b0191c9213aadbcc4ed", + "0x0000000000000000000000004ecfc56672c7630b84dac9c1f7407579715de155" + ], + "data": "0x0000000000000000000000000000000000000000000001df1858999999999999", + "blockNumber": "0x10fa02b", + "transactionHash": "0xba363483b992ef59342094ab98b8523ed6c055b5788e6726140d2badf27bf6d6", + "transactionIndex": "0x4", + "blockHash": "0xe380e7cf640a646ef901b6a5db4d3076fdcad5ac2a922ca098f639d2b762df4f", + "logIndex": "0x9", + "removed": false + }, + { + "address": "0x4ecfc56672c7630b84dac9c1f7407579715de155", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000397217ae1de4a6e543858b0191c9213aadbcc4ed", + "0x0000000000000000000000006b75d8af000000e20b7a7ddf000ba900b4009a80" + ], + "data": "0x00000000000000000000000000000000000000000000238ece93666666666667", + "blockNumber": "0x10fa02b", + "transactionHash": "0xba363483b992ef59342094ab98b8523ed6c055b5788e6726140d2badf27bf6d6", + "transactionIndex": "0x4", + "blockHash": "0xe380e7cf640a646ef901b6a5db4d3076fdcad5ac2a922ca098f639d2b762df4f", + "logIndex": "0xa", + "removed": false + }, + { + "address": "0x397217ae1de4a6e543858b0191c9213aadbcc4ed", + "topics": [ + "0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1" + ], + "data": "0x0000000000000000000000000000000000000000000ad652dd7967ecf01d441000000000000000000000000000000000000000000000000122a5b6292417bf7a", + "blockNumber": "0x10fa02b", + "transactionHash": "0xba363483b992ef59342094ab98b8523ed6c055b5788e6726140d2badf27bf6d6", + "transactionIndex": "0x4", + "blockHash": "0xe380e7cf640a646ef901b6a5db4d3076fdcad5ac2a922ca098f639d2b762df4f", + "logIndex": "0xb", + "removed": false + }, + { + "address": "0x397217ae1de4a6e543858b0191c9213aadbcc4ed", + "topics": [ + "0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822", + "0x0000000000000000000000006b75d8af000000e20b7a7ddf000ba900b4009a80", + "0x0000000000000000000000006b75d8af000000e20b7a7ddf000ba900b4009a80" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e168d70000000000000000000000000000000000000000000000000000256de6ec0000000000000000000000000000000000000000000000000000000000000000000000000000", + "blockNumber": "0x10fa02b", + "transactionHash": "0xba363483b992ef59342094ab98b8523ed6c055b5788e6726140d2badf27bf6d6", + "transactionIndex": "0x4", + "blockHash": "0xe380e7cf640a646ef901b6a5db4d3076fdcad5ac2a922ca098f639d2b762df4f", + "logIndex": "0xc", + "removed": false + } + ], + "logsBloom": "0x00200000000000000000000080000000000000000000004000000000400000000000008000000020001000000000040002000000084000000000000000000000000000000000000000000008000000200000000040000000000000000000000000000200000000000000000000000000000000000000000080000010000000000000800000000000000000000000000000000000000000080000004000000000000000000000000000000000000000000000000000100000000000000000400000000002000000000000000000000000000004000000001000001000000000000000200000000000000000000000000000000000000000000000000000000000", + "status": "0x1", + "to": "0x6b75d8af000000e20b7a7ddf000ba900b4009a80", + "transactionHash": "0xba363483b992ef59342094ab98b8523ed6c055b5788e6726140d2badf27bf6d6", + "transactionIndex": "0x4", + "type": "0x2" + }, + { + "type": "0x2", + "transactionHash": "0xa3b805acacb25da412a44bd9612a73464292fc684a400ab54f0a9626f7d9c3f2", + "transactionIndex": "0x5", + "blockHash": "0x421e594f79995d1aba3c62c80c678a1f6d4d70a6c49c9d721a5ad1ef802f79b3", + "blockNumber": "0x10fd2c3", + "from": "0x979db18107552faa36a52480a1dbb65ed3f51d70", + "to": null, + "cumulativeGasUsed": "0x16fa7c", + "gasUsed": "0xefb7a", + "contractAddress": "0x451445a9adb7e4c8ab4a266755626c136e093a4e", + "logs": [ + { + "removed": false, + "logIndex": "0xd", + "transactionIndex": "0x5", + "transactionHash": "0xa3b805acacb25da412a44bd9612a73464292fc684a400ab54f0a9626f7d9c3f2", + "blockHash": "0x421e594f79995d1aba3c62c80c678a1f6d4d70a6c49c9d721a5ad1ef802f79b3", + "blockNumber": "0x10fd2c3", + "address": "0x451445a9adb7e4c8ab4a266755626c136e093a4e", + "data": "0x", + "topics": [ + "0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b", + "0x0000000000000000000000007e22fcb742572515d1c3fef972ec066c995820ef" + ] + }, + { + "removed": false, + "logIndex": "0xe", + "transactionIndex": "0x5", + "transactionHash": "0xa3b805acacb25da412a44bd9612a73464292fc684a400ab54f0a9626f7d9c3f2", + "blockHash": "0x421e594f79995d1aba3c62c80c678a1f6d4d70a6c49c9d721a5ad1ef802f79b3", + "blockNumber": "0x10fd2c3", + "address": "0x451445a9adb7e4c8ab4a266755626c136e093a4e", + "data": "0x", + "topics": [ + "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x000000000000000000000000979db18107552faa36a52480a1dbb65ed3f51d70" + ] + }, + { + "removed": false, + "logIndex": "0xf", + "transactionIndex": "0x5", + "transactionHash": "0xa3b805acacb25da412a44bd9612a73464292fc684a400ab54f0a9626f7d9c3f2", + "blockHash": "0x421e594f79995d1aba3c62c80c678a1f6d4d70a6c49c9d721a5ad1ef802f79b3", + "blockNumber": "0x10fd2c3", + "address": "0x451445a9adb7e4c8ab4a266755626c136e093a4e", + "data": "0x0000000000000000000000000000000000000000000000000000000064c7eb930000000000000000000000000000000000000000000000000000000064d2bde30000000000000000000000000000000000000000000000000000000064c7e277", + "topics": [ + "0x23f6ad8232d75562dd1c6b37dfc895af6bfc1ecd0fb3b88722c6a5e6b4dc9a20" + ] + }, + { + "removed": false, + "logIndex": "0x10", + "transactionIndex": "0x5", + "transactionHash": "0xa3b805acacb25da412a44bd9612a73464292fc684a400ab54f0a9626f7d9c3f2", + "blockHash": "0x421e594f79995d1aba3c62c80c678a1f6d4d70a6c49c9d721a5ad1ef802f79b3", + "blockNumber": "0x10fd2c3", + "address": "0x451445a9adb7e4c8ab4a266755626c136e093a4e", + "data": "0x0000000000000000000000000000000000000000000000000000000000000001", + "topics": [ + "0x7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498" + ] + }, + { + "removed": false, + "logIndex": "0x11", + "transactionIndex": "0x5", + "transactionHash": "0xa3b805acacb25da412a44bd9612a73464292fc684a400ab54f0a9626f7d9c3f2", + "blockHash": "0x421e594f79995d1aba3c62c80c678a1f6d4d70a6c49c9d721a5ad1ef802f79b3", + "blockNumber": "0x10fd2c3", + "address": "0x451445a9adb7e4c8ab4a266755626c136e093a4e", + "data": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d89f6892a2b58d50e0e8f51a961b12a25ce3f757", + "topics": [ + "0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f" + ] + } + ], + "logsBloom": "0x0000000000000000000000000000000040000000000000000080000001000000000000000000000000000000000000000000000200004000000000000201000000000000000000000000000000000200000100000000000000000000000000000000000002000000000000000000080004000080000000000000000000000040000000000000000000000004000000000000000000008000000000040080000000000000000000000000000000040000000000000000000000000000000000000000002020000000000000000004000a000000000400000000000000000020000000000000000000000000000000000000000000000000000000000000020000", + "status": "0x1", + "effectiveGasPrice": "0xa00a0c2f8" + } +] diff --git a/beacon_chain/libnimbus_lc/test_files/transactions.json b/beacon_chain/libnimbus_lc/test_files/transactions.json index 5c01427c5..a3e90376b 100644 --- a/beacon_chain/libnimbus_lc/test_files/transactions.json +++ b/beacon_chain/libnimbus_lc/test_files/transactions.json @@ -1,4 +1,21 @@ [ + { + "blockHash": "0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd", + "blockNumber": "0xb443", + "from": "0xa1e4380a3b1f749673e270229993ee55f35663b4", + "gas": "0x5208", + "gasPrice": "0x2d79883d2000", + "hash": "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060", + "input": "0x", + "nonce": "0x0", + "r": "0x88ff6cf0fefd94db46111149ae4bfc179e9b94721fffd821d38d16464b3f71d0", + "s": "0x45e0aff800961cfce805daef7016b9b675c137a6a41a548f7b60a3484c06a33a", + "to": "0x5df9b87991262f6ba471f09758cde1c0fc1de734", + "transactionIndex": "0x0", + "type": "0x0", + "v": "0x1c", + "value": "0x7a69" + }, { "blockHash": "0x8e38b4dbf6b11fcc3b9dee84fb7986e29ca0a02cecd8977c161ff7333329681e", "blockNumber": "0xf4240", @@ -9,7 +26,7 @@ "input": "0x", "nonce": "0x43eb", "to": "0xdf190dc7190dfba737d7777a163445b7fff16133", - "transactionIndex": "0x0", + "transactionIndex": "0x1", "value": "0x6113a84987be800", "type": "0x0", "v": "0x1c", @@ -26,7 +43,7 @@ "input": "0xd508e62389272d541e4168e5303b5838dcef5f9ac769a057f8dc6aabce7ec1e69b7ce5e6", "nonce": "0x2ecd", "to": "0x84654be796dad370032391d5479f8f1fd9ddd14e", - "transactionIndex": "0x1", + "transactionIndex": "0x2", "value": "0x0", "v": "0x25", "r": "0x78e88f9c69d217c76d92d5472f5812501021342f0054178c0579ee532dc2a218", @@ -44,7 +61,7 @@ "input": "0x5f53273d00000000000000000000000000000000000000000000000000112cfa39a81d7c00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000004e4128acb080000000000000000000000003765521db364ee269e9540970fd21e5a3e825699000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000001dac7be33000000000000000000000000000000000000000000000000000000010005bd8200000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000004200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a9850e46518231b23e50467c975fa94026be5d5000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000324128acb0800000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000001ade409ce94c21807e0000000000000000000000000000000000000000000000000000000010005bd8200000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000f1f85b2c54a2bd284b1cf4141d64fd171bd855390000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000f1f85b2c54a2bd284b1cf4141d64fd171bd8553900000000000000000000000000000000000000000000000034a2e5498f6f66f80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4022c0d9f0000000000000000000000000000000000000000000001ade409ce94c21807e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006a9850e46518231b23e50467c975fa94026be5d500000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "nonce": "0x1536", "to": "0x3765521db364ee269e9540970fd21e5a3e825699", - "transactionIndex": "0x2", + "transactionIndex": "0x3", "value": "0x0", "type": "0x1", "accessList": [ @@ -179,7 +196,7 @@ "input": "0x2b2f1a397217ae1de4a6e543858b0191c9213aadbcc4ed256de6ec", "nonce": "0xf9b35", "to": "0x6b75d8af000000e20b7a7ddf000ba900b4009a80", - "transactionIndex": "0x3", + "transactionIndex": "0x4", "value": "0x3e168d7", "v": "0x1", "r": "0xbcd30031cd0ee1132ec0fd4debd5157269adf0e478e4c4733d846b09f8891dcd", @@ -237,7 +254,7 @@ "input": "0x608060405260405162000eda38038062000eda83398101604081905262000026916200049d565b828162000036828260006200004d565b50620000449050826200008a565b505050620005d0565b6200005883620000e5565b600082511180620000665750805b1562000085576200008383836200012760201b620001791760201c565b505b505050565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f620000b562000156565b604080516001600160a01b03928316815291841660208301520160405180910390a1620000e2816200018f565b50565b620000f08162000244565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b60606200014f838360405180606001604052806027815260200162000eb360279139620002f8565b9392505050565b60006200018060008051602062000e9383398151915260001b6200037760201b620001a51760201c565b546001600160a01b0316919050565b6001600160a01b038116620001fa5760405162461bcd60e51b815260206004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b806200022360008051602062000e9383398151915260001b6200037760201b620001a51760201c565b80546001600160a01b0319166001600160a01b039290921691909117905550565b6200025a816200037a60201b620001a81760201c565b620002be5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401620001f1565b80620002237f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc60001b6200037760201b620001a51760201c565b6060600080856001600160a01b0316856040516200031791906200057d565b600060405180830381855af49150503d806000811462000354576040519150601f19603f3d011682016040523d82523d6000602084013e62000359565b606091505b5090925090506200036d8683838762000389565b9695505050505050565b90565b6001600160a01b03163b151590565b60608315620003fa578251620003f2576001600160a01b0385163b620003f25760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401620001f1565b508162000406565b6200040683836200040e565b949350505050565b8151156200041f5781518083602001fd5b8060405162461bcd60e51b8152600401620001f191906200059b565b80516001600160a01b03811681146200045357600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b838110156200048b57818101518382015260200162000471565b83811115620000835750506000910152565b600080600060608486031215620004b357600080fd5b620004be846200043b565b9250620004ce602085016200043b565b60408501519092506001600160401b0380821115620004ec57600080fd5b818601915086601f8301126200050157600080fd5b81518181111562000516576200051662000458565b604051601f8201601f19908116603f0116810190838211818310171562000541576200054162000458565b816040528281528960208487010111156200055b57600080fd5b6200056e8360208301602088016200046e565b80955050505050509250925092565b60008251620005918184602087016200046e565b9190910192915050565b6020815260008251806020840152620005bc8160408501602087016200046e565b601f01601f19169190910160400192915050565b6108b380620005e06000396000f3fe60806040523661001357610011610017565b005b6100115b61001f6101b7565b6001600160a01b0316336001600160a01b0316141561016f5760606001600160e01b031960003516631b2ce7f360e11b8114156100655761005e6101ea565b9150610167565b6001600160e01b0319811663278f794360e11b14156100865761005e610241565b6001600160e01b031981166308f2839760e41b14156100a75761005e610287565b6001600160e01b031981166303e1469160e61b14156100c85761005e6102b8565b6001600160e01b03198116635c60da1b60e01b14156100e95761005e6102f8565b60405162461bcd60e51b815260206004820152604260248201527f5472616e73706172656e745570677261646561626c6550726f78793a2061646d60448201527f696e2063616e6e6f742066616c6c6261636b20746f2070726f78792074617267606482015261195d60f21b608482015260a4015b60405180910390fd5b815160208301f35b61017761030c565b565b606061019e83836040518060600160405280602781526020016108576027913961031c565b9392505050565b90565b6001600160a01b03163b151590565b60007fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035b546001600160a01b0316919050565b60606101f4610394565b600061020336600481846106a2565b81019061021091906106e8565b905061022d8160405180602001604052806000815250600061039f565b505060408051602081019091526000815290565b606060008061025336600481846106a2565b8101906102609190610719565b915091506102708282600161039f565b604051806020016040528060008152509250505090565b6060610291610394565b60006102a036600481846106a2565b8101906102ad91906106e8565b905061022d816103cb565b60606102c2610394565b60006102cc6101b7565b604080516001600160a01b03831660208201529192500160405160208183030381529060405291505090565b6060610302610394565b60006102cc610422565b610177610317610422565b610431565b6060600080856001600160a01b0316856040516103399190610807565b600060405180830381855af49150503d8060008114610374576040519150601f19603f3d011682016040523d82523d6000602084013e610379565b606091505b509150915061038a86838387610455565b9695505050505050565b341561017757600080fd5b6103a8836104d3565b6000825111806103b55750805b156103c6576103c48383610179565b505b505050565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f6103f46101b7565b604080516001600160a01b03928316815291841660208301520160405180910390a161041f81610513565b50565b600061042c6105bc565b905090565b3660008037600080366000845af43d6000803e808015610450573d6000f35b3d6000fd5b606083156104c15782516104ba576001600160a01b0385163b6104ba5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161015e565b50816104cb565b6104cb83836105e4565b949350505050565b6104dc8161060e565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6001600160a01b0381166105785760405162461bcd60e51b815260206004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201526564647265737360d01b606482015260840161015e565b807fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035b80546001600160a01b0319166001600160a01b039290921691909117905550565b60007f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc6101db565b8151156105f45781518083602001fd5b8060405162461bcd60e51b815260040161015e9190610823565b6001600160a01b0381163b61067b5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b606482015260840161015e565b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc61059b565b600080858511156106b257600080fd5b838611156106bf57600080fd5b5050820193919092039150565b80356001600160a01b03811681146106e357600080fd5b919050565b6000602082840312156106fa57600080fd5b61019e826106cc565b634e487b7160e01b600052604160045260246000fd5b6000806040838503121561072c57600080fd5b610735836106cc565b9150602083013567ffffffffffffffff8082111561075257600080fd5b818501915085601f83011261076657600080fd5b81358181111561077857610778610703565b604051601f8201601f19908116603f011681019083821181831017156107a0576107a0610703565b816040528281528860208487010111156107b957600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b60005b838110156107f65781810151838201526020016107de565b838111156103c45750506000910152565b600082516108198184602087016107db565b9190910192915050565b60208152600082518060208401526108428160408501602087016107db565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a264697066735822122012bb4f564f73959a03513dc74fc3c6e40e8386e6f02c16b78d6db00ce0aa16af64736f6c63430008090033b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c65640000000000000000000000007e22fcb742572515d1c3fef972ec066c995820ef000000000000000000000000d89f6892a2b58d50e0e8f51a961b12a25ce3f7570000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000020457405d050000000000000000000000005f4ec3df9cbd43714fe2740f5e3616155c5b8419000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000000000064c7eb930000000000000000000000000000000000000000000000000000000064d2bde300000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000004580900be782a567ad407cc8fcde24dbda2a1aae000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000165a0bc00000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000009795118749000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000023a8f4b6a00000000000000000000000000000000000000000000000000000000", "nonce": "0x3", "to": null, - "transactionIndex": "0x4", + "transactionIndex": "0x5", "value": "0x0", "type": "0x2", "accessList": [], diff --git a/beacon_chain/libnimbus_lc/test_libnimbus_lc.c b/beacon_chain/libnimbus_lc/test_libnimbus_lc.c index ac46b38bd..2553fdd03 100644 --- a/beacon_chain/libnimbus_lc/test_libnimbus_lc.c +++ b/beacon_chain/libnimbus_lc/test_libnimbus_lc.c @@ -238,8 +238,9 @@ static void visualizeHeader(const ETHLightClientHeader *header, const ETHConsens int executionTimestamp = ETHExecutionPayloadHeaderGetTimestamp(execution); printf(" - timestamp: %d\n", executionTimestamp); - const void *executionExtraDataBytes = ETHExecutionPayloadHeaderGetExtraDataBytes(execution); - int numExecutionExtraDataBytes = ETHExecutionPayloadHeaderGetNumExtraDataBytes(execution); + int numExecutionExtraDataBytes; + const void *executionExtraDataBytes = + ETHExecutionPayloadHeaderGetExtraDataBytes(execution, &numExecutionExtraDataBytes); printf(" - extra_data: "); printHexString(executionExtraDataBytes, numExecutionExtraDataBytes); printf("\n"); @@ -391,10 +392,10 @@ int main(void) ETHExecutionBlockHeaderDestroy(executionBlockHeader); ETHRoot sampleTransactionsRoot = {{ - 0x4e, 0x90, 0xdc, 0x06, 0xca, 0xd6, 0xa7, 0xc0, - 0x57, 0xd2, 0xd7, 0x7f, 0x8f, 0x77, 0xd1, 0x45, - 0xb4, 0x6f, 0xf3, 0xad, 0x9c, 0xa7, 0xe1, 0xef, - 0x57, 0x11, 0x5f, 0xa8, 0xbf, 0xad, 0xfe, 0xe1, + 0x73, 0x36, 0x36, 0xe8, 0x0e, 0x47, 0x60, 0x09, + 0xd1, 0xc8, 0x9f, 0x81, 0xaa, 0x64, 0xe1, 0xfd, + 0xf7, 0xff, 0x36, 0xd6, 0x04, 0x6e, 0x95, 0x6c, + 0x39, 0xed, 0xcd, 0x6c, 0x95, 0x2d, 0xce, 0xc2, }}; void *sampleTransactionsJson = readEntireFile( __DIR__ "/test_files/transactions.json", /* numBytes: */ NULL); @@ -403,10 +404,26 @@ int main(void) check(transactions); free(sampleTransactionsJson); + ETHRoot sampleReceiptsRoot = {{ + 0x51, 0x4d, 0xdf, 0xd7, 0xf8, 0x33, 0xfb, 0x2a, + 0x4f, 0x60, 0xed, 0x49, 0xdf, 0xc7, 0x9c, 0x07, + 0xb6, 0x9c, 0x37, 0xef, 0xd1, 0xa5, 0x97, 0xca, + 0x42, 0x76, 0x23, 0xff, 0xa1, 0x79, 0x49, 0xae, + }}; + void *sampleReceiptsJson = readEntireFile( + __DIR__ "/test_files/receipts.json", /* numBytes: */ NULL); + ETHReceipts *receipts = + ETHReceiptsCreateFromJson(&sampleReceiptsRoot, sampleReceiptsJson, transactions); + check(receipts); + free(sampleReceiptsJson); + int numTransactions = ETHTransactionsGetCount(transactions); + int numReceipts = ETHReceiptsGetCount(receipts); + check(numTransactions == numReceipts); printf("\nSample transactions:\n"); for (int transactionIndex = 0; transactionIndex < numTransactions; transactionIndex++) { const ETHTransaction *transaction = ETHTransactionsGet(transactions, transactionIndex); + const ETHReceipt *receipt = ETHReceiptsGet(receipts, transactionIndex); const ETHRoot *transactionHash = ETHTransactionGetHash(transaction); printf("- "); @@ -506,8 +523,63 @@ int main(void) printf(" - bytes: "); printHexString(transactionBytes, numTransactionBytes); printf("\n"); + + printf(" - receipt:\n"); + + bool receiptHasStatus = ETHReceiptHasStatus(receipt); + if (!receiptHasStatus) { + const ETHRoot *receiptRoot = ETHReceiptGetRoot(receipt); + printf(" - root: "); + printHexString(receiptRoot, sizeof *receiptRoot); + printf("\n"); + } else { + bool receiptStatus = ETHReceiptGetStatus(receipt); + printf(" - status: %d\n", receiptStatus); + } + + const uint64_t *receiptGasUsed = ETHReceiptGetGasUsed(receipt); + printf(" - gas_used: %" PRIu64 "\n", *receiptGasUsed); + + const ETHLogsBloom *receiptLogsBloom = ETHReceiptGetLogsBloom(receipt); + printf(" - logs_bloom: "); + printHexString(receiptLogsBloom, sizeof *receiptLogsBloom); + printf("\n"); + + const ETHLogs *receiptLogs = ETHReceiptGetLogs(receipt); + printf(" - logs:\n"); + int numLogs = ETHLogsGetCount(receiptLogs); + for (int logIndex = 0; logIndex < numLogs; logIndex++) { + const ETHLog *log = ETHLogsGet(receiptLogs, logIndex); + + const ETHExecutionAddress *logAddress = ETHLogGetAddress(log); + printf(" - address: "); + printHexString(logAddress, sizeof *logAddress); + printf("\n"); + + printf(" - topics:\n"); + int numTopics = ETHLogGetNumTopics(log); + for (int topicIndex = 0; topicIndex < numTopics; topicIndex++) { + const ETHRoot *topic = ETHLogGetTopic(log, topicIndex); + printf(" - "); + printHexString(topic, sizeof *topic); + printf("\n"); + } + + int numLogDataBytes; + const void *logDataBytes = ETHLogGetDataBytes(log, &numLogDataBytes); + printf(" - data: "); + printHexString(logDataBytes, numLogDataBytes); + printf("\n"); + } + + int numReceiptBytes; + const void *receiptBytes = ETHReceiptGetBytes(receipt, &numReceiptBytes); + printf(" - bytes: "); + printHexString(receiptBytes, numReceiptBytes); + printf("\n"); } + ETHReceiptsDestroy(receipts); ETHTransactionsDestroy(transactions); return 0; diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 84c9a05ad..068737b88 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -33,6 +33,7 @@ func toEther*(gwei: Gwei): Ether = type ExecutionHash256* = eth_types.Hash256 ExecutionTransaction* = eth_types.Transaction + ExecutionReceipt* = eth_types.Receipt ExecutionWithdrawal = eth_types.Withdrawal ExecutionBlockHeader* = eth_types.BlockHeader