Commit 0154de17 authored by George Hotz's avatar George Hotz

delete stuff, remove TODOs

parent 54a6f4d7
...@@ -18,13 +18,10 @@ It's half geth, half of what I think truebit was supposed to be. When it's done, ...@@ -18,13 +18,10 @@ It's half geth, half of what I think truebit was supposed to be. When it's done,
The system is checking an embedded block in CI now The system is checking an embedded block in CI now
* TODO: Fix missing trie nodes [see issue](https://github.com/geohot/cannon/issues/1) * TODO: Fix missing trie nodes [see issue](https://github.com/geohot/cannon/issues/1)
* TODO: Get initial block info / txs with oracle
* TODO: Stub all syscalls after it's "booted" * TODO: Stub all syscalls after it's "booted"
## TODO ## TODO
* Make minigeth use the 0xD0000000 input oracle / add input oracle to risc/run.py. See [contracts/Challenge.sol](https://github.com/geohot/cannon/blob/master/contracts/Challenge.sol)
* Add blocks / tx trie to the preimage oracle [see issue](https://github.com/geohot/cannon/issues/2)
* Finish and test the MIPS state transition function in contracts/MIPS.sol * Finish and test the MIPS state transition function in contracts/MIPS.sol
* Get minigeth running in Solidity MIPS emulator with reasonable performance (Go code using EVM with native memory) * Get minigeth running in Solidity MIPS emulator with reasonable performance (Go code using EVM with native memory)
* Add merkleization for MIPS ReadMemory and WriteMemory * Add merkleization for MIPS ReadMemory and WriteMemory
......
\ No newline at end of file
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')
// local geth
const provider = new ethers.providers.JsonRpcProvider('http://192.168.1.213:8545')
/*
type extblock struct {
Header *Header
Txs []*Transaction
Uncles []*Header
}
*/
function getTransactionRlp(tx : any): Buffer {
let dat: any
// TODO: there are also type 1 transactions
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): Buffer {
let dat = [
block['parentHash'],
block['sha3Uncles'],
block['miner'],
block['stateRoot'],
block['transactionsRoot'],
block['receiptsRoot'],
block['logsBloom'],
block['difficulty'],
block['number'],
block['gasLimit'],
block['gasUsed'],
block['timestamp'],
block['extraData'],
block['mixHash'],
block['nonce'],
block['baseFeePerGas']
];
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 getBlock(blockNumber: Number) {
let blockData = await provider.send("eth_getBlockByNumber", ["0x"+(blockNumber).toString(16), true])
const blockHeaderRlp = getBlockRlp(blockData)
//console.log(blockData)
const txsRlp = blockData.transactions.map(getTransactionRlp)
fs.writeFileSync(`data/block_${blockNumber}`, blockHeaderRlp)
fs.writeFileSync(`data/txs_${blockNumber}`, rlp.encode(txsRlp))
}
async function main() {
/*await getBlock(13247501)
await getBlock(13247502)*/
await getBlock(13284491)
await getBlock(13284492)
}
main().then(() => process.exit(0))
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