-
Notifications
You must be signed in to change notification settings - Fork 323
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
feat: internal keyword + lending contract and tests #978
Changes from 19 commits
673284a
c4b6264
684e14b
46d6e9e
0f62615
bc58383
876df6b
7aa3e02
6191d5e
b3f6e88
cfe0493
1245143
3689ab4
c6a2b12
9b22e07
2c6102d
25cf778
746b74e
fac6b3c
b41a7dc
f123135
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+1 −1 | README.md | |
+11 −3 | scripts/deploy_dockerhub | |
+2 −2 | scripts/deploy_npm | |
+1 −1 | scripts/remote_run_script |
+48 −6 | .github/workflows/ci.yml | |
+29 −0 | .github/workflows/sync.yml | |
+1 −1 | foundry.toml | |
+1 −1 | package.json | |
+5 −3 | src/Base.sol | |
+3 −2 | src/Script.sol | |
+8 −12 | src/StdChains.sol | |
+183 −17 | src/StdCheats.sol | |
+1 −1 | src/StdInvariant.sol | |
+4 −0 | src/StdStorage.sol | |
+2 −2 | src/StdStyle.sol | |
+6 −1 | src/StdUtils.sol | |
+4 −2 | src/Test.sol | |
+91 −10 | src/Vm.sol | |
+394 −382 | src/console2.sol | |
+13,248 −0 | src/safeconsole.sol | |
+91 −36 | test/StdChains.t.sol | |
+197 −13 | test/StdCheats.t.sol | |
+17 −2 | test/StdMath.t.sol | |
+10 −0 | test/StdStorage.t.sol | |
+4 −4 | test/StdStyle.t.sol | |
+53 −8 | test/StdUtils.t.sol |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,14 +32,15 @@ template <typename NCT> struct FunctionLeafPreimage { | |
using uint32 = typename NCT::uint32; | ||
|
||
uint32 function_selector = 0; | ||
boolean is_internal = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This being almost the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly, 3 are overlapping. But the function data is accesible inside noir as well, so maybe the leaf should include the function data: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the sounds of that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think perhaps the difference between
Some of this is faint memories, so I could be wrong, but I believe their separation was intentional. Re storing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good, it can stay as is! |
||
boolean is_private = false; | ||
fr vk_hash = 0; | ||
fr acir_hash = 0; | ||
|
||
boolean operator==(FunctionLeafPreimage<NCT> const& other) const | ||
{ | ||
return function_selector == other.function_selector && is_private == other.is_private && | ||
vk_hash == other.vk_hash && acir_hash == other.acir_hash; | ||
return function_selector == other.function_selector && is_internal == other.is_internal && | ||
is_private == other.is_private && vk_hash == other.vk_hash && acir_hash == other.acir_hash; | ||
}; | ||
|
||
template <typename Builder> FunctionLeafPreimage<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const | ||
|
@@ -50,10 +51,7 @@ template <typename NCT> struct FunctionLeafPreimage { | |
auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; | ||
|
||
FunctionLeafPreimage<CircuitTypes<Builder>> preimage = { | ||
to_ct(function_selector), | ||
to_ct(is_private), | ||
to_ct(vk_hash), | ||
to_ct(acir_hash), | ||
to_ct(function_selector), to_ct(is_internal), to_ct(is_private), to_ct(vk_hash), to_ct(acir_hash), | ||
}; | ||
|
||
return preimage; | ||
|
@@ -65,10 +63,7 @@ template <typename NCT> struct FunctionLeafPreimage { | |
auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt<Builder>(e); }; | ||
|
||
FunctionLeafPreimage<NativeTypes> preimage = { | ||
to_nt(function_selector), | ||
to_nt(is_private), | ||
to_nt(vk_hash), | ||
to_nt(acir_hash), | ||
to_nt(function_selector), to_nt(is_internal), to_nt(is_private), to_nt(vk_hash), to_nt(acir_hash), | ||
}; | ||
|
||
return preimage; | ||
|
@@ -79,6 +74,7 @@ template <typename NCT> struct FunctionLeafPreimage { | |
static_assert(!(std::is_same<NativeTypes, NCT>::value)); | ||
|
||
function_selector.set_public(); | ||
fr(is_internal).set_public(); | ||
fr(is_private).set_public(); | ||
vk_hash.set_public(); | ||
acir_hash.set_public(); | ||
|
@@ -87,10 +83,7 @@ template <typename NCT> struct FunctionLeafPreimage { | |
fr hash() const | ||
{ | ||
std::vector<fr> const inputs = { | ||
function_selector, | ||
fr(is_private), | ||
vk_hash, | ||
acir_hash, | ||
function_selector, fr(is_internal), fr(is_private), vk_hash, acir_hash, | ||
}; | ||
return NCT::compress(inputs, GeneratorIndex::FUNCTION_LEAF); | ||
} | ||
|
@@ -101,6 +94,7 @@ template <typename NCT> void read(uint8_t const*& it, FunctionLeafPreimage<NCT>& | |
using serialize::read; | ||
|
||
read(it, preimage.function_selector); | ||
read(it, preimage.is_internal); | ||
read(it, preimage.is_private); | ||
read(it, preimage.vk_hash); | ||
read(it, preimage.acir_hash); | ||
|
@@ -111,6 +105,7 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, FunctionLeafPreima | |
using serialize::write; | ||
|
||
write(buf, preimage.function_selector); | ||
write(buf, preimage.is_internal); | ||
write(buf, preimage.is_private); | ||
write(buf, preimage.vk_hash); | ||
write(buf, preimage.acir_hash); | ||
|
@@ -119,6 +114,7 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, FunctionLeafPreima | |
template <typename NCT> std::ostream& operator<<(std::ostream& os, FunctionLeafPreimage<NCT> const& preimage) | ||
{ | ||
return os << "function_selector: " << preimage.function_selector << "\n" | ||
<< "is_internal: " << preimage.is_internal << "\n" | ||
<< "is_private: " << preimage.is_private << "\n" | ||
<< "vk_hash: " << preimage.vk_hash << "\n" | ||
<< "acir_hash: " << preimage.acir_hash << "\n"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,15 @@ void common_validate_inputs(DummyBuilder& builder, KernelInput const& public_ker | |
builder.do_assert(public_kernel_inputs.public_call.bytecode_hash != 0, | ||
"Bytecode hash must be non-zero", | ||
CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a cpp test testing this code path, similarly for the other assert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, will do. It's tested in the TS as well. |
||
if (this_call_stack_item.function_data.is_internal) { | ||
auto const target = this_call_stack_item.contract_address; | ||
auto const sender = this_call_stack_item.public_inputs.call_context.msg_sender; | ||
|
||
builder.do_assert(target == sender, | ||
"call is internal, but msg_sender is not self", | ||
CircuitErrorCode::PUBLIC_KERNEL__IS_INTERNAL_BUT_NOT_SELF_CALL); | ||
} | ||
} | ||
|
||
template <typename KernelInput, typename Builder> | ||
|
+48 −6 | .github/workflows/ci.yml | |
+29 −0 | .github/workflows/sync.yml | |
+1 −1 | foundry.toml | |
+1 −1 | package.json | |
+5 −3 | src/Base.sol | |
+4 −3 | src/Script.sol | |
+8 −12 | src/StdChains.sol | |
+183 −17 | src/StdCheats.sol | |
+1 −1 | src/StdInvariant.sol | |
+4 −0 | src/StdStorage.sol | |
+2 −2 | src/StdStyle.sol | |
+11 −2 | src/StdUtils.sol | |
+4 −3 | src/Test.sol | |
+91 −10 | src/Vm.sol | |
+394 −382 | src/console2.sol | |
+13,248 −0 | src/safeconsole.sol | |
+91 −36 | test/StdChains.t.sol | |
+197 −13 | test/StdCheats.t.sol | |
+17 −2 | test/StdMath.t.sol | |
+10 −0 | test/StdStorage.t.sol | |
+4 −4 | test/StdStyle.t.sol | |
+53 −8 | test/StdUtils.t.sol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the build system be changed in this pr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, should be fixed now.