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

Question about the Type system #62

Closed
DuanYuFi opened this issue Dec 29, 2022 · 10 comments
Closed

Question about the Type system #62

DuanYuFi opened this issue Dec 29, 2022 · 10 comments

Comments

@DuanYuFi
Copy link
Contributor

Hi, I am reading the code about the definition of secret share, and in spu/mpc/aby3/type.h: 22, AShrTy inherits from TypeImpl<AShrTy, RingTy, Secret, AShare>. I followed into TypeImpl and here are my questions:

  • Why the first item in the templates is the class itself? Is that a stipulation?
  • Is RingTy means this data is in ring?
  • Is Secret means this data is secret instead of public?
  • Is AShare emphasizes that this is an Arithmetic data? In other words, the point of it is Arithmetic instead of Share?
  • Is TypeImpl just defined the attribute of the share, and it doesn't store any real data? For example, there's a replicated secret share (x0, x1), and TypeImpl only defines attribute such as RingTy, Secret, etc. but don't store x0, x1.

Thanks for reply!

@rivertalk
Copy link

Hi @DuanYuFi , thanks for the question

Why the first item in the templates is the class itself? Is that a stipulation?

Yes, it's a stipulation, the pattern is from https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern, it's widely used in a number of C++ projects, like LLVM/Eigen/xtensor.

Is RingTy means this data is in ring?

Yes, you can think RingTy as SPU VM's unsigned integer, but with more clear semantic.

Is Secret means this data is secret instead of public?

Yes, you will see something like x.eltype().ias<Secret>, which test if the value is a secret value.

s AShare emphasizes that this is an Arithmetic data? In other words, the point of it is Arithmetic instead of Share?

It means a Arithmetic shared data, an AShare is a Secret Share, which is, of course, a Secret.

Is TypeImpl just defined the attribute of the share, and it doesn't store any real data? For example, there's a replicated secret share (x0, x1), and TypeImpl only defines attribute such as RingTy, Secret, etc. but don't store x0, x1.

Yes, type is type, value is value. Type just describes the runtime type information of values, its does not hold content of values.

Jin,
Thanks

@DuanYuFi
Copy link
Contributor Author

Thanks for your detailed answer, it solves all my questions. Thank you!

@DuanYuFi
Copy link
Contributor Author

Hi, if I want to build a field type, should I still use RingTy? I didn't find something like FieldTy.
By the way, happy Lunar Newyear to everyone :)

@DuanYuFi DuanYuFi reopened this Jan 30, 2023
@DuanYuFi
Copy link
Contributor Author

Seems that according to our previous conversation:

Yes, you can think RingTy as SPU VM's unsigned integer, but with more clear semantic.

RingTy means unsigned integer, of course it could represent field element. And RingTy has an attribute Ring2k, which has some comments

// This trait means the data is maintained in ring 2^k, it DOES NOT mean that
// data storage is k-bits.
// For example, some protocol works in Zq, but the data it manipulates on is
// [0, 2^k).

Thanks LOL, if anything incorrect, please tell me.

@rivertalk
Copy link

Hi, if I want to build a field type, should I still use RingTy? I didn't find something like FieldTy. By the way, happy Lunar Newyear to everyone :)

Let me guess, you are trying to add a new protocol which works on Zq, but the upper layer (Hal layer) assumes all operations works on Z2k(Ring2k).

If am correct, you can simply expose the type as Z2k(Ring2k), because the upper system use this trait to interact with protocol layer. But inside your protocol, maintain Zq storage and related operations.

In the future, we may support Zq from the HAL layer, which means, HAL acts differently according to the working field. At that time, we can 'lift' Zq to //spu/core/type.h (from your protocol's local definition)

@DuanYuFi
Copy link
Contributor Author

OK, thanks for your detailed reply. You are right, I'll spend some time to comprehend。

@DuanYuFi DuanYuFi closed this as completed Feb 6, 2023
@DuanYuFi
Copy link
Contributor Author

What's the difference between TypeObject, FieldType and ring2k_t (from Ring2kTrait)?

@DuanYuFi DuanYuFi reopened this Feb 25, 2023
@DuanYuFi
Copy link
Contributor Author

It seems that FieldType is included in TypeObject, and ring2k_t is some struct related to FieldType?

@rivertalk
Copy link

TypeObject is just a general object that represent a type, you can derive from it to represent a concrete type. i.e.

class MyPrototocolType : public TypeObject {};

But the system sometime want to know how your derived type behave like, i.e. does like behave like a Ring2k, or a boolean share? So we should add these interface to it.

class Ring2k { 
  FieldType field(); // return the concrete field of this ring.
};
// also inherit from Ring2k
class MyPrototocolType : public TypeObject, public Ring2k;

And finally, we use CRTP and concept model idiom to inject some other information to the classes.

class MyProtocolType : public TypeImpl<MyProtocolType, Ring2k, ...> {}

ring2k_t is totally a different thing, it's use to dispatch to static type according to dynamic type. i.e

// if you define 
enum CppType {
  Int32,
  Int64,
};

if (ty == Int32) {
  using ring2k_t = int32_t; // inject static type information here.
  fn(...); // call your lambda function, and the `ring2k_t` is injected.
} else if (ty == Int64) {
  ...
}

Have a nice day.

@DuanYuFi
Copy link
Contributor Author

That's a detailed description. Thank you. I learned so much about computer systems, principles of compiles, etc. in this issue than what I've done all my life. I hope I can get on it well as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants