2022-06-20 20:32:29 -07:00
|
|
|
//! Loads each kernel assembly file and concatenates them.
|
|
|
|
|
|
2022-07-08 08:56:46 -07:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use ethereum_types::U256;
|
2022-06-20 20:32:29 -07:00
|
|
|
use itertools::Itertools;
|
2022-07-14 11:31:47 -07:00
|
|
|
use once_cell::sync::Lazy;
|
2022-06-20 20:32:29 -07:00
|
|
|
|
|
|
|
|
use super::assembler::{assemble, Kernel};
|
|
|
|
|
use crate::cpu::kernel::parser::parse;
|
2022-07-16 09:59:23 -07:00
|
|
|
use crate::memory::segments::Segment;
|
2022-06-20 20:32:29 -07:00
|
|
|
|
2022-07-14 11:31:47 -07:00
|
|
|
pub static KERNEL: Lazy<Kernel> = Lazy::new(combined_kernel);
|
2022-06-20 20:32:29 -07:00
|
|
|
|
2022-07-08 08:56:46 -07:00
|
|
|
pub fn evm_constants() -> HashMap<String, U256> {
|
|
|
|
|
let mut c = HashMap::new();
|
2022-07-16 09:59:23 -07:00
|
|
|
for segment in Segment::all() {
|
|
|
|
|
c.insert(segment.var_name().into(), (segment as u32).into());
|
|
|
|
|
}
|
2022-07-08 08:56:46 -07:00
|
|
|
c
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 20:32:29 -07:00
|
|
|
#[allow(dead_code)] // TODO: Should be used once witness generation is done.
|
|
|
|
|
pub(crate) fn combined_kernel() -> Kernel {
|
|
|
|
|
let files = vec![
|
2022-07-18 13:48:51 -07:00
|
|
|
include_str!("asm/assertions.asm"),
|
2022-06-25 23:10:08 -07:00
|
|
|
include_str!("asm/basic_macros.asm"),
|
2022-07-05 21:24:51 +02:00
|
|
|
include_str!("asm/exp.asm"),
|
2022-07-05 21:12:11 +02:00
|
|
|
include_str!("asm/curve_mul.asm"),
|
2022-07-01 18:28:22 +02:00
|
|
|
include_str!("asm/curve_add.asm"),
|
2022-07-05 15:01:40 +02:00
|
|
|
include_str!("asm/moddiv.asm"),
|
2022-07-13 19:22:32 +02:00
|
|
|
include_str!("asm/secp256k1/curve_mul.asm"),
|
|
|
|
|
include_str!("asm/secp256k1/curve_add.asm"),
|
|
|
|
|
include_str!("asm/secp256k1/moddiv.asm"),
|
2022-07-14 13:07:58 +02:00
|
|
|
include_str!("asm/secp256k1/lift_x.asm"),
|
|
|
|
|
include_str!("asm/secp256k1/inverse_scalar.asm"),
|
2022-07-13 18:48:25 +02:00
|
|
|
include_str!("asm/ecrecover.asm"),
|
2022-07-05 21:24:51 +02:00
|
|
|
include_str!("asm/storage_read.asm"),
|
|
|
|
|
include_str!("asm/storage_write.asm"),
|
2022-06-20 20:32:29 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let parsed_files = files.iter().map(|f| parse(f)).collect_vec();
|
2022-07-08 08:56:46 -07:00
|
|
|
assemble(parsed_files, evm_constants())
|
2022-06-20 20:32:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
2022-07-13 09:53:44 -07:00
|
|
|
use log::debug;
|
2022-07-07 18:06:24 +02:00
|
|
|
|
2022-06-20 20:32:29 -07:00
|
|
|
use crate::cpu::kernel::aggregator::combined_kernel;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn make_kernel() {
|
2022-07-13 09:53:44 -07:00
|
|
|
let _ = env_logger::Builder::from_default_env()
|
|
|
|
|
.format_timestamp(None)
|
|
|
|
|
.try_init();
|
|
|
|
|
|
2022-06-20 20:32:29 -07:00
|
|
|
// Make sure we can parse and assemble the entire kernel.
|
2022-07-07 08:59:53 -07:00
|
|
|
let kernel = combined_kernel();
|
2022-07-13 09:53:44 -07:00
|
|
|
debug!("Total kernel size: {} bytes", kernel.code.len());
|
2022-06-20 20:32:29 -07:00
|
|
|
}
|
|
|
|
|
}
|