Skip to content

Commit

Permalink
Rename raw_extension_data to extension_scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong committed Apr 19, 2024
1 parent cd7866f commit 2e887b1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
22 changes: 11 additions & 11 deletions c/xudt_rce.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int ckb_exit(signed char);
typedef unsigned __int128 uint128_t;

uint8_t g_script[SCRIPT_SIZE] = {0};
uint8_t g_raw_extension_data[RAW_EXTENSION_SIZE] = {0};
uint8_t g_extension_scripts[RAW_EXTENSION_SIZE] = {0};
WitnessArgsType g_witness_args;

uint8_t g_code_buff[MAX_CODE_SIZE] __attribute__((aligned(RISCV_PGSIZE)));
Expand Down Expand Up @@ -253,7 +253,7 @@ int get_owner_script(uint8_t *buff, uint32_t buff_len, uint32_t *out_len) {
}

// the *var_len may be bigger than real length of raw extension data
int load_raw_extension_data(uint8_t **var_data, uint32_t *var_len) {
int load_extension_scripts(uint8_t **var_data, uint32_t *var_len) {
int err = 0;
bool use_input_type = true;
err = make_cursor_from_witness(&g_witness_args, &use_input_type);
Expand All @@ -272,13 +272,13 @@ int load_raw_extension_data(uint8_t **var_data, uint32_t *var_len) {
// convert Bytes to XudtWitnessType
XudtWitnessType witness_input = make_XudtWitness(&bytes);
ScriptVecOptType script_vec =
witness_input.t->raw_extension_data(&witness_input);
witness_input.t->extension_scripts(&witness_input);

uint32_t read_len =
mol2_read_at(&script_vec.cur, g_raw_extension_data, RAW_EXTENSION_SIZE);
mol2_read_at(&script_vec.cur, g_extension_scripts, RAW_EXTENSION_SIZE);
CHECK2(read_len == script_vec.cur.size, ERROR_INVALID_MOL_FORMAT);

*var_data = g_raw_extension_data;
*var_data = g_extension_scripts;
*var_len = read_len;

err = 0;
Expand Down Expand Up @@ -379,7 +379,7 @@ int check_enhanced_owner_mode(int *owner_mode) {
}

// *var_data will point to "Raw Extension Data", which can be in args or witness
// *var_data will refer to a memory location of g_script or g_raw_extension_data
// *var_data will refer to a memory location of g_script or g_extension_scripts
int parse_args(int *owner_mode, XUDTFlags *flags, uint8_t **var_data,
uint32_t *var_len, uint8_t *hashes, uint32_t *hashes_count) {
int err = 0;
Expand Down Expand Up @@ -484,7 +484,7 @@ int parse_args(int *owner_mode, XUDTFlags *flags, uint8_t **var_data,
args_bytes_seg.size - BLAKE2B_BLOCK_SIZE - FLAGS_SIZE;
CHECK2(hash_size == BLAKE160_SIZE, ERROR_INVALID_FLAG);

err = load_raw_extension_data(var_data, var_len);
err = load_extension_scripts(var_data, var_len);
CHECK(err);
CHECK2(var_len > 0, ERROR_INVALID_MOL_FORMAT);
// verify the hash
Expand Down Expand Up @@ -633,13 +633,13 @@ int main() {
#endif
int err = 0;
int owner_mode = 0;
uint8_t *raw_extension_data = NULL;
uint8_t *extension_scripts = NULL;
uint32_t raw_extension_len = 0;
XUDTFlags flags = XUDTFlagsPlain;
uint8_t
input_lock_script_hashes[MAX_LOCK_SCRIPT_HASH_COUNT * BLAKE2B_BLOCK_SIZE];
uint32_t input_lock_script_hash_count = 0;
err = parse_args(&owner_mode, &flags, &raw_extension_data, &raw_extension_len,
err = parse_args(&owner_mode, &flags, &extension_scripts, &raw_extension_len,
input_lock_script_hashes, &input_lock_script_hash_count);
CHECK(err);
CHECK2(owner_mode == 1 || owner_mode == 0, ERROR_INVALID_ARGS_FORMAT);
Expand All @@ -651,7 +651,7 @@ int main() {
}

if (flags != XUDTFlagsPlain) {
CHECK2(raw_extension_data != NULL, ERROR_INVALID_ARGS_FORMAT);
CHECK2(extension_scripts != NULL, ERROR_INVALID_ARGS_FORMAT);
CHECK2(raw_extension_len > 0, ERROR_INVALID_ARGS_FORMAT);
}
err = simple_udt(owner_mode);
Expand All @@ -665,7 +665,7 @@ int main() {
}

mol_seg_t raw_extension_seg = {0};
raw_extension_seg.ptr = raw_extension_data;
raw_extension_seg.ptr = extension_scripts;
raw_extension_seg.size = raw_extension_len;
CHECK2(MolReader_ScriptVec_verify(&raw_extension_seg, true) == MOL_OK,
ERROR_INVALID_ARGS_FORMAT);
Expand Down
2 changes: 1 addition & 1 deletion c/xudt_rce.mol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ option ScriptVecOpt (ScriptVec);
table XudtWitness {
owner_script: ScriptOpt,
owner_signature: BytesOpt,
raw_extension_data: ScriptVecOpt,
extension_scripts: ScriptVecOpt,
extension_data: BytesVec,
}

Expand Down
4 changes: 2 additions & 2 deletions c/xudt_rce_mol.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MOLECULE_API_DECORATOR mol_errno MolReader_XudtWitness_verify
#define MolReader_XudtWitness_has_extra_fields(s) mol_table_has_extra_fields(s, 4)
#define MolReader_XudtWitness_get_owner_script(s) mol_table_slice_by_index(s, 0)
#define MolReader_XudtWitness_get_owner_signature(s) mol_table_slice_by_index(s, 1)
#define MolReader_XudtWitness_get_raw_extension_data(s) mol_table_slice_by_index(s, 2)
#define MolReader_XudtWitness_get_extension_scripts(s) mol_table_slice_by_index(s, 2)
#define MolReader_XudtWitness_get_extension_data(s) mol_table_slice_by_index(s, 3)
#define MolReader_RCRule_verify(s, c) mol_verify_fixed_size(s, 33)
#define MolReader_RCRule_get_smt_root(s) mol_slice_by_offset(s, 0, 32)
Expand Down Expand Up @@ -88,7 +88,7 @@ MOLECULE_API_DECORATOR mol_errno MolReader_XudtData_verify
#define MolBuilder_XudtWitness_init(b) mol_table_builder_initialize(b, 128, 4)
#define MolBuilder_XudtWitness_set_owner_script(b, p, l) mol_table_builder_add(b, 0, p, l)
#define MolBuilder_XudtWitness_set_owner_signature(b, p, l) mol_table_builder_add(b, 1, p, l)
#define MolBuilder_XudtWitness_set_raw_extension_data(b, p, l) mol_table_builder_add(b, 2, p, l)
#define MolBuilder_XudtWitness_set_extension_scripts(b, p, l) mol_table_builder_add(b, 2, p, l)
#define MolBuilder_XudtWitness_set_extension_data(b, p, l) mol_table_builder_add(b, 3, p, l)
MOLECULE_API_DECORATOR mol_seg_res_t MolBuilder_XudtWitness_build (mol_builder_t);
#define MolBuilder_XudtWitness_clear(b) mol_builder_discard(b)
Expand Down
8 changes: 4 additions & 4 deletions c/xudt_rce_mol2.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ScriptOptType XudtWitness_get_owner_script_impl(
struct XudtWitnessType *);
struct BytesOptType XudtWitness_get_owner_signature_impl(
struct XudtWitnessType *);
struct ScriptVecOptType XudtWitness_get_raw_extension_data_impl(
struct ScriptVecOptType XudtWitness_get_extension_scripts_impl(
struct XudtWitnessType *);
struct BytesVecType XudtWitness_get_extension_data_impl(
struct XudtWitnessType *);
Expand Down Expand Up @@ -124,7 +124,7 @@ typedef struct ScriptVecOptType {
typedef struct XudtWitnessVTable {
struct ScriptOptType (*owner_script)(struct XudtWitnessType *);
struct BytesOptType (*owner_signature)(struct XudtWitnessType *);
struct ScriptVecOptType (*raw_extension_data)(struct XudtWitnessType *);
struct ScriptVecOptType (*extension_scripts)(struct XudtWitnessType *);
struct BytesVecType (*extension_data)(struct XudtWitnessType *);
} XudtWitnessVTable;
typedef struct XudtWitnessType {
Expand Down Expand Up @@ -299,7 +299,7 @@ struct XudtWitnessVTable *GetXudtWitnessVTable(void) {
if (inited) return &s_vtable;
s_vtable.owner_script = XudtWitness_get_owner_script_impl;
s_vtable.owner_signature = XudtWitness_get_owner_signature_impl;
s_vtable.raw_extension_data = XudtWitness_get_raw_extension_data_impl;
s_vtable.extension_scripts = XudtWitness_get_extension_scripts_impl;
s_vtable.extension_data = XudtWitness_get_extension_data_impl;
return &s_vtable;
}
Expand All @@ -319,7 +319,7 @@ BytesOptType XudtWitness_get_owner_signature_impl(
ret.t = GetBytesOptVTable();
return ret;
}
ScriptVecOptType XudtWitness_get_raw_extension_data_impl(
ScriptVecOptType XudtWitness_get_extension_scripts_impl(
XudtWitnessType *this) {
ScriptVecOptType ret;
mol2_cursor_t cur = mol2_table_slice_by_index(&this->cur, 2);
Expand Down
2 changes: 1 addition & 1 deletion tests/xudt_rce/ckb_syscall_xudt_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int ckb_load_witness(void* addr, uint64_t* len, size_t offset, size_t index,
mol_builder_t xwi_builder;
MolBuilder_XudtWitness_init(&xwi_builder);
if (g_flags == 2) {
MolBuilder_XudtWitness_set_raw_extension_data(
MolBuilder_XudtWitness_set_extension_scripts(
&xwi_builder, g_extension_script_hash.ptr,
g_extension_script_hash.size);
}
Expand Down
26 changes: 13 additions & 13 deletions tests/xudt_rce_rust/src/xudt_rce_mol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ impl ::core::fmt::Display for XudtWitness {
write!(
f,
", {}: {}",
"raw_extension_data",
self.raw_extension_data()
"extension_scripts",
self.extension_scripts()
)?;
write!(f, ", {}: {}", "extension_data", self.extension_data())?;
let extra_count = self.count_extra_fields();
Expand Down Expand Up @@ -577,7 +577,7 @@ impl XudtWitness {
let end = molecule::unpack_number(&slice[12..]) as usize;
BytesOpt::new_unchecked(self.0.slice(start..end))
}
pub fn raw_extension_data(&self) -> ScriptVecOpt {
pub fn extension_scripts(&self) -> ScriptVecOpt {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[12..]) as usize;
let end = molecule::unpack_number(&slice[16..]) as usize;
Expand Down Expand Up @@ -622,7 +622,7 @@ impl molecule::prelude::Entity for XudtWitness {
Self::new_builder()
.owner_script(self.owner_script())
.owner_signature(self.owner_signature())
.raw_extension_data(self.raw_extension_data())
.extension_scripts(self.extension_scripts())
.extension_data(self.extension_data())
}
}
Expand Down Expand Up @@ -650,8 +650,8 @@ impl<'r> ::core::fmt::Display for XudtWitnessReader<'r> {
write!(
f,
", {}: {}",
"raw_extension_data",
self.raw_extension_data()
"extension_scripts",
self.extension_scripts()
)?;
write!(f, ", {}: {}", "extension_data", self.extension_data())?;
let extra_count = self.count_extra_fields();
Expand Down Expand Up @@ -691,7 +691,7 @@ impl<'r> XudtWitnessReader<'r> {
let end = molecule::unpack_number(&slice[12..]) as usize;
BytesOptReader::new_unchecked(&self.as_slice()[start..end])
}
pub fn raw_extension_data(&self) -> ScriptVecOptReader<'r> {
pub fn extension_scripts(&self) -> ScriptVecOptReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[12..]) as usize;
let end = molecule::unpack_number(&slice[16..]) as usize;
Expand Down Expand Up @@ -768,7 +768,7 @@ impl<'r> molecule::prelude::Reader<'r> for XudtWitnessReader<'r> {
pub struct XudtWitnessBuilder {
pub(crate) owner_script: ScriptOpt,
pub(crate) owner_signature: BytesOpt,
pub(crate) raw_extension_data: ScriptVecOpt,
pub(crate) extension_scripts: ScriptVecOpt,
pub(crate) extension_data: BytesVec,
}
impl XudtWitnessBuilder {
Expand All @@ -781,8 +781,8 @@ impl XudtWitnessBuilder {
self.owner_signature = v;
self
}
pub fn raw_extension_data(mut self, v: ScriptVecOpt) -> Self {
self.raw_extension_data = v;
pub fn extension_scripts(mut self, v: ScriptVecOpt) -> Self {
self.extension_scripts = v;
self
}
pub fn extension_data(mut self, v: BytesVec) -> Self {
Expand All @@ -797,7 +797,7 @@ impl molecule::prelude::Builder for XudtWitnessBuilder {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
+ self.owner_script.as_slice().len()
+ self.owner_signature.as_slice().len()
+ self.raw_extension_data.as_slice().len()
+ self.extension_scripts.as_slice().len()
+ self.extension_data.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
Expand All @@ -808,7 +808,7 @@ impl molecule::prelude::Builder for XudtWitnessBuilder {
offsets.push(total_size);
total_size += self.owner_signature.as_slice().len();
offsets.push(total_size);
total_size += self.raw_extension_data.as_slice().len();
total_size += self.extension_scripts.as_slice().len();
offsets.push(total_size);
total_size += self.extension_data.as_slice().len();
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
Expand All @@ -817,7 +817,7 @@ impl molecule::prelude::Builder for XudtWitnessBuilder {
}
writer.write_all(self.owner_script.as_slice())?;
writer.write_all(self.owner_signature.as_slice())?;
writer.write_all(self.raw_extension_data.as_slice())?;
writer.write_all(self.extension_scripts.as_slice())?;
writer.write_all(self.extension_data.as_slice())?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/xudt_rce_rust/tests/test_xudt_rce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ fn build_extension_data(
let b = ScriptVecOptBuilder::default()
.set(Some(extension_script_vec))
.build();
wi_builder = wi_builder.raw_extension_data(b);
wi_builder = wi_builder.extension_scripts(b);
wi_builder = wi_builder.extension_data(bytes_vec_builder.build());
if owner_script.is_some() {
wi_builder = wi_builder.owner_script(owner_script.pack());
Expand Down

0 comments on commit 2e887b1

Please sign in to comment.