Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a bunch of troubleshooting noise
Browse files Browse the repository at this point in the history
This change makes it much clearer exactly where the Mac is running out
of ink.
eljobe committed Jul 17, 2024

Verified

This commit was signed with the committer’s verified signature.
eljobe Pepper Lebeck-Jobe
1 parent b6d2ff5 commit f00ea31
Showing 6 changed files with 44 additions and 15 deletions.
4 changes: 4 additions & 0 deletions arbitrator/prover/src/programs/meter.rs
Original file line number Diff line number Diff line change
@@ -246,6 +246,10 @@ pub trait MeteredMachine {
}

fn out_of_ink<T>(&mut self) -> Result<T, OutOfInkError> {
println!(
"Got out of ink in rust at:\n{}",
std::backtrace::Backtrace::force_capture()
);
self.set_meter(MachineMeter::Exhausted);
Err(OutOfInkError)
}
2 changes: 1 addition & 1 deletion arbitrator/stylus/tests/multicall/Cargo.toml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ edition = "2021"
alloy-primitives = "0.3.1"
alloy-sol-types = "0.3.1"
mini-alloc = "0.4.2"
stylus-sdk = { path = "../../../langs/rust/stylus-sdk", features = ["reentrant"] }
stylus-sdk = { path = "../../../langs/rust/stylus-sdk", features = ["reentrant", "debug"] }
hex = "0.4.3"
wee_alloc = "0.4.5"

36 changes: 25 additions & 11 deletions arbitrator/stylus/tests/multicall/src/main.rs
Original file line number Diff line number Diff line change
@@ -6,21 +6,20 @@
extern crate alloc;

use stylus_sdk::{
storage::{StorageCache, GlobalStorage},
alloy_primitives::{Address, B256},
alloy_sol_types::sol,
call::RawCall,
console,
evm,
console, evm,
prelude::*,
storage::{GlobalStorage, StorageCache},
};

use wee_alloc::WeeAlloc;

#[global_allocator]
static ALLOC: WeeAlloc = WeeAlloc::INIT;

sol!{
sol! {
event Called(address addr, uint8 count, bool success, bytes return_data);
event Storage(bytes32 slot, bytes32 data, bool write);
}
@@ -74,20 +73,31 @@ fn user_main(input: Vec<u8>) -> Result<Vec<u8>, Vec<u8>> {
Ok(return_data) => (true, return_data),
Err(revert_data) => {
if kind & 0x4 == 0 {
return Err(revert_data)
console!(
"Contract {addr} errored with {} and kind matchhing 0x4",
revert_data.len()
);
return Err(revert_data);
}
(false, vec![])
},
}
};

