Skip to content

Commit

Permalink
move bytecode v6
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Dec 26, 2022
1 parent a74cba0 commit bd1cea9
Show file tree
Hide file tree
Showing 83 changed files with 1,035 additions and 558 deletions.
769 changes: 458 additions & 311 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion abi/decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version = "1.12.5"
[dependencies]
anyhow = "1.0.41"
hex = "0.4.3"
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "8613078820ba81686071b224e64441b68d6dc6cf" }
starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
starcoin-vm-types = { path = "../../vm/types" }
starcoin-abi-types = { path = "../types" }
Expand Down
4 changes: 4 additions & 0 deletions abi/decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ fn value_to_json(origin: AnnotatedMoveValue) -> serde_json::Value {
use serde_json::Value;
match origin {
AnnotatedMoveValue::U8(v) => Value::Number(v.into()),
AnnotatedMoveValue::U16(v) => Value::Number(v.into()),
AnnotatedMoveValue::U32(v) => Value::Number(v.into()),
AnnotatedMoveValue::U64(v) => Value::Number(v.into()),
AnnotatedMoveValue::U128(v) => Value::Number(v.into()),
// XXX FIXME YSG
AnnotatedMoveValue::U256(v) => Value::String(v.to_string()),
AnnotatedMoveValue::Bool(v) => Value::Bool(v),
AnnotatedMoveValue::Address(v) => Value::String(v.to_string()),
AnnotatedMoveValue::Vector(v) => Value::Array(v.into_iter().map(value_to_json).collect()),
Expand Down
2 changes: 1 addition & 1 deletion abi/resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ starcoin-vm-types = { path = "../../vm/types" }
starcoin-abi-types = { path = "../types" }
anyhow = "~1"
starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
move-model = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
move-model = { git = "https://github.com/starcoinorg/move", rev = "8613078820ba81686071b224e64441b68d6dc6cf" }
[dev-dependencies]
stdlib = { path = "../../vm/stdlib" }
serde_json = "1"
Expand Down
6 changes: 6 additions & 0 deletions abi/resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ impl<'a> ABIResolver<'a> {
Ok(match type_tag {
TypeTag::Bool => TypeInstantiation::Bool,
TypeTag::U8 => TypeInstantiation::U8,
TypeTag::U16 => TypeInstantiation::U16,
TypeTag::U32 => TypeInstantiation::U32,
TypeTag::U64 => TypeInstantiation::U64,
TypeTag::U128 => TypeInstantiation::U128,
TypeTag::U256 => TypeInstantiation::U256,
TypeTag::Address => TypeInstantiation::Address,

TypeTag::Signer => TypeInstantiation::Signer,
Expand All @@ -134,8 +137,11 @@ impl<'a> ABIResolver<'a> {
Ok(match ty {
Type::Bool => TypeInstantiation::Bool,
Type::U8 => TypeInstantiation::U8,
Type::U16 => TypeInstantiation::U16,
Type::U32 => TypeInstantiation::U32,
Type::U64 => TypeInstantiation::U64,
Type::U128 => TypeInstantiation::U128,
Type::U256 => TypeInstantiation::U256,
Type::Address => TypeInstantiation::Address,
Type::Signer => TypeInstantiation::Signer,
Type::Struct {
Expand Down
1 change: 1 addition & 0 deletions abi/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ serde_bytes = "0.11"
serde_json = "~1"
hex = "0.4"
schemars = { git = "https://github.com/starcoinorg/schemars", rev = "6972da92f4360e1779168bb3fe0274c521d324e2" }
move-core-types = { git = "https://github.com/starcoinorg/move", rev = "8613078820ba81686071b224e64441b68d6dc6cf" }
17 changes: 14 additions & 3 deletions abi/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,11 @@ impl FieldABI {
pub enum TypeInstantiation {
Bool,
U8,
U16,
U32,
U64,
U128,
U256,
Address,
Signer,
Vector(Box<TypeInstantiation>),
Expand All @@ -591,9 +594,11 @@ impl TypeInstantiation {
Ok(match self {
Self::Bool => MoveTypeLayout::Bool,
Self::U8 => MoveTypeLayout::U8,

Self::U16 => MoveTypeLayout::U16,
Self::U32 => MoveTypeLayout::U32,
Self::U64 => MoveTypeLayout::U64,
Self::U128 => MoveTypeLayout::U128,
Self::U256 => MoveTypeLayout::U256,
Self::Address => MoveTypeLayout::Address,
Self::Signer => MoveTypeLayout::Signer,

Expand All @@ -607,14 +612,16 @@ impl TypeInstantiation {
Ok(match self {
Self::Bool => TypeTag::Bool,
Self::U8 => TypeTag::U8,

Self::U16 => TypeTag::U16,
Self::U32 => TypeTag::U32,
Self::U64 => TypeTag::U64,
Self::U128 => TypeTag::U128,
Self::U256 => TypeTag::U256,
Self::Address => TypeTag::Address,
Self::Signer => TypeTag::Signer,

Self::Vector(t) => TypeTag::Vector(Box::new(t.type_tag()?)),
Self::Struct(s) => TypeTag::Struct(s.struct_tag()?),
Self::Struct(s) => TypeTag::Struct(Box::new(s.struct_tag()?)),
Self::TypeParameter(_) => anyhow::bail!("get type tag failed -- {:?}", self),
Self::Reference(_, _) => anyhow::bail!("get type tag failed -- {:?}", self),
})
Expand Down Expand Up @@ -650,8 +657,12 @@ impl<'d> serde::de::DeserializeSeed<'d> for &TypeInstantiation {
match &self {
T::Bool => bool::deserialize(deserializer).map(V::Bool),
T::U8 => u8::deserialize(deserializer).map(Into::into),
T::U16 => u16::deserialize(deserializer).map(Into::into),
T::U32 => u32::deserialize(deserializer).map(Into::into),
T::U64 => u64::deserialize(deserializer).map(Into::into),
T::U128 => u128::deserialize(deserializer).map(Into::into),
// XXX FIXME YSG
T::U256 => Err(D::Error::custom("type U256 not process variant")),
T::Address => {
AccountAddress::deserialize(deserializer).map(|addr| V::String(addr.to_string()))
}
Expand Down
4 changes: 2 additions & 2 deletions chain/tests/test_block_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ fn test_chain_filter_events() {
let times = 10;
mock_chain.produce_and_apply_times(times).unwrap();

let event_type_tag = TypeTag::Struct(StructTag {
let event_type_tag = TypeTag::Struct(Box::new(StructTag {
address: genesis_address(),
module: Identifier::from_str("Block").unwrap(),
name: Identifier::from_str("NewBlockEvent").unwrap(),
type_params: vec![],
});
}));

// Origin block event index is 4, after https://github.com/starcoinorg/starcoin-framework/pull/42 , Genesis account create more event_handles, so the block event index is 7.
// So we should use type_tags to filter event, do not dependent on event key.
Expand Down
2 changes: 1 addition & 1 deletion cmd/airdrop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async fn main() -> Result<()> {
.token_code
.unwrap_or_else(|| G_STC_TOKEN_CODE.clone())
.try_into()?;
let is_stc = stc_type_tag().eq(&TypeTag::Struct(token_type.clone()));
let is_stc = stc_type_tag().eq(&TypeTag::Struct(Box::new(token_type.clone())));

let mut total_amount = 0u128;
let airdrop_infos: Vec<AirdropInfo> = {
Expand Down
4 changes: 2 additions & 2 deletions cmd/db-exporter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ logger = { path = "../../commons/logger", package = "starcoin-logger" }
clap = { version = "3", features = ["derive"] }
atomic-counter = "1.0.1"
tokio = { version = "^1", features = ["full"] }
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
move-bytecode-verifier = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "8613078820ba81686071b224e64441b68d6dc6cf" }
move-bytecode-verifier = { git = "https://github.com/starcoinorg/move", rev = "8613078820ba81686071b224e64441b68d6dc6cf" }
starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
starcoin-state-tree = { path = "../../state/state-tree" }
[target."cfg(target_os=\"linux\")".dependencies]
Expand Down
3 changes: 2 additions & 1 deletion cmd/db-exporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,12 +1833,13 @@ impl serde::Serialize for MoveValue {
}
AnnotatedMoveValue::Bytes(v) => hex::encode(v).serialize(serializer),
AnnotatedMoveValue::Struct(v) => MoveStruct(v.clone()).serialize(serializer),
_ => todo!("XXX FXIME YSG"),
}
}
}
fn parse_struct_tag(input: &str) -> anyhow::Result<StructTag> {
match parse_type_tag(input)? {
TypeTag::Struct(s) => Ok(s),
TypeTag::Struct(s) => Ok(*s),
_ => {
anyhow::bail!("invalid struct tag")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/resource-exporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ impl serde::Serialize for MoveValue {
}
AnnotatedMoveValue::Bytes(v) => hex::encode(v).serialize(serializer),
AnnotatedMoveValue::Struct(v) => MoveStruct(v.clone()).serialize(serializer),
_ => todo!("XXX FIXME YSG"),
}
}
}

fn parse_struct_tag(input: &str) -> anyhow::Result<StructTag> {
match parse_type_tag(input)? {
TypeTag::Struct(s) => Ok(s),
TypeTag::Struct(s) => Ok(*s),
_ => {
anyhow::bail!("invalid struct tag")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/starcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ starcoin-resource-viewer = { path = "../../vm/resource-viewer" }
starcoin-service-registry = { path = "../../commons/service-registry" }
starcoin-move-explain = { path = "../../vm/move-explain" }
vm-status-translator = { path = "../../vm/vm-status-translator" }
move-errmapgen = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
move-errmapgen = { git = "https://github.com/starcoinorg/move", rev = "8613078820ba81686071b224e64441b68d6dc6cf" }
network-api = { path = "../../network/api", package = "network-api" }
starcoin-network-rpc-api = { path = "../../network-rpc/api" }
starcoin-abi-decoder = { path = "../../abi/decoder" }
starcoin-abi-resolver = { path = "../../abi/resolver" }
starcoin-abi-types = { path = "../../abi/types" }
move-command-line-common = { git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
move-command-line-common = { git = "https://github.com/starcoinorg/move", rev = "8613078820ba81686071b224e64441b68d6dc6cf" }

[dev-dependencies]
test-helper = { path = "../../test-helper" }
Expand Down
4 changes: 3 additions & 1 deletion cmd/starcoin/src/account/accept_token_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ impl CommandAction for AcceptTokenCommand {
TransactionPayload::ScriptFunction(ScriptFunction::new(
ModuleId::new(core_code_address(), Identifier::new("Account").unwrap()),
Identifier::new("accept_token").unwrap(),
vec![TypeTag::Struct(opt.token_code.clone().try_into().unwrap())],
vec![TypeTag::Struct(Box::new(
opt.token_code.clone().try_into().unwrap(),
))],
vec![],
)),
)
Expand Down
14 changes: 7 additions & 7 deletions cmd/starcoin/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub enum EventDataView {

impl EventDataView {
pub fn new(event_type_tag: &TypeTag, event_data: &[u8]) -> anyhow::Result<Self> {
if event_type_tag == &TypeTag::Struct(DepositEvent::struct_tag()) {
if event_type_tag == &TypeTag::Struct(Box::new(DepositEvent::struct_tag())) {
if let Ok(received_event) = DepositEvent::try_from_bytes(event_data) {
Ok(EventDataView::ReceivedPayment {
amount: received_event.amount(),
Expand All @@ -179,7 +179,7 @@ impl EventDataView {
} else {
Err(format_err!("Unable to parse ReceivedPaymentEvent"))
}
} else if event_type_tag == &TypeTag::Struct(WithdrawEvent::struct_tag()) {
} else if event_type_tag == &TypeTag::Struct(Box::new(WithdrawEvent::struct_tag())) {
if let Ok(sent_event) = WithdrawEvent::try_from_bytes(event_data) {
Ok(EventDataView::SentPayment {
amount: sent_event.amount(),
Expand All @@ -189,7 +189,7 @@ impl EventDataView {
} else {
Err(format_err!("Unable to parse SentPaymentEvent"))
}
} else if event_type_tag == &TypeTag::Struct(MintEvent::struct_tag()) {
} else if event_type_tag == &TypeTag::Struct(Box::new(MintEvent::struct_tag())) {
if let Ok(mint_event) = MintEvent::try_from_bytes(event_data) {
Ok(EventDataView::Mint {
amount: mint_event.amount(),
Expand All @@ -198,7 +198,7 @@ impl EventDataView {
} else {
Err(format_err!("Unable to parse MintEvent"))
}
} else if event_type_tag == &TypeTag::Struct(ProposalCreatedEvent::struct_tag()) {
} else if event_type_tag == &TypeTag::Struct(Box::new(ProposalCreatedEvent::struct_tag())) {
if let Ok(event) = ProposalCreatedEvent::try_from_bytes(event_data) {
Ok(EventDataView::ProposalCreated {
proposal_id: event.proposal_id,
Expand All @@ -207,7 +207,7 @@ impl EventDataView {
} else {
Err(format_err!("Unable to parse ProposalCreatedEvent"))
}
} else if event_type_tag == &TypeTag::Struct(VoteChangedEvent::struct_tag()) {
} else if event_type_tag == &TypeTag::Struct(Box::new(VoteChangedEvent::struct_tag())) {
if let Ok(event) = VoteChangedEvent::try_from_bytes(event_data) {
Ok(EventDataView::VoteChanged {
proposal_id: event.proposal_id,
Expand All @@ -219,15 +219,15 @@ impl EventDataView {
} else {
Err(format_err!("Unable to parse VoteChangedEvent"))
}
} else if event_type_tag == &TypeTag::Struct(AcceptTokenEvent::struct_tag()) {
} else if event_type_tag == &TypeTag::Struct(Box::new(AcceptTokenEvent::struct_tag())) {
if let Ok(event) = AcceptTokenEvent::try_from_bytes(event_data) {
Ok(EventDataView::AcceptToken {
token_code: event.token_code().to_string(),
})
} else {
Err(format_err!("Unable to parse VoteChangedEvent"))
}
} else if event_type_tag == &TypeTag::Struct(BlockRewardEvent::struct_tag()) {
} else if event_type_tag == &TypeTag::Struct(Box::new(BlockRewardEvent::struct_tag())) {
Ok(BlockRewardEvent::try_from_bytes(event_data)
.map_err(|_| format_err!("Unable to parse {}", BlockRewardEvent::struct_tag()))?
.into())
Expand Down
2 changes: 1 addition & 1 deletion commons/bcs_ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ version = "1.12.5"

[dependencies]
anyhow = "1.0.41"
bcs = "0.1.3"
bcs = "0.1.4"
serde = {version = "1.0.130"}
2 changes: 1 addition & 1 deletion commons/proptest-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ version = "1.12.5"

[dependencies]
crossbeam = "0.7.3"
diem-proptest-helpers = { package = "diem-proptest-helpers", git = "https://github.com/starcoinorg/move", rev = "e5a7e90a2fcfec1abd50bdfcf1d7a59f4de91790" }
diem-proptest-helpers = { package = "diem-proptest-helpers", git = "https://github.com/starcoinorg/move", rev = "8613078820ba81686071b224e64441b68d6dc6cf" }
proptest = "1.0.0"
proptest-derive = "0.3.0"
8 changes: 7 additions & 1 deletion config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,14 @@ mod tests {
let mut entries = instrs;
let mut natives = natives;
let mut constants = constants;
entries.push(("instr.ld_u16".to_string(), 3));
entries.push(("instr.ld_u32".to_string(), 2));
entries.push(("instr.ld_u256".to_string(), 3));
entries.push(("instr.cast_u16".to_string(), 3));
entries.push(("instr.cast_u32".to_string(), 2));
entries.push(("instr.cast_u256".to_string(), 3));
entries.append(&mut natives);
// instruction_schedule don't have this two
// native_table don't have these
entries.push(("nursery.debug.print.base_cost".to_string(), 1));
entries.push(("nursery.debug.print_stack_trace.base_cost".to_string(), 1));

Expand Down
18 changes: 18 additions & 0 deletions etc/starcoin_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ TransactionArgument:
5:
Bool:
NEWTYPE: BOOL
6:
U16:
NEWTYPE: U16
7:
U32:
NEWTYPE: U32
8:
U256:
NEWTYPE:
TUPLEARRAY:
CONTENT: U8
SIZE: 32
TransactionAuthenticator:
ENUM:
0:
Expand Down Expand Up @@ -325,6 +337,12 @@ TypeTag:
struct:
NEWTYPE:
TYPENAME: StructTag
8:
u16: UNIT
9:
u32: UNIT
10:
u256: UNIT
WithdrawCapabilityResource:
STRUCT:
- account_address:
Expand Down
8 changes: 4 additions & 4 deletions executor/tests/module_upgrade_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ fn test_init_script() -> Result<()> {
)?;
let chain_state = prepare_customized_genesis(&net);

let dao_action_type_tag = TypeTag::Struct(StructTag {
let dao_action_type_tag = TypeTag::Struct(Box::new(StructTag {
address: genesis_address(),
module: Identifier::new("UpgradeModuleDaoProposal").unwrap(),
name: Identifier::new("UpgradeModule").unwrap(),
type_params: vec![],
});
}));

let init_script = ScriptFunction::new(
ModuleId::new(
Expand Down Expand Up @@ -123,12 +123,12 @@ fn test_upgrade_stdlib_with_incremental_package() -> Result<()> {
)?;
let chain_state = prepare_customized_genesis(&net);

let dao_action_type_tag = TypeTag::Struct(StructTag {
let dao_action_type_tag = TypeTag::Struct(Box::new(StructTag {
address: genesis_address(),
module: Identifier::new("UpgradeModuleDaoProposal").unwrap(),
name: Identifier::new("UpgradeModule").unwrap(),
type_params: vec![],
});
}));
let path = std::path::PathBuf::from("../vm/stdlib/compiled/2/1-2/stdlib.blob")
.canonicalize()
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions executor/tests/readonly_function_call_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ fn test_readonly_function_call() -> Result<()> {
None,
)?;

let ty = TypeTag::Struct(StructTag {
let ty = TypeTag::Struct(Box::new(StructTag {
address: *account1.address(),
module: Identifier::new("A").unwrap(),
name: Identifier::new("S").unwrap(),
type_params: vec![],
});
}));
assert_eq!(result[0].0, ty);
#[derive(Serialize, Deserialize)]
struct S {
Expand Down
Loading

0 comments on commit bd1cea9

Please sign in to comment.