Skip to content

Instantly share code, notes, and snippets.

#[test]
fn use_ccp_to_memory_clear() {
let mut test_context = TestBuilder::new(2322u64);
let gas_limit = 10_000_000;
let program = vec![
op::ret(RegId::ZERO), // super short contract
];
pub(crate) fn copy_from_slice_zero_fill<A: ToAddr, B: ToAddr>(
memory: &mut Memory,
owner: H160,
src: &[u8],
dst_addr: A,
src_offset: usize,
len: usize,
) -> Result<(), Error> {
let range = memory.write(owner, dst_addr, len)?;
pub(crate) fn code_copy(...) {
// Charges gas based on the contract's length
dependent_gas_charge_without_base(
self.cgas,
self.ggas,
profiler,
self.gas_cost,
contract_len as u64, // <-- Charged based on this
)?;
#[tokio::test]
async fn pow_bug() {
//Setup
let (instance, _id) = get_contract_instance().await;
println!("------------u8 pow function overflow----------------");
let asset_id = instance.methods().demonstrate_bug_u8(Identity::Address(instance.account().address().into()), 20)
.append_variable_outputs(1)
.call()
.await
contract;
//Setup
use std::{
asset::mint_to,
constants::DEFAULT_SUB_ID
};
abi PowBug {
fn demonstrate_bug_u8(recipient: Identity, a: u8) -> AssetId;
impl Power for u32 {
fn pow(self, exponent: u32) -> Self {
asm(r1: self, r2: exponent, r3) {
exp r3 r1 r2;
r3: Self
}
}
}
impl Power for u16 {
/// Returns a list of all registers *read* by instruction `self`.
pub(crate) fn use_registers(&self) -> BTreeSet<&VirtualRegister> {
use VirtualOp::*;
(match self {
/* Arithmetic/Logic (ALU) Instructions */
...
WQAM(_, r2, r3, r4) => vec![r2, r3, r4],
...
})
.into_iter()
// ownable.sw
library;
pub struct OwnershipTransferred {
previous_owner: b256,
new_owner: b256,
}
pub trait StorageHelpers {
// main.sw
contract;
mod ownable;
use ownable::*;
storage {
owner: b256 = b256::zero(),
}
pub fn validate_root(...) {
...
// ABI entries are all functions declared in impl_traits on the contract type
// itself, except for ABI supertraits, which do not expose their methods to
// the user
...
}