Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 78 additions & 13 deletions app_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use craftlib::{
item::{CraftBuilder, MiningRecipe},
powpod::PowPod,
predicates::ItemPredicates,
vdfpod::VdfPod,
};
use plonky2::field::types::Field;
use pod2::{
Expand Down Expand Up @@ -180,6 +181,7 @@ impl Helper {
recipe: Recipe,
item_def: ItemDef,
input_item_pods: Vec<MainPod>,
vdf_pod: Option<VdfPod>,
pow_pod: Option<PowPod>,
) -> anyhow::Result<MainPod> {
let prover = &Prover {};
Expand Down Expand Up @@ -229,7 +231,7 @@ impl Helper {
CraftBuilder::new(BuildContext::new(&mut builder, &self.batches), &self.params);
let st_craft = match recipe {
Recipe::Stone => {
// unwrap safe since if we're at Stone, pow_pod is Some
// unwrap safe since if we're at Stone, both pods are Some
let pow_pod = pow_pod.unwrap();
let st_pow = pow_pod.pub_statements()[0].clone();
let main_pow_pod = MainPod {
Expand All @@ -238,15 +240,47 @@ impl Helper {
params: craft_builder.params.clone(),
};
craft_builder.ctx.builder.add_pod(main_pow_pod);
craft_builder.st_is_stone(item_def, st_item_def.clone(), st_pow)?

let vdf_pod = vdf_pod.unwrap();
let st_vdf = vdf_pod.pub_statements()[0].clone();
let main_vdf_pod = MainPod {
pod: Box::new(vdf_pod.clone()),
public_statements: vdf_pod.pub_statements(),
params: craft_builder.params.clone(),
};
craft_builder.ctx.builder.add_pod(main_vdf_pod);
craft_builder.st_is_stone(item_def, st_item_def.clone(), st_pow, st_vdf)?
}
Recipe::Wood => {
// unwrap safe since if we're at Wood, pow_pod is Some
let pow_pod = pow_pod.unwrap();
let st_pow = pow_pod.pub_statements()[0].clone();
let main_pow_pod = MainPod {
pod: Box::new(pow_pod.clone()),
public_statements: pow_pod.pub_statements(),
params: craft_builder.params.clone(),
};
craft_builder.ctx.builder.add_pod(main_pow_pod);
craft_builder.st_is_wood(item_def, st_item_def.clone(), st_pow)?
}
Recipe::Axe => {
// unwrap safe since if we're at Axe, pow_pod is Some
let pow_pod = pow_pod.unwrap();
let st_pow = pow_pod.pub_statements()[0].clone();
let main_pow_pod = MainPod {
pod: Box::new(pow_pod.clone()),
public_statements: pow_pod.pub_statements(),
params: craft_builder.params.clone(),
};
craft_builder.ctx.builder.add_pod(main_pow_pod);
craft_builder.st_is_axe(
item_def,
st_item_def.clone(),
st_pow,
sts_input_craft[0].clone(),
sts_input_craft[1].clone(),
)?
}
Recipe::Wood => craft_builder.st_is_wood(item_def, st_item_def.clone())?,
Recipe::Axe => craft_builder.st_is_axe(
item_def,
st_item_def.clone(),
sts_input_craft[0].clone(),
sts_input_craft[1].clone(),
)?,
Recipe::WoodenAxe => craft_builder.st_is_wooden_axe(
item_def,
st_item_def.clone(),
Expand Down Expand Up @@ -306,7 +340,7 @@ pub fn craft_item(
let vd_set = DEFAULT_VD_SET.clone();
let key = rand_raw_value();
info!("About to craft \"{recipe}\" with key {key:#}");
let (item_def, input_items, pow_pod) = match recipe {
let (item_def, input_items, vdf_pod, pow_pod) = match recipe {
Recipe::Stone => {
if !inputs.is_empty() {
bail!("{recipe} takes 0 inputs");
Expand All @@ -320,16 +354,26 @@ pub fn craft_item(
let pow_pod = PowPod::new(
params,
vd_set.clone(),
3, // num_iters
RawValue::from(ingredients_def.dict(params)?.commitment()),
STONE_MINING_MAX,
)?;
log::info!("[TIME] PowPod proving time: {:?}", start.elapsed());

let start = std::time::Instant::now();
let vdf_pod = VdfPod::new(
params,
vd_set.clone(),
3, // num_iters
RawValue::from(ingredients_def.dict(params)?.commitment()),
)?;
log::info!("[TIME] VdfPod proving time: {:?}", start.elapsed());
(
ItemDef {
ingredients: ingredients_def.clone(),
work: pow_pod.output,
work: vdf_pod.output,
},
vec![],
Some(vdf_pod),
Some(pow_pod),
)
}
Expand All @@ -341,13 +385,23 @@ pub fn craft_item(
let ingredients_def = mining_recipe
.do_mining(params, key, 0, WOOD_MINING_MAX)?
.unwrap();

let start = std::time::Instant::now();
let pow_pod = PowPod::new(
params,
vd_set.clone(),
RawValue::from(ingredients_def.dict(params)?.commitment()),
WOOD_MINING_MAX,
)?;
log::info!("[TIME] PowPod proving time: {:?}", start.elapsed());
(
ItemDef {
ingredients: ingredients_def.clone(),
work: WOOD_WORK,
},
vec![],
None,
Some(pow_pod),
)
}
Recipe::Axe => {
Expand All @@ -363,13 +417,23 @@ pub fn craft_item(
let ingredients_def = mining_recipe
.do_mining(params, key, 0, AXE_MINING_MAX)?
.unwrap();

let start = std::time::Instant::now();
let pow_pod = PowPod::new(
params,
vd_set.clone(),
RawValue::from(ingredients_def.dict(params)?.commitment()),
AXE_MINING_MAX,
)?;
log::info!("[TIME] PowPod proving time: {:?}", start.elapsed());
(
ItemDef {
ingredients: ingredients_def.clone(),
work: AXE_WORK,
},
vec![wood, stone],
None,
Some(pow_pod),
)
}
Recipe::WoodenAxe => {
Expand All @@ -392,13 +456,14 @@ pub fn craft_item(
},
vec![wood1, wood2],
None,
None,
)
}
};

let helper = Helper::new(params.clone(), vd_set);
let input_item_pods: Vec<_> = input_items.iter().map(|item| &item.pod).cloned().collect();
let pod = helper.make_item_pod(recipe, item_def.clone(), input_item_pods, pow_pod)?;
let pod = helper.make_item_pod(recipe, item_def.clone(), input_item_pods, vdf_pod, pow_pod)?;

let crafted_item = CraftedItem { pod, def: item_def };
let mut file = std::fs::File::create(output)?;
Expand Down
18 changes: 11 additions & 7 deletions app_gui/src/crafting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ lazy_static! {
description: "Stone. Hard to find.",
outputs: &["Stone"],
predicate: r#"
use intro Pow(count, input, output) from 0x3493488bc23af15ac5fabe38c3cb6c4b66adb57e3898adf201ae50cc57183f65
use intro Vdf(count, input, output) from 0x3493488bc23af15ac5fabe38c3cb6c4b66adb57e3898adf201ae50cc57183f65
use intro Pow(hash, difficulty) from 0x42fed42704533123de144a9e820c9d6bdf4c8616f29664111469bd696b628686 // powpod vd hash

IsStone(item, private: ingredients, inputs, key, work) = AND(
IsStone(item, private: ingredients, inputs, key, work, difficulty, ingredients_hash) = AND(
ItemDef(item, ingredients, inputs, key, work)
Equal(inputs, {})
DictContains(ingredients, "blueprint", "stone")
Pow(3, ingredients, work)
Pow(ingredients, difficulty)
Vdf(3, ingredients, work)
)"#,
..Default::default()
};
Expand All @@ -57,6 +59,7 @@ IsWood(item, private: ingredients, inputs, key, work) = AND(
ItemDef(item, ingredients, inputs, key, work)
Equal(inputs, {})
DictContains(ingredients, "blueprint", "wood")
Pow(ingredients, difficulty)
)"#,
..Default::default()
};
Expand All @@ -68,6 +71,7 @@ IsWood(item, private: ingredients, inputs, key, work) = AND(
IsAxe(item, private: ingredients, inputs, key, work, s1, wood, stone) = AND(
ItemDef(item, ingredients, inputs, key, work)
DictContains(ingredients, "blueprint", "axe")
Pow(ingredients, difficulty)
Equal(work, {})

// 2 ingredients
Expand Down Expand Up @@ -136,7 +140,7 @@ IsTomato(item, private: batch, ingredients, inputs, key, work, farm_level) = AND
TomatoRecipe(batch, farm_level, ingredients, inputs, key, work)
ItemInBatch(item, batch, "tomato")
)

UsedFarm(item, level, private: batch, ingredients, inputs, key, work) = AND(
TomatoRecipe(batch, level ingredients, inputs, key, work)
ItemInBatch(item, batch, "farm")
Expand Down Expand Up @@ -164,7 +168,7 @@ SteelSwordRecipe(batch, ingredients, inputs, key, work, forge, steel1, steel2, w
SetInsert(s3, s2, steel2)
SetInsert(s4, s3, wood)
SetInsert(inputs, s4, forge)

IsForge(forge)
IsSteel(steel1)
IsSteel(steel2)
Expand Down Expand Up @@ -215,7 +219,7 @@ IsH(item) = OR(
IsH0(item)
IsH1(item)
)

IsO(item, private: batch, ingredients, inputs, key, work) = AND(
DisassembleH2O(batch, ingredients, inputs, key, work)
ItemInBatch(item, batch, "2")
Expand All @@ -233,7 +237,7 @@ IsRefinedUranium(item, private: ingredients, inputs, key, work) = AND(

SetInsert(inputs, {}, uranium)
IsUranium(uranium)
Pow(100, ingredients, work)
Vdf(100, ingredients, work)
)"#,
..Default::default()
};
Expand Down
Loading