Skip to content

Commit

Permalink
lang, ts: Consistent domain delimiters (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante authored May 25, 2021
1 parent 68c601a commit 21fc2d1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ incremented for features.
## Breaking Changes

* lang: `#[account(associated)]` now requires `init` to be provided to create an associated account. If not provided, then the address will be assumed to exist, and a constraint will be added to ensure its correctness ([#318](https://github.com/project-serum/anchor/pull/318)).
* lang, ts: Change domain delimiters for the pre-image of the instruciton sighash to be a single colon `:` to be consistent with accounts. This change should only be noticed by library maintainers.

## [0.6.0] - 2021-05-23

Expand Down
4 changes: 2 additions & 2 deletions examples/ido-pool/programs/ido-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.4.4"
anchor-spl = "0.4.4"
anchor-lang = { path = "../../../../lang" }
anchor-spl = { path = "../../../../spl" }
2 changes: 1 addition & 1 deletion examples/pyth/programs/pyth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.5.0"
anchor-lang = { path = "../../../../lang" }
arrayref = "0.3.6"
bytemuck = { version = "1.4.0" }
4 changes: 2 additions & 2 deletions lang/syn/src/codegen/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ fn generate_cpi(program: &Program) -> proc_macro2::TokenStream {
// However, we do namespace methods in the preeimage so that we can use
// different traits with the same method name.
pub fn sighash(namespace: &str, name: &str) -> [u8; 8] {
let preimage = format!("{}::{}", namespace, name);
let preimage = format!("{}:{}", namespace, name);

let mut sighash = [0u8; 8];
sighash.copy_from_slice(&crate::hash::hash(preimage.as_bytes()).to_bytes()[..8]);
Expand All @@ -1371,7 +1371,7 @@ pub fn sighash(namespace: &str, name: &str) -> [u8; 8] {

fn sighash_ctor() -> [u8; 8] {
let namespace = SIGHASH_STATE_NAMESPACE;
let preimage = format!("{}::new", namespace);
let preimage = format!("{}:new", namespace);

let mut sighash = [0u8; 8];
sighash.copy_from_slice(&crate::hash::hash(preimage.as_bytes()).to_bytes()[..8]);
Expand Down
2 changes: 1 addition & 1 deletion ts/src/coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export function accountSize(
// doesn't allow function overloading.
function sighash(nameSpace: string, ixName: string): Buffer {
let name = snakeCase(ixName);
let preimage = `${nameSpace}::${name}`;
let preimage = `${nameSpace}:${name}`;
// @ts-ignore
return Buffer.from(sha256.digest(preimage)).slice(0, 8);
}

0 comments on commit 21fc2d1

Please sign in to comment.