if !return_data.is_empty() {
console!("Contract {addr} returned {} bytes", return_data.len());
} else {
console!("Contract {addr} returned no data");
}
if kind & 0x8 != 0 {
evm::log(Called { addr, count, success, return_data: return_data.clone() })
evm::log(Called {
addr,
count,
success,
return_data: return_data.clone(),
})
}
output.extend(return_data);
} else if kind & 0xf0 == 0x10 {
} else if kind & 0xf0 == 0x10 {
// storage
let slot = B256::try_from(&curr[..32]).unwrap();
curr = &curr[32..];
@@ -99,7 +109,7 @@ fn user_main(input: Vec<u8>) -> Result<Vec<u8>, Vec<u8>> {
write = true;
unsafe { StorageCache::set_word(slot.into(), data.into()) };
StorageCache::flush();
} else if kind & 0x7 == 1{
} else if kind & 0x7 == 1 {
console!("reading slot");
write = false;
data = StorageCache::get_word(slot.into());
@@ -109,7 +119,11 @@ fn user_main(input: Vec<u8>) -> Result<Vec<u8>, Vec<u8>> {
}
if kind & 0x8 != 0 {
console!("slot: {}, data: {}, write {write}", slot, data);
evm::log(Storage { slot: slot.into(), data: data.into(), write })
evm::log(Storage {
slot: slot.into(),
data: data.into(),
write,
})
}
} else {
panic!("unknown action {kind}")
3 changes: 3 additions & 0 deletions arbos/programs/api.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ package programs

import (
"errors"
"fmt"
"runtime/debug"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
@@ -209,6 +211,7 @@ func newApiClosures(
baseCost = am.SaturatingUAdd(baseCost, keccakCost)
}
if gas < baseCost {
fmt.Printf("got out of gas at:\n%v\n", string(debug.Stack()))
return zeroAddr, nil, gas, vm.ErrOutOfGas
}
gas -= baseCost
6 changes: 5 additions & 1 deletion arbos/programs/programs.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"math/big"
"runtime/debug"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
@@ -210,6 +211,7 @@ func (p Programs) CallProgram(
callCost = am.SaturatingUAdd(callCost, program.initGas(params))
}
if err := contract.BurnGas(callCost); err != nil {
fmt.Printf("got out of gas at:\n%v\n", string(debug.Stack()))
return nil, err
}
statedb.AddStylusPages(program.footprint)
@@ -253,6 +255,7 @@ func (p Programs) CallProgram(
evmCost := evmMemoryCost(uint64(len(ret)))
if startingGas < evmCost {
contract.Gas = 0
fmt.Printf("got out of gas at:\n%v\n", string(debug.Stack()))
return nil, vm.ErrOutOfGas
}
maxGasToReturn := startingGas - evmCost
@@ -552,7 +555,7 @@ const (
userOutOfStack
)

func (status userStatus) toResult(data []byte, debug bool) ([]byte, string, error) {
func (status userStatus) toResult(data []byte, _ bool) ([]byte, string, error) {
msg := arbutil.ToStringOrHex(data)
switch status {
case userSuccess:
@@ -562,6 +565,7 @@ func (status userStatus) toResult(data []byte, debug bool) ([]byte, string, erro
case userFailure:
return nil, msg, vm.ErrExecutionReverted
case userOutOfInk:
fmt.Printf("got out of gas at:\n%v\n", string(debug.Stack()))
return nil, "", vm.ErrOutOfGas
case userOutOfStack:
return nil, "", vm.ErrDepth
8 changes: 6 additions & 2 deletions system_tests/program_test.go
Original file line number Diff line number Diff line change
@@ -960,7 +960,6 @@ func testMemory(t *testing.T, jit bool) {
l2info := builder.L2Info
l2client := builder.L2.Client
l2rpc := l2client.Client()
defer l2rpc.Close()
defer cleanup()

trace := func(ctx context.Context, tx *types.Transaction) error {
@@ -995,7 +994,7 @@ func testMemory(t *testing.T, jit bool) {
Require(t, err)

ensure(arbOwner.SetInkPrice(&auth, 1e4))
ensure(arbOwner.SetMaxTxGasLimit(&auth, 34000000))
ensure(arbOwner.SetMaxTxGasLimit(&auth, 1e9))

memoryAddr := deployWasm(t, ctx, auth, l2client, watFile("memory"))
multiAddr := deployWasm(t, ctx, auth, l2client, rustFile("multicall"))
@@ -1553,6 +1552,11 @@ func readWasmFile(t *testing.T, file string) ([]byte, []byte) {
wasm, err := arbcompress.Compress(wasmSource, arbcompress.LEVEL_WELL, randDict)
Require(t, err)

if name == "memory" {
colors.PrintGrey(fmt.Sprintf("memory randDict: %v", randDict))
colors.PrintGrey(fmt.Sprintf("memory wasmHash: %v", crypto.Keccak256Hash(wasm)))
}

toKb := func(data []byte) float64 { return float64(len(data)) / 1024.0 }
colors.PrintGrey(fmt.Sprintf("%v: len %.2fK vs %.2fK", name, toKb(wasm), toKb(wasmSource)))

0 comments on commit f00ea31

Please sign in to comment.