Prepared by:
HALBORN
Last Updated 07/21/2025
Date of Engagement: June 23rd, 2025 - July 7th, 2025
100% of all REPORTED Findings have been addressed
All findings
7
Critical
0
High
0
Medium
0
Low
4
Informational
3
Casper
engaged Halborn to conduct a security assessment of the CEP18 contract, beginning June 23rd, 2024 and ending July 7th, 2024.
The CEP18 contract is the standard token contract within the Casper ecosystem, and the engagement aimed to verify that the Casper network Conder upgrade did not create security vulnerabilities in the updated contract.
The team at Halborn assigned a full-time security engineer to verify the security of the smart contract. The security engineer is a blockchain and smart-contract security expert with advanced penetration testing, smart-contract hacking, and deep knowledge of multiple blockchain protocols.
The purpose of this assessment is to:
Ensure that smart contract functions operate as intended.
Identify potential security issues with the smart contracts.
In summary, Halborn identified some improvements to reduce the likelihood and impact of risks, which were mostly addressed by the Casper team
. The main ones were the following:
Support the AddressableEntities feature.
Synchronize the SDK with the added entry points.
Fix the SDK entry point parameters.
Fix the SDK events support.
Halborn performed a combination of the manual view of the code and automated security testing to balance efficiency, timeliness, practicality, and accuracy regarding the scope of the smart contract assessment. While manual testing is recommended to uncover flaws in logic, process, and implementation, automated testing techniques help enhance the coverage of smart contracts. They can quickly identify items that do not follow security best practices. The following phases and associated tools were used throughout the term of the assessment:
Research into architecture, purpose, and use of the platform.
Manual code read and walk through.
Manual Assessment of use and safety for the critical Rust variables and functions in scope to identify any arithmetic related vulnerability classes.
Cross contract call controls.
Architecture related logical controls.
Test complex scenarios with unit tests.
EXPLOITABILITY METRIC () | METRIC VALUE | NUMERICAL VALUE |
---|---|---|
Attack Origin (AO) | Arbitrary (AO:A) Specific (AO:S) | 1 0.2 |
Attack Cost (AC) | Low (AC:L) Medium (AC:M) High (AC:H) | 1 0.67 0.33 |
Attack Complexity (AX) | Low (AX:L) Medium (AX:M) High (AX:H) | 1 0.67 0.33 |
IMPACT METRIC () | METRIC VALUE | NUMERICAL VALUE |
---|---|---|
Confidentiality (C) | None (I:N) Low (I:L) Medium (I:M) High (I:H) Critical (I:C) | 0 0.25 0.5 0.75 1 |
Integrity (I) | None (I:N) Low (I:L) Medium (I:M) High (I:H) Critical (I:C) | 0 0.25 0.5 0.75 1 |
Availability (A) | None (A:N) Low (A:L) Medium (A:M) High (A:H) Critical (A:C) | 0 0.25 0.5 0.75 1 |
Deposit (D) | None (D:N) Low (D:L) Medium (D:M) High (D:H) Critical (D:C) | 0 0.25 0.5 0.75 1 |
Yield (Y) | None (Y:N) Low (Y:L) Medium (Y:M) High (Y:H) Critical (Y:C) | 0 0.25 0.5 0.75 1 |
SEVERITY COEFFICIENT () | COEFFICIENT VALUE | NUMERICAL VALUE |
---|---|---|
Reversibility () | None (R:N) Partial (R:P) Full (R:F) | 1 0.5 0.25 |
Scope () | Changed (S:C) Unchanged (S:U) | 1.25 1 |
Severity | Score Value Range |
---|---|
Critical | 9 - 10 |
High | 7 - 8.9 |
Medium | 4.5 - 6.9 |
Low | 2 - 4.4 |
Informational | 0 - 1.9 |
Critical
0
High
0
Medium
0
Low
4
Informational
3
Security analysis | Risk level | Remediation Date |
---|---|---|
Addressable entities feature activation leads to total loss of funds | Low | Risk Accepted - 07/13/2025 |
SDK is missing events | Low | Solved - 07/13/2025 |
Missing ChangeEventsModeParams declaration in SDK | Low | Solved - 07/13/2025 |
Deprecated BurnerList argument in ChangeSecurityArgs | Low | Solved - 07/13/2025 |
Unreachable caller kinds in get_immediate_caller | Informational | Solved - 07/13/2025 |
Redundant sender recipient check | Informational | Acknowledged - 07/13/2025 |
Unused ENTRY_POINT_UPGRADE constant | Informational | Solved - 07/13/2025 |
//
In casper, the caller could be externally owned accounts, represented by an AccountHash
, or a contract, represented by ContractPackageHash
, two enums of the Key
type, wrapping a hash, and the access control and balances recording are done using Key::to_bytes
.
In the new Casper network upgrade, Casper introduce a new enum inside the Key
, the AddressableEntity
. It is a new enum of Key
that can carry both Account
and Package
hashes, present in AccountHash
and ContractPackageHash
in the older version.
Therefore Casper Network is preparing to replace through a simple switch in the node codebase, that will replace in the call context:
Key::AccountHash
, by Key::AddressableEntity::Account
Key::ContractPackageHash
, by Key::AddressableEntity::Package
The critical point of that upgrade is that the transition to AddressableEntity
does not maintain the same byte value behind a Key holding the hash for an Account
and the previous AccountHash
. This has the effect of treating differently the same actors before and after the upgrade, meaning that:
Access control will cease to work on the last configuration.
Balances will immediately be lost.
The network still did not introduce the feature, but a future release with this feature activated would cause irrecoverable loss of funds for all the users in the protocol, because the getImmediateCaller
would not return the same data before and after the feature release.
The following snippets illustrates that balances will not be recognized under the same accounts. In balances.rs
, the Key
is used to create the dictionary key:
pub fn read_balance_from(address: Key) -> U256 {
let dictionary_item_key = make_dictionary_item_key(address);
get_dictionary_value_from_key(DICT_BALANCES, &dictionary_item_key).unwrap_or_default()
}
The dicitonary key is created using the Key::to_bytes
, which gives a different result before and after the AddressableEntities
upgrade.
fn make_dictionary_item_key(owner: Key) -> String {
let preimage = owner
.to_bytes()
.unwrap_or_revert_with(Cep18Error::FailedToConvertBytes);
base64_encode(preimage)
}
The following unit test shows inequality of the keys but equality of the values:
#[test]
fn test_mint_to_account_and_check_balance_with_entity_addr() {
let mint_amount = U256::from(1000);
let (
mut builder,
TestContext {
cep18_contract_hash,
..
},
) = setup_with_args(runtime_args! {
ARG_NAME => TOKEN_NAME,
ARG_SYMBOL => TOKEN_SYMBOL,
ARG_DECIMALS => TOKEN_DECIMALS,
ARG_TOTAL_SUPPLY => U256::from(TOKEN_TOTAL_SUPPLY),
ARG_ENABLE_MINT_BURN => true,
});
// Create a 32-byte array for our test address starting with `0xbeef...`.
let mut addr_bytes: HashAddr = [0u8; 32];
addr_bytes[0] = 0xbe;
addr_bytes[1] = 0xef;
// Create the keys
let account_hash = AccountHash::new(addr_bytes);
let key_as_account = Key::Account(account_hash);
let entity_addr = EntityAddr::Account(addr_bytes);
let key_as_entity_addr = Key::AddressableEntity(entity_addr.into());
let addressable_cep18_contract_hash = AddressableEntityHash::new(cep18_contract_hash.value());
let mint_request = ExecuteRequestBuilder::contract_call_by_hash(
*DEFAULT_ACCOUNT_ADDR,
addressable_cep18_contract_hash,
ENTRY_POINT_MINT,
runtime_args! {
ARG_OWNER => key_as_account,
ARG_AMOUNT => mint_amount,
},
)
.build();
builder.exec(mint_request).expect_success().commit();
let balance_from_account_key = cep18_check_balance_of(
&mut builder,
&cep18_contract_hash,
key_as_account,
);
assert_eq!(balance_from_account_key, mint_amount);
let balance_from_entity_addr_key = cep18_check_balance_of(
&mut builder,
&cep18_contract_hash,
key_as_entity_addr,
);
// This one passes because the balance is not the same even though the address hash is the same
assert_ne!(balance_from_account_key, balance_from_entity_addr_key);
}
The test is successful and proves that keys are not equal, leading to different balances for the AccountHash
and the AddressableEntity
:
Implement a canonical serialization within Key::to_bytes
(or inside make_dictionary_item_key
) that maps AddressableEntity::Account
to the legacy AccountHash
byte sequence and AddressableEntity::Package
to the legacy ContractPackageHash
sequence. This ensures that dictionary keys and access controls established before the upgrade remain valid.
RISK ACCEPTED: The Casper team accepted the risk behind this finding, also mentioning that:
Current CEP-18
implementation still derives the dictionary keys straight from Key::to_bytes(
).
There is no logic anywhere in the crate that recognizes the new Key::AddressableEntity::{Account,Package}
variants or normalizes them back to the old byte layout.
No occurrence of AddressableEntity
in the codebase.
No conversion helper that strips the leading variant-tag byte before storing / reading.
utils::get_immediate_caller_address()
still returns a plain Key produced with Key::from(...)
. When the upstream Casper libraries switch that constructor to emit the new Key::AddressableEntity
variants, the bytes returned by to_bytes()
will differ from the ones that were stored previously
Moreover, the CEP18 contract is intended for the current configuration of the Casper network, and the activation of the AddressableEntities
feature would take the nodes to apply the change, which would most likely not happen if Casper Labs
does not push for it.
//
The TypeScript client is missing two events that are defined and emitted by the Rust contract:
ChangeSecurity
, emitted when security settings are modified.
ChangeEventsMode
, emitted when the events mode is changed.
Update the TypeScript SDK’s contract ABI to incorporate the ChangeSecurity
and ChangeEventsMode
event definitions. Additionally, add the corresponding event interfaces and listener logic to enable the client to emit these events.
SOLVED: The Casper team added ChangeSecurity and ChangeEventsMode event types to client-js/src/events.ts, extending the CEP-18 event union and EventsMap so the TypeScript client now recognizes and handles these contract events correctly.
//
The SDK exposes types for each entry points in the CEP18 contract, however does not declare the ChangeEventsMode
params.
For example, the ChangeSecurityArgs
type in client-js/src/types.ts
:
export type ChangeSecurityArgs = {
adminList?: Entity[];
minterList?: Entity[];
// [...]
};
Reflects the change_security function in contracts/contract/src/main.rs
:
pub extern "C" fn change_security() {
if 0 == get_stored_value::<u8>(ARG_ENABLE_MINT_BURN) {
revert(Cep18Error::MintBurnDisabled);
}
sec_check(vec![SecurityBadge::Admin]);
let admin_list: Option<Vec<Key>> =
get_optional_named_arg_with_user_errors(ADMIN_LIST, Cep18Error::InvalidAdminList);
let minter_list: Option<Vec<Key>> =
get_optional_named_arg_with_user_errors(MINTER_LIST, Cep18Error::InvalidMinterList);
let none_list: Option<Vec<Key>> =
get_optional_named_arg_with_user_errors(NONE_LIST, Cep18Error::InvalidNoneList);
Implement and export a ChangeEventsModeParams
interface in the SDK’s TypeScript definitions that corresponds to the ChangeEventsMode
entry point parameters of the CEP18 contract.
SOLVED: The Casper team added the missing ChangeEventsModeArgs interface so the SDK now has typed parameters for the change_events_mode entry-point.
//
The SDK declares an interface that is not up to date with the latest contract version. The SDK shows burnerList
and mintAndBurnList
arguments that are not used in the CEP18
contract:
export type ChangeSecurityArgs = {
adminList?: Entity[];
minterList?: Entity[];
burnerList?: Entity[];
mintAndBurnList?: Entity[];
noneList?: Entity[];
};
For reference, in the contract side:
pub extern "C" fn change_security() {
if 0 == get_stored_value::<u8>(ARG_ENABLE_MINT_BURN) {
revert(Cep18Error::MintBurnDisabled);
}
sec_check(vec![SecurityBadge::Admin]);
let admin_list: Option<Vec<Key>> =
get_optional_named_arg_with_user_errors(ADMIN_LIST, Cep18Error::InvalidAdminList);
let minter_list: Option<Vec<Key>> =
get_optional_named_arg_with_user_errors(MINTER_LIST, Cep18Error::InvalidMinterList);
let none_list: Option<Vec<Key>> =
get_optional_named_arg_with_user_errors(NONE_LIST, Cep18Error::InvalidNoneList);
Calling the entry point with these arguments will therefore not work as intended.
Update the ChangeSecurityArgs
type in the SDK to align with the latest CEP18 contract by removing the deprecated burnerList
and mintAndBurnList
fields, and regenerate the client bindings to include only adminList
, minterList
, and noneList
.
SOLVED: The Casper team successfully remediated this issue.
//
The get_immediate_caller
function retrieves the information about the caller, that could be either an externally owned account or a contract. The function consider some items as caller_info.kind
that will never be provided by the node codebase, such as: PACKAGE
and CONTRACT_PACKAGE
.
The node codebase only consider three branches:
ACCOUNT
ENTITY
CONTRACT
Therefore, the other kinds will never be reached in the get_immediate_caller
implementation.
In the get_immediate_caller
function, many kinds are defined:
pub fn get_immediate_caller() -> Key {
const ACCOUNT: u8 = 0;
const PACKAGE: u8 = 1;
const CONTRACT_PACKAGE: u8 = 2;
const ENTITY: u8 = 3;
const CONTRACT: u8 = 4;
let caller_info = casper_get_immediate_caller().unwrap_or_revert();
match caller_info.kind() {
ACCOUNT => caller_info
.get_field_by_index(ACCOUNT)
.unwrap()
.to_t::<Option<AccountHash>>()
.unwrap_or_revert()
.unwrap_or_revert_with(Cep18Error::InvalidContext)
.into(),
PACKAGE => caller_info
.get_field_by_index(PACKAGE)
.unwrap()
.to_t::<Option<PackageHash>>()
.unwrap_or_revert()
.unwrap_or_revert_with(Cep18Error::InvalidContext)
.into(),
CONTRACT_PACKAGE | CONTRACT => caller_info
.get_field_by_index(CONTRACT_PACKAGE)
.unwrap()
.to_t::<Option<ContractPackageHash>>()
.unwrap_or_revert()
.unwrap_or_revert_with(Cep18Error::InvalidContext)
.into(),
ENTITY => caller_info
.get_field_by_index(ENTITY)
.unwrap()
.to_t::<Option<EntityAddr>>()
.unwrap_or_revert()
.unwrap_or_revert_with(Cep18Error::InvalidContext)
.into(),
_ => revert(Cep18Error::InvalidContext),
}
}
In the Casper codebase (types/src/system/caller.rs
), the system only branches through the three aforementioned kinds:
impl TryFrom<Caller> for CallerInfo {
type Error = CLValueError;
fn try_from(value: Caller) -> Result<Self, Self::Error> {
match value {
Caller::Initiator { account_hash } => {
let kind = ACCOUNT;
let mut ret = BTreeMap::new();
ret.insert(ACCOUNT, CLValue::from_t(Some(account_hash))?);
ret.insert(PACKAGE, CLValue::from_t(Option::<PackageHash>::None)?);
ret.insert(
CONTRACT_PACKAGE,
CLValue::from_t(Option::<ContractPackageHash>::None)?,
);
ret.insert(ENTITY, CLValue::from_t(Option::<EntityAddr>::None)?);
ret.insert(CONTRACT, CLValue::from_t(Option::<ContractHash>::None)?);
Ok(CallerInfo { kind, fields: ret })
}
Caller::Entity {
package_hash,
entity_addr,
} => {
let kind = ENTITY;
let mut ret = BTreeMap::new();
ret.insert(ACCOUNT, CLValue::from_t(Option::<AccountHash>::None)?);
ret.insert(PACKAGE, CLValue::from_t(Some(package_hash))?);
ret.insert(
CONTRACT_PACKAGE,
CLValue::from_t(Option::<ContractPackageHash>::None)?,
);
ret.insert(ENTITY, CLValue::from_t(Some(entity_addr))?);
ret.insert(CONTRACT, CLValue::from_t(Option::<ContractHash>::None)?);
Ok(CallerInfo { kind, fields: ret })
}
Caller::SmartContract {
contract_package_hash,
contract_hash,
} => {
let kind = CONTRACT;
let mut ret = BTreeMap::new();
ret.insert(ACCOUNT, CLValue::from_t(Option::<AccountHash>::None)?);
ret.insert(PACKAGE, CLValue::from_t(Option::<PackageHash>::None)?);
ret.insert(
CONTRACT_PACKAGE,
CLValue::from_t(Some(contract_package_hash))?,
);
ret.insert(ENTITY, CLValue::from_t(Option::<EntityAddr>::None)?);
ret.insert(CONTRACT, CLValue::from_t(Some(contract_hash))?);
Ok(CallerInfo { kind, fields: ret })
}
}
}
}
Refactor the get_immediate_caller
implementation to align with the node’s CallerInfo
kinds by removing the PACKAGE
and CONTRACT_PACKAGE
constants and their corresponding match arms, and handle only ACCOUNT
, ENTITY
, and CONTRACT
types to eliminate unreachable code paths.
SOLVED: The over-broad variant list (PACKAGE, CONTRACT_PACKAGE, …) inside get_immediate_caller is not present in this version of the contract; the helper now uses CallStackElement instead.
//
The codebase contains duplicate checks for recipient to caller inequality:
pub extern "C" fn transfer() {
let caller = get_immediate_caller();
let recipient: Key = runtime::get_named_arg(ARG_RECIPIENT);
if caller == recipient {
revert(Cep18Error::CannotTargetSelfUser);
}
let amount: U256 = runtime::get_named_arg(ARG_AMOUNT);
transfer_balance(caller, recipient, amount).unwrap_or_revert();
events::record_event_dictionary(Event::Transfer(Transfer {
sender: caller,
recipient,
amount,
}))
}
pub fn transfer_balance(sender: Key, recipient: Key, amount: U256) -> Result<(), Cep18Error> {
if sender == recipient || amount.is_zero() {
return Ok(());
}
let new_sender_balance = {
let sender_balance = read_balance_from(sender);
sender_balance
.checked_sub(amount)
.ok_or(Cep18Error::InsufficientBalance)?
};
let new_recipient_balance = {
let recipient_balance = read_balance_from(recipient);
recipient_balance
.checked_add(amount)
.ok_or(Cep18Error::Overflow)?
};
write_balance_to(sender, new_sender_balance);
write_balance_to(recipient, new_recipient_balance);
Ok(())
}
Eliminate the redundant sender == recipient
check from transfer()
and centralize the self-transfer validation within transfer_balance
by returning Err(Cep18Error::CannotTargetSelfUser)
when sender == recipient
. Propagate this error upstream to enforce the validation consistently in a single location.
ACKNOWLEDGED: Duplicate sender == recipient
check remains in both transfer()
and transfer_balance()
.
//
The ENTRY_POINT_UPGRADE
constant defined in constants.rs
is not used in the entry points. This endpoint is not expected to be implemented because of the way Casper handles upgrades.
Remove the unused ENTRY_POINT_UPGRADE
constant from constants.rs
to eliminate dead code and ensure alignment with Casper’s native upgrade mechanism.
SOLVED: The Casper team successfully remediated this issue.
Halborn strongly recommends conducting a follow-up assessment of the project either within six months or immediately following any material changes to the codebase, whichever comes first. This approach is crucial for maintaining the project’s integrity and addressing potential vulnerabilities introduced by code modifications.
// Download the full report
CEP18
* Use Google Chrome for best results
** Check "Background Graphics" in the print settings if needed