Skip to content

Commit

Permalink
cache updates working
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Jul 25, 2024
1 parent be51b58 commit 469abc6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
31 changes: 6 additions & 25 deletions check/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023-2024, Offchain Labs, Inc.
// For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/stylus/licenses/COPYRIGHT.md

use alloy_primitives::FixedBytes;
use alloy_primitives::Address;
use alloy_sol_macro::sol;
use alloy_sol_types::{SolCall, SolInterface};
use cargo_stylus_util::color::{Color, DebugColor};
Expand All @@ -10,18 +10,16 @@ use ethers::middleware::{Middleware, SignerMiddleware};
use ethers::signers::Signer;
use ethers::types::spoof::State;
use ethers::types::{Eip1559TransactionRequest, U256};
use ethers::utils::keccak256;
use eyre::{bail, Context, Result};

use crate::check::{eth_call, EthCallError};
use crate::constants::{CACHE_MANAGER_H160, EOF_PREFIX_NO_DICT};
use crate::deploy::{format_gas, run_tx};
use crate::macros::greyln;
use crate::CacheConfig;

sol! {
interface CacheManager {
function placeBid(bytes32 codehash) external payable;
function placeBid(address program) external payable;

error AsmTooLarge(uint256 asm, uint256 queueSize, uint256 cacheSize);
error AlreadyCached(bytes32 codehash);
Expand All @@ -41,27 +39,10 @@ pub async fn cache_program(cfg: &CacheConfig) -> Result<()> {
let wallet = wallet.with_chain_id(chain_id.as_u64());
let client = SignerMiddleware::new(provider.clone(), wallet);

let program_code = client
.get_code(cfg.program_address, None)
.await
.wrap_err("failed to fetch program code")?;

if !program_code.starts_with(hex::decode(EOF_PREFIX_NO_DICT).unwrap().as_slice()) {
bail!(
"program code does not start with Stylus prefix {}",
EOF_PREFIX_NO_DICT
);
}
let codehash = FixedBytes::<32>::from(keccak256(&program_code));
greyln!(
"Program codehash {}",
hex::encode(codehash).debug_lavender()
);
let codehash = FixedBytes::<32>::from(keccak256(&program_code));

let data = CacheManager::placeBidCall { codehash }.abi_encode();
let program: Address = cfg.address.to_fixed_bytes().into();
let data = CacheManager::placeBidCall { program }.abi_encode();
let mut tx = Eip1559TransactionRequest::new()
.to(*CACHE_MANAGER_H160)
.to(cfg.cache_manager_address)
.data(data);

// If a bid is set, specify it. Otherwise, a zero bid will be sent.
Expand Down Expand Up @@ -100,7 +81,7 @@ pub async fn cache_program(cfg: &CacheConfig) -> Result<()> {
)
.await?;

let address = cfg.program_address.debug_lavender();
let address = cfg.address.debug_lavender();

if verbose {
let gas = format_gas(receipt.gas_used.unwrap_or_default());
Expand Down
5 changes: 0 additions & 5 deletions check/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ pub const BROTLI_COMPRESSION_LEVEL: u32 = 11;
lazy_static! {
/// Address of the ArbWasm precompile.
pub static ref ARB_WASM_H160: H160 = H160(*ARB_WASM_ADDRESS.0);
/// Address of the Stylus program cache manager.
pub static ref CACHE_MANAGER_H160: H160 = H160(*CACHE_MANAGER_ADDRESS.0);
}

/// Address of the ArbWasm precompile.
pub const ARB_WASM_ADDRESS: Address = address!("0000000000000000000000000000000000000071");

/// Address of the Stylus program cache manager for Arbitrum chains.
pub const CACHE_MANAGER_ADDRESS: Address = address!("d1bbd579988f394a26d6ec16e77b3fa8a5e8fcee");

/// Target for compiled WASM folder in a Rust project
pub const RUST_TARGET: &str = "wasm32-unknown-unknown";

Expand Down
4 changes: 3 additions & 1 deletion check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ pub struct CacheConfig {
auth: AuthOpts,
/// Deployed and activated program address to cache.
#[arg(long)]
program_address: H160,
address: H160,
#[arg(long, default_value = "0c9043d042ab52cfa8d0207459260040cca54253")]
cache_manager_address: H160,
/// Bid, in wei, to place on the desired program to cache
#[arg(short, long, hide(true))]
bid: Option<u64>,
Expand Down

0 comments on commit 469abc6

Please sign in to comment.