Skip to content

Commit

Permalink
new pricing table
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Dec 19, 2023
1 parent 3d3cc66 commit d408154
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 161 deletions.
63 changes: 19 additions & 44 deletions arbitrator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion arbitrator/arbutil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ digest = "0.9.0"
eyre = "0.6.5"
hex = "0.4.3"
num-traits = "0.2.17"
sha3 = "0.10.5"
siphasher = "0.3.10"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
wasmparser.workspace = true
serde = { version = "1.0.130", features = ["derive", "rc"] }

Expand Down
17 changes: 12 additions & 5 deletions arbitrator/arbutil/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// Copyright 2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

use sha3::{Digest, Keccak256};
use siphasher::sip::SipHasher24;
use std::hash::Hasher;
use std::mem::MaybeUninit;
use tiny_keccak::{Hasher, Keccak};

pub fn keccak<T: AsRef<[u8]>>(preimage: T) -> [u8; 32] {
let mut hasher = Keccak256::new();
hasher.update(preimage);
hasher.finalize().into()
let mut output = MaybeUninit::<[u8; 32]>::uninit();
let mut hasher = Keccak::v256();
hasher.update(preimage.as_ref());

// SAFETY: finalize() writes 32 bytes
unsafe {
hasher.finalize(&mut *output.as_mut_ptr());
output.assume_init()
}
}

pub fn siphash(preimage: &[u8], key: &[u8; 16]) -> u64 {
use std::hash::Hasher;
let mut hasher = SipHasher24::new_with_key(key);
hasher.write(preimage);
hasher.finish()
Expand Down
4 changes: 2 additions & 2 deletions arbitrator/arbutil/src/pricing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

/// For hostios that may return something.
pub const HOSTIO_INK: u64 = 12513;
pub const HOSTIO_INK: u64 = 8400;

/// For hostios that include pointers.
pub const PTR_INK: u64 = 22137 - HOSTIO_INK;
pub const PTR_INK: u64 = 13440 - HOSTIO_INK;

/// For hostios that involve an API cost.
pub const EVM_API_INK: u64 = 59673;
2 changes: 1 addition & 1 deletion arbitrator/prover/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl<'a> Debug for WasmBinary<'a> {
impl<'a> WasmBinary<'a> {
/// Instruments a user wasm, producing a version bounded via configurable instrumentation.
pub fn instrument(&mut self, compile: &CompileConfig) -> Result<StylusData> {
let meter = Meter::new(compile.pricing.costs);
let meter = Meter::new(&compile.pricing);
let dygas = DynamicMeter::new(&compile.pricing);
let depth = DepthChecker::new(compile.bounds);
let bound = HeapBound::new(compile.bounds);
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/prover/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@ impl Machine {

if !guards.is_empty() || self.guards.enabled {
h.update(b"With guards:");
h.update(&[self.guards.enabled as u8]);
h.update([self.guards.enabled as u8]);
h.update(ErrorGuardProof::hash_guards(&guards));
}
}
Expand Down
10 changes: 7 additions & 3 deletions arbitrator/prover/src/programs/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub struct CompilePricingParams {
/// Associates opcodes to their ink costs
#[derivative(Debug = "ignore")]
pub costs: OpCosts,
/// Cost of checking the amount of ink left.
pub ink_header_cost: u64,
/// Per-byte `MemoryFill` cost
pub memory_fill_ink: u64,
/// Per-byte `MemoryCopy` cost
Expand All @@ -132,6 +134,7 @@ impl Default for CompilePricingParams {
fn default() -> Self {
Self {
costs: |_, _| 0,
ink_header_cost: 0,
memory_fill_ink: 0,
memory_copy_ink: 0,
}
Expand Down Expand Up @@ -163,8 +166,9 @@ impl CompileConfig {
config.bounds.max_frame_contention = 4096;
config.pricing = CompilePricingParams {
costs: meter::pricing_v1,
memory_fill_ink: 1000 / 8,
memory_copy_ink: 1000 / 8,
ink_header_cost: 2450,
memory_fill_ink: 800 / 8,
memory_copy_ink: 800 / 8,
};
}
_ => panic!("no config exists for Stylus version {version}"),
Expand All @@ -186,7 +190,7 @@ impl CompileConfig {
compiler.canonicalize_nans(true);
compiler.enable_verifier();

let meter = MiddlewareWrapper::new(Meter::new(self.pricing.costs));
let meter = MiddlewareWrapper::new(Meter::new(&self.pricing));
let dygas = MiddlewareWrapper::new(DynamicMeter::new(&self.pricing));
let depth = MiddlewareWrapper::new(DepthChecker::new(self.bounds));
let bound = MiddlewareWrapper::new(HeapBound::new(self.bounds));
Expand Down
Loading

0 comments on commit d408154

Please sign in to comment.