Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ledger: fix whitelist check #1018

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/scripts/schedule-e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@ def find_freer_machine():
command = CARGO_TEST_COMMAND.format(test_name)
subprocess.check_call(command, shell=True, stdout=sys.stdout, stderr=subprocess.STDOUT)
except:
print("TEST FAILED: {}".format(test_name))
print("run locally with: {}".format(command))
break
continue
26 changes: 22 additions & 4 deletions core/src/ledger/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,24 @@ impl Parameters {

// write vp whitelist parameter
let vp_whitelist_key = storage::get_vp_whitelist_storage_key();
let vp_whitelist_value = encode(&vp_whitelist);
let vp_whitelist_value = encode(
&vp_whitelist
.iter()
.map(|id| id.to_lowercase())
.collect::<Vec<String>>(),
);
storage.write(&vp_whitelist_key, vp_whitelist_value).expect(
"Vp whitelist parameter must be initialized in the genesis block",
);

// write tx whitelist parameter
let tx_whitelist_key = storage::get_tx_whitelist_storage_key();
let tx_whitelist_value = encode(&tx_whitelist);
let tx_whitelist_value = encode(
&tx_whitelist
.iter()
.map(|id| id.to_lowercase())
.collect::<Vec<String>>(),
);
storage.write(&tx_whitelist_key, tx_whitelist_value).expect(
"Tx whitelist parameter must be initialized in the genesis block",
);
Expand Down Expand Up @@ -263,7 +273,11 @@ where
H: ledger_storage::StorageHasher,
{
let key = storage::get_vp_whitelist_storage_key();
update(storage, &value, key)
update(
storage,
&value.iter().map(|id| id.to_lowercase()).collect::<String>(),
key,
)
}

/// Update the tx whitelist parameter in storage. Returns the parameters and gas
Expand All @@ -277,7 +291,11 @@ where
H: ledger_storage::StorageHasher,
{
let key = storage::get_tx_whitelist_storage_key();
update(storage, &value, key)
update(
storage,
&value.iter().map(|id| id.to_lowercase()).collect::<String>(),
key,
)
}

/// Update the epoch parameter in storage. Returns the parameters and gas
Expand Down
7 changes: 6 additions & 1 deletion tests/src/e2e/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ pub fn network(
let test_dir = TestDir::new();

// Open the source genesis file
let genesis = genesis_config::open_genesis_config(
let mut genesis = genesis_config::open_genesis_config(
working_dir.join(SINGLE_NODE_NET_GENESIS),
)?;

genesis.parameters.vp_whitelist =
Some(get_all_wasms_hashes(&working_dir, Some("vp_")));
genesis.parameters.tx_whitelist =
Some(get_all_wasms_hashes(&working_dir, Some("tx_")));

// Run the provided function on it
let genesis = update_genesis(genesis);

Expand Down
6 changes: 4 additions & 2 deletions vp_prelude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ pub fn is_tx_whitelisted(ctx: &Ctx) -> VpResult {
let key = parameters::storage::get_tx_whitelist_storage_key();
let whitelist: Vec<String> = ctx.read_pre(&key)?.unwrap_or_default();
// if whitelist is empty, allow any transaction
Ok(whitelist.is_empty() || whitelist.contains(&tx_hash.to_string()))
Ok(whitelist.is_empty()
|| whitelist.contains(&tx_hash.to_string().to_lowercase()))
}

pub fn is_vp_whitelisted(ctx: &Ctx, vp_bytes: &[u8]) -> VpResult {
let vp_hash = sha256(vp_bytes);
let key = parameters::storage::get_vp_whitelist_storage_key();
let whitelist: Vec<String> = ctx.read_pre(&key)?.unwrap_or_default();
// if whitelist is empty, allow any transaction
Ok(whitelist.is_empty() || whitelist.contains(&vp_hash.to_string()))
Ok(whitelist.is_empty()
|| whitelist.contains(&vp_hash.to_string().to_lowercase()))
}

/// Log a string. The message will be printed at the `tracing::Level::Info`.
Expand Down