Commit 1bc67228 authored by George Hotz's avatar George Hotz

now getting nonce too high :)

parent aa48e6ae
import { ethers } from 'ethers'
import assert from 'assert'
import fs from 'fs'
import { exit } from 'process'
const keccak256 = ethers.utils.keccak256
const rlp = require('rlp')
......@@ -15,23 +16,51 @@ type extblock struct {
Uncles []*Header
}
*/
function getTransactionRlp(tx : any) {
let dat = [
tx.nonce,
tx.gasPrice,
tx.gas,
tx.to,
tx.value,
tx.input,
tx.v,
tx.r,
tx.s,
];
dat = dat.map((x) => (x == "0x0") ? "0x" : x)
function getTransactionRlp(tx : any): Buffer {
let dat: any
if (tx.type == "0x2") {
let accesslist = tx.accessList.map((x : any) => [x.address, x.storageKeys])
// london
dat = [
tx.chainId,
tx.nonce,
tx.maxPriorityFeePerGas,
tx.maxFeePerGas,
tx.gas,
tx.to,
tx.value,
tx.input,
accesslist,
tx.v,
tx.r,
tx.s,
]
dat = dat.map((x : any) => (x == "0x0") ? "0x" : x)
dat = Buffer.concat([Buffer.from([parseInt(tx.type)]), rlp.encode(dat)])
assert(keccak256(dat) == tx.hash)
} else {
// pre london
dat = [
tx.nonce,
tx.gasPrice,
tx.gas,
tx.to,
tx.value,
tx.input,
tx.v,
tx.r,
tx.s,
];
dat = dat.map((x : any) => (x == "0x0") ? "0x" : x)
dat = rlp.encode(dat)
assert(keccak256(dat) == tx.hash)
dat = rlp.decode(dat)
}
//console.log(tx)
return dat
}
function getBlockRlp(block : any) {
function getBlockRlp(block : any): Buffer {
let dat = [
block['parentHash'],
block['sha3Uncles'],
......@@ -50,20 +79,22 @@ function getBlockRlp(block : any) {
block['nonce'],
block['baseFeePerGas']
];
dat = dat.map((x) => (x == "0x0") ? "0x" : x)
return dat
dat = dat.map((x : any) => (x == "0x0") ? "0x" : x)
//console.log(dat)
let rdat = rlp.encode(dat)
assert(keccak256(rdat) == block['hash'])
return rdat
}
async function main() {
const blockNumber = 13247502;
let blockData = await provider.send("eth_getBlockByNumber", ["0x"+(blockNumber).toString(16), true])
const blockHeaderRlp = rlp.encode(getBlockRlp(blockData))
assert(keccak256(blockHeaderRlp) == blockData['hash'])
const blockHeaderRlp = getBlockRlp(blockData)
//console.log(blockData)
const txsRlp = rlp.encode(blockData.transactions.map(getTransactionRlp))
const txsRlp = blockData.transactions.map(getTransactionRlp)
fs.writeFileSync(`data/block_${blockNumber}`, blockHeaderRlp)
fs.writeFileSync(`data/tx_${blockNumber}`, txsRlp)
fs.writeFileSync(`data/txs_${blockNumber}`, rlp.encode(txsRlp))
}
main().then(() => process.exit(0))
......@@ -32,7 +32,7 @@ func main() {
// read txs
var txs []*types.Transaction
{
f, _ := os.Open("data/tx_13247502")
f, _ := os.Open("data/txs_13247502")
defer f.Close()
rlpheader := rlp.NewStream(f, 0)
rlpheader.Decode(&txs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment